10 #ifndef __embedded_rpc__thread__ 11 #define __embedded_rpc__thread__ 13 #include "erpc_config_internal.h" 19 #if ERPC_THREADS_IS(PTHREADS) 21 #elif ERPC_THREADS_IS(FREERTOS) 25 #elif ERPC_THREADS_IS(ZEPHYR) 27 #elif ERPC_THREADS_IS(MBED) 28 #if MBED_CONF_RTOS_PRESENT 31 #warning mbed-rpc: Threading is enabled but Mbed RTOS is not present! 33 #endif // ERPC_THREADS_IS 54 #if defined(__cplusplus) 76 Thread(
const char *name = 0);
88 Thread(
thread_entry_t entry, uint32_t priority = 0, uint32_t stackSize = 0,
const char *name = 0);
100 void setName(
const char *name) { m_name = name; }
107 const char *
getName(
void)
const {
return m_name; }
123 void start(
void *arg = 0);
130 static void sleep(uint32_t usecs);
139 #if ERPC_THREADS_IS(PTHREADS) 140 return reinterpret_cast<thread_id_t
>(m_thread);
141 #elif ERPC_THREADS_IS(FREERTOS) 142 return reinterpret_cast<thread_id_t
>(m_task);
143 #elif ERPC_THREADS_IS(ZEPHYR) 144 return reinterpret_cast<thread_id_t
>(m_thread);
145 #elif ERPC_THREADS_IS(MBED) 146 return reinterpret_cast<thread_id_t
>(m_thread->get_id());
157 #if ERPC_THREADS_IS(PTHREADS) 158 return reinterpret_cast<thread_id_t
>(pthread_self());
159 #elif ERPC_THREADS_IS(FREERTOS) 160 return reinterpret_cast<thread_id_t
>(xTaskGetCurrentTaskHandle());
161 #elif ERPC_THREADS_IS(ZEPHYR) 162 return reinterpret_cast<thread_id_t
>(k_current_get());
163 #elif ERPC_THREADS_IS(MBED) 164 return reinterpret_cast<thread_id_t
>(rtos::ThisThread::get_id());
168 #if ERPC_THREADS_IS(ZEPHYR) 174 void setStackPointer(k_thread_stack_t *stack) { m_stack = stack; }
204 uint32_t m_stackSize;
206 #if ERPC_THREADS_IS(PTHREADS) 207 static pthread_key_t s_threadObjectKey;
209 #elif ERPC_THREADS_IS(FREERTOS) 213 #elif ERPC_THREADS_IS(ZEPHYR) 214 struct k_thread m_thread;
215 k_thread_stack_t *m_stack;
216 #elif ERPC_THREADS_IS(MBED) 217 rtos::Thread *m_thread;
222 #if ERPC_THREADS_IS(PTHREADS) 229 static void *threadEntryPointStub(
void *arg);
230 #elif ERPC_THREADS_IS(FREERTOS) 237 static void threadEntryPointStub(
void *arg);
238 #elif ERPC_THREADS_IS(ZEPHYR) 247 static void *threadEntryPointStub(
void *arg1,
void *arg2,
void *arg3);
249 #elif ERPC_THREADS_IS(MBED) 256 static void threadEntryPointStub(
void *arg);
345 #if ERPC_THREADS_IS(PTHREADS) 351 pthread_mutex_t *getPtr(
void) {
return &m_mutex; }
355 #if ERPC_THREADS_IS(PTHREADS) 356 pthread_mutex_t m_mutex;
357 #elif ERPC_THREADS_IS(FREERTOS) 358 SemaphoreHandle_t m_mutex;
359 #elif ERPC_THREADS_IS(ZEPHYR) 360 struct k_mutex m_mutex;
361 #elif ERPC_THREADS_IS(MBED) 362 rtos::Mutex *m_mutex;
391 static const uint32_t kWaitForever = 0xffffffff;
410 #if ERPC_THREADS_IS(FREERTOS) 414 void putFromISR(
void);
415 #endif // ERPC_HAS_FREERTOS 425 bool get(uint32_t timeout = kWaitForever);
432 int getCount(
void)
const;
435 #if ERPC_THREADS_IS(PTHREADS) 437 pthread_cond_t m_cond;
440 #elif ERPC_THREADS_IS(FREERTOS) 441 SemaphoreHandle_t m_sem;
442 #elif ERPC_THREADS_IS(ZEPHYR) 444 #elif ERPC_THREADS_IS(MBED) 445 rtos::Semaphore *m_sem;
466 #endif // defined(__cplusplus) 470 #endif // ERPC_THREADS 472 #endif // defined(__embedded_rpc__thread__) bool operator==(Thread &o)
Compare operator compares two threads.
Definition: erpc_threading_pthreads.cpp:72
void init(thread_entry_t entry, uint32_t priority=0, uint32_t stackSize=0)
This function initializes thread.
Definition: erpc_threading_pthreads.cpp:52
void(* thread_entry_t)(void *arg)
Thread function type.
Definition: erpc_threading.h:48
static thread_id_t getCurrentThreadId(void)
This function returns thread id where function is called.
Definition: erpc_threading.h:155
Simple thread class.
Definition: erpc_threading.h:62
~Guard(void)
Destructor.
Definition: erpc_threading.h:305
static void sleep(uint32_t usecs)
This function puts thread to sleep.
Definition: erpc_threading_pthreads.cpp:83
void setName(const char *name)
This function sets name for thread.
Definition: erpc_threading.h:100
const char * getName(void) const
This function returns name of thread.
Definition: erpc_threading.h:107
virtual ~Thread(void)
Destructor.
Definition: erpc_threading_pthreads.cpp:50
Definition: erpc_arbitrated_client_manager.h:25
Definition: erpc_threading.h:289
void * thread_id_t
Unique identifier for a thread.
Definition: erpc_threading.h:66
virtual void threadEntryPoint(void)
This function execute entry function.
Definition: erpc_threading_pthreads.cpp:102
static Thread * getCurrentThread(void)
This function returns Thread instance where functions is called.
Definition: erpc_threading_pthreads.cpp:77
thread_id_t getThreadId(void) const
This function returns current thread id.
Definition: erpc_threading.h:137
void start(void *arg=0)
This function starts thread execution.
Definition: erpc_threading_pthreads.cpp:59
Guard(Mutex &mutex)
Constructor.
Definition: erpc_threading.h:297
Mutex.
Definition: erpc_threading.h:283
Simple semaphore class.
Definition: erpc_threading.h:385
Thread(const char *name=0)
Default constructor for use with the init() method.
Definition: erpc_threading_pthreads.cpp:30