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) 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 = 0);
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 = 0);
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);
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;
242 k_thread_stack_t *m_stack;
243 #elif ERPC_THREADS_IS(MBED) 244 rtos::Thread *m_thread;
247 #elif ERPC_THREADS_IS(WIN32) 249 unsigned int m_thrdaddr;
252 static CRITICAL_SECTION m_critical_section;
253 static BOOL m_critical_section_inited;
254 #elif ERPC_THREADS_IS(THREADX) 260 #if ERPC_THREADS_IS(PTHREADS) 267 static void *threadEntryPointStub(
void *arg);
268 #elif ERPC_THREADS_IS(FREERTOS) 275 static void threadEntryPointStub(
void *arg);
276 #elif ERPC_THREADS_IS(ZEPHYR) 285 static void *threadEntryPointStub(
void *arg1,
void *arg2,
void *arg3);
287 #elif ERPC_THREADS_IS(MBED) 294 static void threadEntryPointStub(
void *arg);
296 #elif ERPC_THREADS_IS(WIN32) 303 static unsigned WINAPI threadEntryPointStub(
void *arg);
305 #elif ERPC_THREADS_IS(THREADX) 312 static void threadEntryPointStub(ULONG arg);
400 #if ERPC_THREADS_IS(PTHREADS) 406 pthread_mutex_t *getPtr(
void) {
return &m_mutex; }
410 #if ERPC_THREADS_IS(PTHREADS) 411 pthread_mutex_t m_mutex;
412 #elif ERPC_THREADS_IS(FREERTOS) 413 SemaphoreHandle_t m_mutex;
414 StaticSemaphore_t m_staticQueue;
415 #elif ERPC_THREADS_IS(ZEPHYR) 416 struct k_mutex m_mutex;
417 #elif ERPC_THREADS_IS(MBED) 418 rtos::Mutex *m_mutex;
419 #elif ERPC_THREADS_IS(WIN32) 421 #elif ERPC_THREADS_IS(THREADX) 451 static const uint32_t kWaitForever = 0xffffffff;
470 #if ERPC_THREADS_IS(FREERTOS) 474 void putFromISR(
void);
475 #endif // ERPC_HAS_FREERTOS 485 bool get(uint32_t timeout = kWaitForever);
492 int getCount(
void)
const;
495 #if ERPC_THREADS_IS(PTHREADS) 497 pthread_cond_t m_cond;
500 #elif ERPC_THREADS_IS(FREERTOS) 501 SemaphoreHandle_t m_sem;
502 StaticSemaphore_t m_staticQueue;
503 #elif ERPC_THREADS_IS(ZEPHYR) 505 #elif ERPC_THREADS_IS(MBED) 506 rtos::Semaphore *m_sem;
508 #elif ERPC_THREADS_IS(WIN32) 512 #elif ERPC_THREADS_IS(THREADX) 533 #endif // defined(__cplusplus) 537 #endif // ERPC_THREADS 539 #endif // defined(__embedded_rpc__thread__) bool operator==(Thread &o)
Compare operator compares two threads.
Definition: erpc_threading_pthreads.cpp:81
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:360
static void sleep(uint32_t usecs)
This function puts thread to sleep.
Definition: erpc_threading_pthreads.cpp:93
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:58
Definition: erpc_arbitrated_client_manager.h:25
Definition: erpc_threading.h:344
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:115
static Thread * getCurrentThread(void)
This function returns Thread instance where functions is called.
Definition: erpc_threading_pthreads.cpp:86
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:68
void init(thread_entry_t entry, uint32_t priority=0, uint32_t stackSize=0, thread_stack_pointer stackPtr=0)
This function initializes thread.
Definition: erpc_threading_pthreads.cpp:60
Guard(Mutex &mutex)
Constructor.
Definition: erpc_threading.h:352
Mutex.
Definition: erpc_threading.h:338
Simple semaphore class.
Definition: erpc_threading.h:445
Thread(const char *name=0)
Default constructor for use with the init() method.
Definition: erpc_threading_pthreads.cpp:37