10 #ifndef __embedded_rpc__thread__ 11 #define __embedded_rpc__thread__ 13 #include "erpc_config_internal.h" 18 #if !ERPC_THREADS_IS(NONE) 20 #if ERPC_THREADS_IS(PTHREADS) 22 #elif ERPC_THREADS_IS(FREERTOS) 26 #elif ERPC_THREADS_IS(ZEPHYR) 28 #elif ERPC_THREADS_IS(MBED) 29 #if MBED_CONF_RTOS_PRESENT 32 #warning mbed-rpc: Threading is enabled but Mbed RTOS is not present! 34 #elif ERPC_THREADS_IS(WIN32) 37 #endif // ERPC_THREADS 58 #if defined(__cplusplus) 80 Thread(
const char *name = 0);
92 Thread(
thread_entry_t entry, uint32_t priority = 0, uint32_t stackSize = 0,
const char *name = 0);
104 void setName(
const char *name) { m_name = name; }
111 const char *
getName(
void)
const {
return m_name; }
127 void start(
void *arg = 0);
134 static void sleep(uint32_t usecs);
143 #if ERPC_THREADS_IS(PTHREADS) 144 return reinterpret_cast<thread_id_t
>(m_thread);
145 #elif ERPC_THREADS_IS(FREERTOS) 146 return reinterpret_cast<thread_id_t
>(m_task);
147 #elif ERPC_THREADS_IS(ZEPHYR) 148 return reinterpret_cast<thread_id_t
>(m_thread);
149 #elif ERPC_THREADS_IS(MBED) 150 return reinterpret_cast<thread_id_t
>(m_thread->get_id());
151 #elif ERPC_THREADS_IS(WIN32) 152 return reinterpret_cast<thread_id_t
>(m_thread);
163 #if ERPC_THREADS_IS(PTHREADS) 164 return reinterpret_cast<thread_id_t
>(pthread_self());
165 #elif ERPC_THREADS_IS(FREERTOS) 166 return reinterpret_cast<thread_id_t
>(xTaskGetCurrentTaskHandle());
167 #elif ERPC_THREADS_IS(ZEPHYR) 168 return reinterpret_cast<thread_id_t
>(k_current_get());
169 #elif ERPC_THREADS_IS(MBED) 170 return reinterpret_cast<thread_id_t
>(rtos::ThisThread::get_id());
171 #elif ERPC_THREADS_IS(WIN32) 172 return reinterpret_cast<thread_id_t
>(GetCurrentThread());
176 #if ERPC_THREADS_IS(ZEPHYR) 182 void setStackPointer(k_thread_stack_t *stack) { m_stack = stack; }
212 uint32_t m_stackSize;
214 #if ERPC_THREADS_IS(PTHREADS) 215 static pthread_key_t s_threadObjectKey;
217 #elif ERPC_THREADS_IS(FREERTOS) 221 #elif ERPC_THREADS_IS(ZEPHYR) 222 struct k_thread m_thread;
223 k_thread_stack_t *m_stack;
224 #elif ERPC_THREADS_IS(MBED) 225 rtos::Thread *m_thread;
228 #elif ERPC_THREADS_IS(WIN32) 230 unsigned int m_thrdaddr;
233 static CRITICAL_SECTION m_critical_section;
234 static BOOL m_critical_section_inited;
237 #if ERPC_THREADS_IS(PTHREADS) 244 static void *threadEntryPointStub(
void *arg);
245 #elif ERPC_THREADS_IS(FREERTOS) 252 static void threadEntryPointStub(
void *arg);
253 #elif ERPC_THREADS_IS(ZEPHYR) 262 static void *threadEntryPointStub(
void *arg1,
void *arg2,
void *arg3);
264 #elif ERPC_THREADS_IS(MBED) 271 static void threadEntryPointStub(
void *arg);
273 #elif ERPC_THREADS_IS(WIN32) 280 static unsigned WINAPI threadEntryPointStub(
void *arg);
369 #if ERPC_THREADS_IS(PTHREADS) 375 pthread_mutex_t *getPtr(
void) {
return &m_mutex; }
379 #if ERPC_THREADS_IS(PTHREADS) 380 pthread_mutex_t m_mutex;
381 #elif ERPC_THREADS_IS(FREERTOS) 382 SemaphoreHandle_t m_mutex;
383 #elif ERPC_THREADS_IS(ZEPHYR) 384 struct k_mutex m_mutex;
385 #elif ERPC_THREADS_IS(MBED) 386 rtos::Mutex *m_mutex;
387 #elif ERPC_THREADS_IS(WIN32) 417 static const uint32_t kWaitForever = 0xffffffff;
436 #if ERPC_THREADS_IS(FREERTOS) 440 void putFromISR(
void);
441 #endif // ERPC_HAS_FREERTOS 451 bool get(uint32_t timeout = kWaitForever);
458 int getCount(
void)
const;
461 #if ERPC_THREADS_IS(PTHREADS) 463 pthread_cond_t m_cond;
466 #elif ERPC_THREADS_IS(FREERTOS) 467 SemaphoreHandle_t m_sem;
468 #elif ERPC_THREADS_IS(ZEPHYR) 470 #elif ERPC_THREADS_IS(MBED) 471 rtos::Semaphore *m_sem;
473 #elif ERPC_THREADS_IS(WIN32) 496 #endif // defined(__cplusplus) 500 #endif // ERPC_THREADS 502 #endif // defined(__embedded_rpc__thread__) bool operator==(Thread &o)
Compare operator compares two threads.
Definition: erpc_threading_pthreads.cpp:79
void init(thread_entry_t entry, uint32_t priority=0, uint32_t stackSize=0)
This function initializes thread.
Definition: erpc_threading_pthreads.cpp:59
void(* thread_entry_t)(void *arg)
Thread function type.
Definition: erpc_threading.h:52
static thread_id_t getCurrentThreadId(void)
This function returns thread id where function is called.
Definition: erpc_threading.h:161
Simple thread class.
Definition: erpc_threading.h:66
~Guard(void)
Destructor.
Definition: erpc_threading.h:329
static void sleep(uint32_t usecs)
This function puts thread to sleep.
Definition: erpc_threading_pthreads.cpp:91
void setName(const char *name)
This function sets name for thread.
Definition: erpc_threading.h:104
const char * getName(void) const
This function returns name of thread.
Definition: erpc_threading.h:111
virtual ~Thread(void)
Destructor.
Definition: erpc_threading_pthreads.cpp:57
Definition: erpc_arbitrated_client_manager.h:25
Definition: erpc_threading.h:313
void * thread_id_t
Unique identifier for a thread.
Definition: erpc_threading.h:70
virtual void threadEntryPoint(void)
This function execute entry function.
Definition: erpc_threading_pthreads.cpp:113
static Thread * getCurrentThread(void)
This function returns Thread instance where functions is called.
Definition: erpc_threading_pthreads.cpp:84
thread_id_t getThreadId(void) const
This function returns current thread id.
Definition: erpc_threading.h:141
void start(void *arg=0)
This function starts thread execution.
Definition: erpc_threading_pthreads.cpp:66
Guard(Mutex &mutex)
Constructor.
Definition: erpc_threading.h:321
Mutex.
Definition: erpc_threading.h:307
Simple semaphore class.
Definition: erpc_threading.h:411
Thread(const char *name=0)
Default constructor for use with the init() method.
Definition: erpc_threading_pthreads.cpp:37