11 #ifndef __embedded_rpc__thread__ 12 #define __embedded_rpc__thread__ 14 #include "erpc_config_internal.h" 19 #if !ERPC_THREADS_IS(NONE) 21 #if ERPC_THREADS_IS(PTHREADS) 23 #elif ERPC_THREADS_IS(FREERTOS) 27 #elif ERPC_THREADS_IS(ZEPHYR) 28 #include <zephyr/kernel.h> 29 #elif ERPC_THREADS_IS(MBED) 30 #if MBED_CONF_RTOS_PRESENT 33 #warning mbed-rpc: Threading is enabled but Mbed RTOS is not present! 35 #elif ERPC_THREADS_IS(WIN32) 37 #elif ERPC_THREADS_IS(THREADX) 40 #endif // ERPC_THREADS 61 #if defined(__cplusplus) 74 #if ERPC_THREADS_IS(FREERTOS) 75 typedef StackType_t *thread_stack_pointer;
77 typedef void *thread_stack_pointer;
88 Thread(
const char *name = 0);
101 Thread(
thread_entry_t entry, uint32_t priority = 0, uint32_t stackSize = 0,
const char *name = 0,
102 thread_stack_pointer stackPtr = NULL);
114 void setName(
const char *name) { m_name = name; }
121 const char *
getName(
void)
const {
return m_name; }
131 void init(
thread_entry_t entry, uint32_t priority = 0, uint32_t stackSize = 0, thread_stack_pointer stackPtr = NULL);
138 void start(
void *arg = 0);
145 static void sleep(uint32_t usecs);
154 #if ERPC_THREADS_IS(PTHREADS) 155 return reinterpret_cast<thread_id_t
>(m_thread);
156 #elif ERPC_THREADS_IS(FREERTOS) 157 return reinterpret_cast<thread_id_t
>(m_task);
158 #elif ERPC_THREADS_IS(ZEPHYR) 159 return reinterpret_cast<thread_id_t
>(m_thread_id);
160 #elif ERPC_THREADS_IS(MBED) 161 return reinterpret_cast<thread_id_t
>(m_thread->get_id());
162 #elif ERPC_THREADS_IS(WIN32) 163 return reinterpret_cast<thread_id_t
>(m_thread);
164 #elif ERPC_THREADS_IS(THREADX) 165 return reinterpret_cast<thread_id_t
>(m_thread.tx_thread_id);
176 #if ERPC_THREADS_IS(PTHREADS) 177 return reinterpret_cast<thread_id_t
>(pthread_self());
178 #elif ERPC_THREADS_IS(FREERTOS) 179 return reinterpret_cast<thread_id_t
>(xTaskGetCurrentTaskHandle());
180 #elif ERPC_THREADS_IS(ZEPHYR) 181 return reinterpret_cast<thread_id_t
>(k_current_get());
182 #elif ERPC_THREADS_IS(MBED) 183 return reinterpret_cast<thread_id_t
>(rtos::ThisThread::get_id());
184 #elif ERPC_THREADS_IS(WIN32) 185 return reinterpret_cast<thread_id_t
>(GetCurrentThread());
186 #elif ERPC_THREADS_IS(THREADX) 187 return reinterpret_cast<thread_id_t
>(tx_thread_identify());
191 #if ERPC_THREADS_IS(ZEPHYR) 197 void setStackPointer(k_thread_stack_t *stack) { m_stack = stack; }
227 uint32_t m_stackSize;
229 thread_stack_pointer m_stackPtr;
230 #if ERPC_THREADS_IS(PTHREADS) 231 static pthread_key_t s_threadObjectKey;
233 #elif ERPC_THREADS_IS(FREERTOS) 237 #if ERPC_ALLOCATION_POLICY == ERPC_ALLOCATION_POLICY_STATIC 238 StaticTask_t m_staticTask;
240 #elif ERPC_THREADS_IS(ZEPHYR) 241 struct k_thread m_thread;
243 k_thread_stack_t *m_stack;
244 #elif ERPC_THREADS_IS(MBED) 245 rtos::Thread *m_thread;
248 #elif ERPC_THREADS_IS(WIN32) 250 unsigned int m_thrdaddr;
253 static CRITICAL_SECTION m_critical_section;
254 static BOOL m_critical_section_inited;
255 #elif ERPC_THREADS_IS(THREADX) 261 #if ERPC_THREADS_IS(PTHREADS) 268 static void *threadEntryPointStub(
void *arg);
269 #elif ERPC_THREADS_IS(FREERTOS) 276 static void threadEntryPointStub(
void *arg);
277 #elif ERPC_THREADS_IS(ZEPHYR) 286 static void threadEntryPointStub(
void *arg1,
void *arg2,
void *arg3);
288 #elif ERPC_THREADS_IS(MBED) 295 static void threadEntryPointStub(
void *arg);
297 #elif ERPC_THREADS_IS(WIN32) 304 static unsigned WINAPI threadEntryPointStub(
void *arg);
306 #elif ERPC_THREADS_IS(THREADX) 313 static void threadEntryPointStub(ULONG arg);
353 Guard(
Mutex &mutex) : m_mutex(mutex) { (void)m_mutex.lock(); }
397 #if ERPC_THREADS_IS(PTHREADS) 403 pthread_mutex_t *getPtr(
void) {
return &m_mutex; }
407 #if ERPC_THREADS_IS(PTHREADS) 408 pthread_mutex_t m_mutex;
409 #elif ERPC_THREADS_IS(FREERTOS) 410 SemaphoreHandle_t m_mutex;
411 StaticSemaphore_t m_staticQueue;
412 #elif ERPC_THREADS_IS(ZEPHYR) 413 struct k_mutex m_mutex;
414 #elif ERPC_THREADS_IS(MBED) 415 rtos::Mutex *m_mutex;
416 #elif ERPC_THREADS_IS(WIN32) 418 #elif ERPC_THREADS_IS(THREADX) 448 static const uint32_t kWaitForever = 0xffffffffu;
467 #if ERPC_THREADS_IS(FREERTOS) 471 void putFromISR(
void);
472 #endif // ERPC_HAS_FREERTOS 482 bool get(uint32_t timeoutUsecs = kWaitForever);
489 int getCount(
void)
const;
492 #if ERPC_THREADS_IS(PTHREADS) 494 pthread_cond_t m_cond;
497 #elif ERPC_THREADS_IS(FREERTOS) 498 SemaphoreHandle_t m_sem;
499 StaticSemaphore_t m_staticQueue;
500 #elif ERPC_THREADS_IS(ZEPHYR) 502 #elif ERPC_THREADS_IS(MBED) 503 rtos::Semaphore *m_sem;
505 #elif ERPC_THREADS_IS(WIN32) 509 #elif ERPC_THREADS_IS(THREADX) 530 #endif // defined(__cplusplus) 534 #endif // ERPC_THREADS 536 #endif // defined(__embedded_rpc__thread__) void init(thread_entry_t entry, uint32_t priority=0, uint32_t stackSize=0, thread_stack_pointer stackPtr=NULL)
This function initializes thread.
Definition: erpc_threading_pthreads.cpp:48
bool operator==(Thread &o)
Compare operator compares two threads.
Definition: erpc_threading_pthreads.cpp:69
void(* thread_entry_t)(void *arg)
Thread function type.
Definition: erpc_threading.h:55
static thread_id_t getCurrentThreadId(void)
This function returns thread id where function is called.
Definition: erpc_threading.h:174
Simple thread class.
Definition: erpc_threading.h:69
~Guard(void)
Destructor.
Definition: erpc_threading.h:357
static void sleep(uint32_t usecs)
This function puts thread to sleep.
Definition: erpc_threading_pthreads.cpp:81
void setName(const char *name)
This function sets name for thread.
Definition: erpc_threading.h:114
const char * getName(void) const
This function returns name of thread.
Definition: erpc_threading.h:121
virtual ~Thread(void)
Destructor.
Definition: erpc_threading_pthreads.cpp:46
Definition: erpc_arbitrated_client_manager.hpp:25
Definition: erpc_threading.h:345
void * thread_id_t
Unique identifier for a thread.
Definition: erpc_threading.h:73
virtual void threadEntryPoint(void)
This function execute entry function.
Definition: erpc_threading_pthreads.cpp:103
static Thread * getCurrentThread(void)
This function returns Thread instance where functions is called.
Definition: erpc_threading_pthreads.cpp:74
thread_id_t getThreadId(void) const
This function returns current thread id.
Definition: erpc_threading.h:152
void start(void *arg=0)
This function starts thread execution.
Definition: erpc_threading_pthreads.cpp:56
Guard(Mutex &mutex)
Constructor.
Definition: erpc_threading.h:353
Mutex.
Definition: erpc_threading.h:339
Simple semaphore class.
Definition: erpc_threading.h:442
Thread(const char *name=0)
Default constructor for use with the init() method.
Definition: erpc_threading_pthreads.cpp:37