mirror of https://github.com/ARMmbed/mbed-os.git
Style clean-up of Thread-related files
parent
96af5a447e
commit
6477b762d1
|
|
@ -26,7 +26,8 @@
|
|||
|
||||
namespace rtos {
|
||||
|
||||
uint64_t Kernel::get_ms_count() {
|
||||
uint64_t Kernel::get_ms_count()
|
||||
{
|
||||
// CMSIS-RTOS 2.1.0 and 2.1.1 differ in the time type. We assume
|
||||
// our header at least matches the implementation, so we don't try looking
|
||||
// at the run-time version report. (There's no compile-time version report)
|
||||
|
|
@ -36,7 +37,7 @@ uint64_t Kernel::get_ms_count() {
|
|||
// 2.1.x who knows? We assume could go back to uint64_t
|
||||
if (sizeof osKernelGetTickCount() == sizeof(uint64_t)) {
|
||||
return osKernelGetTickCount();
|
||||
} else /* assume 32-bit */ {
|
||||
} else { /* assume 32-bit */
|
||||
// Based on suggestion in CMSIS-RTOS 2.1.1 docs, but with reentrancy
|
||||
// protection for the tick memory. We use critical section rather than a
|
||||
// mutex, as hopefully this method can be callable from interrupt later -
|
||||
|
|
|
|||
|
|
@ -32,43 +32,43 @@
|
|||
extern void rtos_idle_loop(void);
|
||||
extern void thread_terminate_hook(osThreadId_t id);
|
||||
|
||||
__NO_RETURN void osRtxIdleThread (void *argument)
|
||||
__NO_RETURN void osRtxIdleThread(void *argument)
|
||||
{
|
||||
for (;;) {
|
||||
rtos_idle_loop();
|
||||
rtos_idle_loop();
|
||||
}
|
||||
}
|
||||
|
||||
__NO_RETURN uint32_t osRtxErrorNotify (uint32_t code, void *object_id)
|
||||
__NO_RETURN uint32_t osRtxErrorNotify(uint32_t code, void *object_id)
|
||||
{
|
||||
osThreadId_t tid = osThreadGetId();
|
||||
|
||||
switch (code) {
|
||||
case osRtxErrorStackUnderflow:
|
||||
// Stack underflow detected for thread (thread_id=object_id)
|
||||
// Note: "overflow" is printed instead of "underflow" due to end user familiarity with overflow errors
|
||||
MBED_ERROR1(MBED_MAKE_ERROR(MBED_MODULE_KERNEL, MBED_ERROR_CODE_STACK_OVERFLOW), "CMSIS-RTOS error: Stack overflow", code);
|
||||
break;
|
||||
case osRtxErrorISRQueueOverflow:
|
||||
// ISR Queue overflow detected when inserting object (object_id)
|
||||
MBED_ERROR1(MBED_MAKE_ERROR(MBED_MODULE_KERNEL, MBED_ERROR_CODE_ISR_QUEUE_OVERFLOW), "CMSIS-RTOS error: ISR Queue overflow", code);
|
||||
break;
|
||||
case osRtxErrorTimerQueueOverflow:
|
||||
// User Timer Callback Queue overflow detected for timer (timer_id=object_id)
|
||||
MBED_ERROR1(MBED_MAKE_ERROR(MBED_MODULE_KERNEL, MBED_ERROR_CODE_TIMER_QUEUE_OVERFLOW), "CMSIS-RTOS error: User Timer Callback Queue overflow", code);
|
||||
break;
|
||||
case osRtxErrorClibSpace:
|
||||
// Standard C/C++ library libspace not available: increase OS_THREAD_LIBSPACE_NUM
|
||||
MBED_ERROR1(MBED_MAKE_ERROR(MBED_MODULE_KERNEL, MBED_ERROR_CODE_CLIB_SPACE_UNAVAILABLE), "CMSIS-RTOS error: STD C/C++ library libspace not available", code);
|
||||
break;
|
||||
case osRtxErrorClibMutex:
|
||||
// Standard C/C++ library mutex initialization failed
|
||||
MBED_ERROR1(MBED_MAKE_ERROR(MBED_MODULE_KERNEL, MBED_ERROR_CODE_CLIB_MUTEX_INIT_FAILURE), "CMSIS-RTOS error: STD C/C++ library mutex initialization failed", code);
|
||||
break;
|
||||
default:
|
||||
//Unknown error flagged from kernel
|
||||
MBED_ERROR1(MBED_MAKE_ERROR(MBED_MODULE_KERNEL, MBED_ERROR_CODE_UNKNOWN), "CMSIS-RTOS error: Unknown", code);
|
||||
break;
|
||||
case osRtxErrorStackUnderflow:
|
||||
// Stack underflow detected for thread (thread_id=object_id)
|
||||
// Note: "overflow" is printed instead of "underflow" due to end user familiarity with overflow errors
|
||||
MBED_ERROR1(MBED_MAKE_ERROR(MBED_MODULE_KERNEL, MBED_ERROR_CODE_STACK_OVERFLOW), "CMSIS-RTOS error: Stack overflow", code);
|
||||
break;
|
||||
case osRtxErrorISRQueueOverflow:
|
||||
// ISR Queue overflow detected when inserting object (object_id)
|
||||
MBED_ERROR1(MBED_MAKE_ERROR(MBED_MODULE_KERNEL, MBED_ERROR_CODE_ISR_QUEUE_OVERFLOW), "CMSIS-RTOS error: ISR Queue overflow", code);
|
||||
break;
|
||||
case osRtxErrorTimerQueueOverflow:
|
||||
// User Timer Callback Queue overflow detected for timer (timer_id=object_id)
|
||||
MBED_ERROR1(MBED_MAKE_ERROR(MBED_MODULE_KERNEL, MBED_ERROR_CODE_TIMER_QUEUE_OVERFLOW), "CMSIS-RTOS error: User Timer Callback Queue overflow", code);
|
||||
break;
|
||||
case osRtxErrorClibSpace:
|
||||
// Standard C/C++ library libspace not available: increase OS_THREAD_LIBSPACE_NUM
|
||||
MBED_ERROR1(MBED_MAKE_ERROR(MBED_MODULE_KERNEL, MBED_ERROR_CODE_CLIB_SPACE_UNAVAILABLE), "CMSIS-RTOS error: STD C/C++ library libspace not available", code);
|
||||
break;
|
||||
case osRtxErrorClibMutex:
|
||||
// Standard C/C++ library mutex initialization failed
|
||||
MBED_ERROR1(MBED_MAKE_ERROR(MBED_MODULE_KERNEL, MBED_ERROR_CODE_CLIB_MUTEX_INIT_FAILURE), "CMSIS-RTOS error: STD C/C++ library mutex initialization failed", code);
|
||||
break;
|
||||
default:
|
||||
//Unknown error flagged from kernel
|
||||
MBED_ERROR1(MBED_MAKE_ERROR(MBED_MODULE_KERNEL, MBED_ERROR_CODE_UNKNOWN), "CMSIS-RTOS error: Unknown", code);
|
||||
break;
|
||||
}
|
||||
|
||||
/* That shouldn't be reached */
|
||||
|
|
@ -77,52 +77,52 @@ __NO_RETURN uint32_t osRtxErrorNotify (uint32_t code, void *object_id)
|
|||
|
||||
#if defined(MBED_TRAP_ERRORS_ENABLED) && MBED_TRAP_ERRORS_ENABLED
|
||||
|
||||
static const char* error_msg(int32_t status)
|
||||
static const char *error_msg(int32_t status)
|
||||
{
|
||||
switch (status) {
|
||||
case osError:
|
||||
return "Unspecified RTOS error";
|
||||
case osErrorTimeout:
|
||||
return "Operation not completed within the timeout period";
|
||||
case osErrorResource:
|
||||
return "Resource not available";
|
||||
case osErrorParameter:
|
||||
return "Parameter error";
|
||||
case osErrorNoMemory:
|
||||
return "System is out of memory";
|
||||
case osErrorISR:
|
||||
return "Not allowed in ISR context";
|
||||
default:
|
||||
return "Unknown";
|
||||
case osError:
|
||||
return "Unspecified RTOS error";
|
||||
case osErrorTimeout:
|
||||
return "Operation not completed within the timeout period";
|
||||
case osErrorResource:
|
||||
return "Resource not available";
|
||||
case osErrorParameter:
|
||||
return "Parameter error";
|
||||
case osErrorNoMemory:
|
||||
return "System is out of memory";
|
||||
case osErrorISR:
|
||||
return "Not allowed in ISR context";
|
||||
default:
|
||||
return "Unknown";
|
||||
}
|
||||
}
|
||||
|
||||
void EvrRtxKernelError (int32_t status)
|
||||
void EvrRtxKernelError(int32_t status)
|
||||
{
|
||||
MBED_ERROR1(MBED_MAKE_ERROR(MBED_MODULE_PLATFORM, MBED_ERROR_CODE_RTOS_EVENT), error_msg(status), status);
|
||||
}
|
||||
|
||||
void EvrRtxThreadError (osThreadId_t thread_id, int32_t status)
|
||||
void EvrRtxThreadError(osThreadId_t thread_id, int32_t status)
|
||||
{
|
||||
MBED_ERROR1(MBED_MAKE_ERROR(MBED_MODULE_PLATFORM, MBED_ERROR_CODE_RTOS_THREAD_EVENT), error_msg(status), thread_id);
|
||||
}
|
||||
|
||||
void EvrRtxTimerError (osTimerId_t timer_id, int32_t status)
|
||||
void EvrRtxTimerError(osTimerId_t timer_id, int32_t status)
|
||||
{
|
||||
MBED_ERROR1(MBED_MAKE_ERROR(MBED_MODULE_PLATFORM, MBED_ERROR_CODE_RTOS_TIMER_EVENT), error_msg(status), timer_id);
|
||||
}
|
||||
|
||||
void EvrRtxEventFlagsError (osEventFlagsId_t ef_id, int32_t status)
|
||||
void EvrRtxEventFlagsError(osEventFlagsId_t ef_id, int32_t status)
|
||||
{
|
||||
MBED_ERROR1(MBED_MAKE_ERROR(MBED_MODULE_PLATFORM, MBED_ERROR_CODE_RTOS_EVENT_FLAGS_EVENT), error_msg(status), ef_id);
|
||||
}
|
||||
|
||||
void EvrRtxMutexError (osMutexId_t mutex_id, int32_t status)
|
||||
void EvrRtxMutexError(osMutexId_t mutex_id, int32_t status)
|
||||
{
|
||||
MBED_ERROR1(MBED_MAKE_ERROR(MBED_MODULE_PLATFORM, MBED_ERROR_CODE_RTOS_MUTEX_EVENT), error_msg(status), mutex_id);
|
||||
}
|
||||
|
||||
void EvrRtxSemaphoreError (osSemaphoreId_t semaphore_id, int32_t status)
|
||||
void EvrRtxSemaphoreError(osSemaphoreId_t semaphore_id, int32_t status)
|
||||
{
|
||||
// Ignore semaphore overflow, the count will saturate with a returned error
|
||||
if (status == osRtxErrorSemaphoreCountLimit) {
|
||||
|
|
@ -132,12 +132,12 @@ void EvrRtxSemaphoreError (osSemaphoreId_t semaphore_id, int32_t status)
|
|||
MBED_ERROR1(MBED_MAKE_ERROR(MBED_MODULE_PLATFORM, MBED_ERROR_CODE_RTOS_SEMAPHORE_EVENT), error_msg(status), semaphore_id);
|
||||
}
|
||||
|
||||
void EvrRtxMemoryPoolError (osMemoryPoolId_t mp_id, int32_t status)
|
||||
void EvrRtxMemoryPoolError(osMemoryPoolId_t mp_id, int32_t status)
|
||||
{
|
||||
MBED_ERROR1(MBED_MAKE_ERROR(MBED_MODULE_PLATFORM, MBED_ERROR_CODE_RTOS_MEMORY_POOL_EVENT), error_msg(status), mp_id);
|
||||
}
|
||||
|
||||
void EvrRtxMessageQueueError (osMessageQueueId_t mq_id, int32_t status)
|
||||
void EvrRtxMessageQueueError(osMessageQueueId_t mq_id, int32_t status)
|
||||
{
|
||||
MBED_ERROR1(MBED_MAKE_ERROR(MBED_MODULE_PLATFORM, MBED_ERROR_CODE_RTOS_MESSAGE_QUEUE_EVENT), error_msg(status), mq_id);
|
||||
}
|
||||
|
|
@ -145,7 +145,7 @@ void EvrRtxMessageQueueError (osMessageQueueId_t mq_id, int32_t status)
|
|||
#endif
|
||||
|
||||
// RTX hook which gets called when a thread terminates, using the event function to call hook
|
||||
void EvrRtxThreadExit (void)
|
||||
void EvrRtxThreadExit(void)
|
||||
{
|
||||
osThreadId_t thread_id = osThreadGetId();
|
||||
thread_terminate_hook(thread_id);
|
||||
|
|
@ -154,7 +154,7 @@ void EvrRtxThreadExit (void)
|
|||
#endif
|
||||
}
|
||||
|
||||
void EvrRtxThreadTerminate (osThreadId_t thread_id)
|
||||
void EvrRtxThreadTerminate(osThreadId_t thread_id)
|
||||
{
|
||||
thread_terminate_hook(thread_id);
|
||||
#if (!defined(EVR_RTX_DISABLE) && (OS_EVR_THREAD != 0) && !defined(EVR_RTX_THREAD_TERMINATE_DISABLE) && defined(RTE_Compiler_EventRecorder))
|
||||
|
|
|
|||
|
|
@ -48,7 +48,8 @@ namespace rtos {
|
|||
#endif
|
||||
|
||||
void Thread::constructor(uint32_t tz_module, osPriority priority,
|
||||
uint32_t stack_size, unsigned char *stack_mem, const char *name) {
|
||||
uint32_t stack_size, unsigned char *stack_mem, const char *name)
|
||||
{
|
||||
|
||||
const uintptr_t unaligned_mem = reinterpret_cast<uintptr_t>(stack_mem);
|
||||
const uintptr_t aligned_mem = ALIGN_UP(unaligned_mem, 8);
|
||||
|
|
@ -63,17 +64,19 @@ void Thread::constructor(uint32_t tz_module, osPriority priority,
|
|||
_attr.priority = priority;
|
||||
_attr.stack_size = aligned_size;
|
||||
_attr.name = name ? name : "application_unnamed_thread";
|
||||
_attr.stack_mem = reinterpret_cast<uint32_t*>(aligned_mem);
|
||||
_attr.stack_mem = reinterpret_cast<uint32_t *>(aligned_mem);
|
||||
_attr.tz_module = tz_module;
|
||||
}
|
||||
|
||||
void Thread::constructor(osPriority priority,
|
||||
uint32_t stack_size, unsigned char *stack_mem, const char *name) {
|
||||
uint32_t stack_size, unsigned char *stack_mem, const char *name)
|
||||
{
|
||||
constructor(MBED_TZ_DEFAULT_ACCESS, priority, stack_size, stack_mem, name);
|
||||
}
|
||||
|
||||
void Thread::constructor(Callback<void()> task,
|
||||
osPriority priority, uint32_t stack_size, unsigned char *stack_mem, const char *name) {
|
||||
osPriority priority, uint32_t stack_size, unsigned char *stack_mem, const char *name)
|
||||
{
|
||||
constructor(MBED_TZ_DEFAULT_ACCESS, priority, stack_size, stack_mem, name);
|
||||
|
||||
switch (start(task)) {
|
||||
|
|
@ -90,7 +93,8 @@ void Thread::constructor(Callback<void()> task,
|
|||
}
|
||||
}
|
||||
|
||||
osStatus Thread::start(Callback<void()> task) {
|
||||
osStatus Thread::start(Callback<void()> task)
|
||||
{
|
||||
_mutex.lock();
|
||||
|
||||
if ((_tid != 0) || _finished) {
|
||||
|
|
@ -99,7 +103,7 @@ osStatus Thread::start(Callback<void()> task) {
|
|||
}
|
||||
|
||||
if (_attr.stack_mem == NULL) {
|
||||
_attr.stack_mem = new uint32_t[_attr.stack_size/sizeof(uint32_t)];
|
||||
_attr.stack_mem = new uint32_t[_attr.stack_size / sizeof(uint32_t)];
|
||||
MBED_ASSERT(_attr.stack_mem != NULL);
|
||||
}
|
||||
|
||||
|
|
@ -115,8 +119,8 @@ osStatus Thread::start(Callback<void()> task) {
|
|||
_tid = osThreadNew(Thread::_thunk, this, &_attr);
|
||||
if (_tid == NULL) {
|
||||
if (_dynamic_stack) {
|
||||
delete[] (uint32_t *)(_attr.stack_mem);
|
||||
_attr.stack_mem = (uint32_t*)NULL;
|
||||
delete[](uint32_t *)(_attr.stack_mem);
|
||||
_attr.stack_mem = (uint32_t *)NULL;
|
||||
}
|
||||
_mutex.unlock();
|
||||
_join_sem.release();
|
||||
|
|
@ -127,7 +131,8 @@ osStatus Thread::start(Callback<void()> task) {
|
|||
return osOK;
|
||||
}
|
||||
|
||||
osStatus Thread::terminate() {
|
||||
osStatus Thread::terminate()
|
||||
{
|
||||
osStatus_t ret = osOK;
|
||||
_mutex.lock();
|
||||
|
||||
|
|
@ -149,7 +154,8 @@ osStatus Thread::terminate() {
|
|||
return ret;
|
||||
}
|
||||
|
||||
osStatus Thread::join() {
|
||||
osStatus Thread::join()
|
||||
{
|
||||
int32_t ret = _join_sem.wait();
|
||||
if (ret < 0) {
|
||||
return osError;
|
||||
|
|
@ -167,7 +173,8 @@ osStatus Thread::join() {
|
|||
return osOK;
|
||||
}
|
||||
|
||||
osStatus Thread::set_priority(osPriority priority) {
|
||||
osStatus Thread::set_priority(osPriority priority)
|
||||
{
|
||||
osStatus_t ret;
|
||||
_mutex.lock();
|
||||
|
||||
|
|
@ -177,7 +184,8 @@ osStatus Thread::set_priority(osPriority priority) {
|
|||
return ret;
|
||||
}
|
||||
|
||||
osPriority Thread::get_priority() {
|
||||
osPriority Thread::get_priority()
|
||||
{
|
||||
osPriority_t ret;
|
||||
_mutex.lock();
|
||||
|
||||
|
|
@ -187,11 +195,13 @@ osPriority Thread::get_priority() {
|
|||
return ret;
|
||||
}
|
||||
|
||||
int32_t Thread::signal_set(int32_t flags) {
|
||||
int32_t Thread::signal_set(int32_t flags)
|
||||
{
|
||||
return osThreadFlagsSet(_tid, flags);
|
||||
}
|
||||
|
||||
Thread::State Thread::get_state() {
|
||||
Thread::State Thread::get_state()
|
||||
{
|
||||
uint8_t state = osThreadTerminated;
|
||||
|
||||
_mutex.lock();
|
||||
|
|
@ -208,7 +218,7 @@ Thread::State Thread::get_state() {
|
|||
|
||||
State user_state;
|
||||
|
||||
switch(state) {
|
||||
switch (state) {
|
||||
case osThreadInactive:
|
||||
user_state = Inactive;
|
||||
break;
|
||||
|
|
@ -256,7 +266,8 @@ Thread::State Thread::get_state() {
|
|||
return user_state;
|
||||
}
|
||||
|
||||
uint32_t Thread::stack_size() {
|
||||
uint32_t Thread::stack_size()
|
||||
{
|
||||
uint32_t size = 0;
|
||||
_mutex.lock();
|
||||
|
||||
|
|
@ -268,7 +279,8 @@ uint32_t Thread::stack_size() {
|
|||
return size;
|
||||
}
|
||||
|
||||
uint32_t Thread::free_stack() {
|
||||
uint32_t Thread::free_stack()
|
||||
{
|
||||
uint32_t size = 0;
|
||||
_mutex.lock();
|
||||
|
||||
|
|
@ -283,7 +295,8 @@ uint32_t Thread::free_stack() {
|
|||
return size;
|
||||
}
|
||||
|
||||
uint32_t Thread::used_stack() {
|
||||
uint32_t Thread::used_stack()
|
||||
{
|
||||
uint32_t size = 0;
|
||||
_mutex.lock();
|
||||
|
||||
|
|
@ -298,7 +311,8 @@ uint32_t Thread::used_stack() {
|
|||
return size;
|
||||
}
|
||||
|
||||
uint32_t Thread::max_stack() {
|
||||
uint32_t Thread::max_stack()
|
||||
{
|
||||
uint32_t size = 0;
|
||||
_mutex.lock();
|
||||
|
||||
|
|
@ -306,8 +320,9 @@ uint32_t Thread::max_stack() {
|
|||
#if defined(MBED_OS_BACKEND_RTX5)
|
||||
mbed_rtos_storage_thread_t *thread = (mbed_rtos_storage_thread_t *)_tid;
|
||||
uint32_t high_mark = 0;
|
||||
while ((((uint32_t *)(thread->stack_mem))[high_mark] == osRtxStackMagicWord) || (((uint32_t *)(thread->stack_mem))[high_mark] == osRtxStackFillPattern))
|
||||
while ((((uint32_t *)(thread->stack_mem))[high_mark] == osRtxStackMagicWord) || (((uint32_t *)(thread->stack_mem))[high_mark] == osRtxStackFillPattern)) {
|
||||
high_mark++;
|
||||
}
|
||||
size = thread->stack_size - (high_mark * sizeof(uint32_t));
|
||||
#else
|
||||
size = osThreadGetStackSize(_tid) - osThreadGetStackSpace(_tid);
|
||||
|
|
@ -318,15 +333,18 @@ uint32_t Thread::max_stack() {
|
|||
return size;
|
||||
}
|
||||
|
||||
const char *Thread::get_name() {
|
||||
const char *Thread::get_name()
|
||||
{
|
||||
return _attr.name;
|
||||
}
|
||||
|
||||
int32_t Thread::signal_clr(int32_t flags) {
|
||||
int32_t Thread::signal_clr(int32_t flags)
|
||||
{
|
||||
return osThreadFlagsClear(flags);
|
||||
}
|
||||
|
||||
osEvent Thread::signal_wait(int32_t signals, uint32_t millisec) {
|
||||
osEvent Thread::signal_wait(int32_t signals, uint32_t millisec)
|
||||
{
|
||||
uint32_t res;
|
||||
osEvent evt;
|
||||
uint32_t options = osFlagsWaitAll;
|
||||
|
|
@ -359,11 +377,13 @@ osEvent Thread::signal_wait(int32_t signals, uint32_t millisec) {
|
|||
return evt;
|
||||
}
|
||||
|
||||
osStatus Thread::wait(uint32_t millisec) {
|
||||
osStatus Thread::wait(uint32_t millisec)
|
||||
{
|
||||
return osDelay(millisec);
|
||||
}
|
||||
|
||||
osStatus Thread::wait_until(uint64_t millisec) {
|
||||
osStatus Thread::wait_until(uint64_t millisec)
|
||||
{
|
||||
// CMSIS-RTOS 2.1.0 and 2.1.1 differ in the time type, which we determine
|
||||
// by looking at the return type of osKernelGetTickCount. We assume
|
||||
// our header at least matches the implementation, so we don't try looking
|
||||
|
|
@ -392,34 +412,39 @@ osStatus Thread::wait_until(uint64_t millisec) {
|
|||
}
|
||||
}
|
||||
|
||||
osStatus Thread::yield() {
|
||||
osStatus Thread::yield()
|
||||
{
|
||||
return osThreadYield();
|
||||
}
|
||||
|
||||
osThreadId Thread::gettid() {
|
||||
osThreadId Thread::gettid()
|
||||
{
|
||||
return osThreadGetId();
|
||||
}
|
||||
|
||||
void Thread::attach_idle_hook(void (*fptr)(void)) {
|
||||
void Thread::attach_idle_hook(void (*fptr)(void))
|
||||
{
|
||||
rtos_attach_idle_hook(fptr);
|
||||
}
|
||||
|
||||
void Thread::attach_terminate_hook(void (*fptr)(osThreadId_t id)) {
|
||||
void Thread::attach_terminate_hook(void (*fptr)(osThreadId_t id))
|
||||
{
|
||||
terminate_hook = fptr;
|
||||
}
|
||||
|
||||
Thread::~Thread() {
|
||||
Thread::~Thread()
|
||||
{
|
||||
// terminate is thread safe
|
||||
terminate();
|
||||
if (_dynamic_stack) {
|
||||
delete[] (uint32_t*)(_attr.stack_mem);
|
||||
_attr.stack_mem = (uint32_t*)NULL;
|
||||
delete[](uint32_t *)(_attr.stack_mem);
|
||||
_attr.stack_mem = (uint32_t *)NULL;
|
||||
}
|
||||
}
|
||||
|
||||
void Thread::_thunk(void * thread_ptr)
|
||||
void Thread::_thunk(void *thread_ptr)
|
||||
{
|
||||
Thread *t = (Thread*)thread_ptr;
|
||||
Thread *t = (Thread *)thread_ptr;
|
||||
t->_task();
|
||||
t->_mutex.lock();
|
||||
t->_tid = (osThreadId)NULL;
|
||||
|
|
|
|||
103
rtos/Thread.h
103
rtos/Thread.h
|
|
@ -94,9 +94,10 @@ public:
|
|||
@note You cannot call this function from ISR context.
|
||||
*/
|
||||
|
||||
Thread(osPriority priority=osPriorityNormal,
|
||||
uint32_t stack_size=OS_STACK_SIZE,
|
||||
unsigned char *stack_mem=NULL, const char *name=NULL) {
|
||||
Thread(osPriority priority = osPriorityNormal,
|
||||
uint32_t stack_size = OS_STACK_SIZE,
|
||||
unsigned char *stack_mem = NULL, const char *name = NULL)
|
||||
{
|
||||
constructor(priority, stack_size, stack_mem, name);
|
||||
}
|
||||
|
||||
|
|
@ -113,9 +114,10 @@ public:
|
|||
@note You cannot call this function from ISR context.
|
||||
*/
|
||||
|
||||
Thread(uint32_t tz_module, osPriority priority=osPriorityNormal,
|
||||
uint32_t stack_size=OS_STACK_SIZE,
|
||||
unsigned char *stack_mem=NULL, const char *name=NULL) {
|
||||
Thread(uint32_t tz_module, osPriority priority = osPriorityNormal,
|
||||
uint32_t stack_size = OS_STACK_SIZE,
|
||||
unsigned char *stack_mem = NULL, const char *name = NULL)
|
||||
{
|
||||
constructor(tz_module, priority, stack_size, stack_mem, name);
|
||||
}
|
||||
|
||||
|
|
@ -140,12 +142,13 @@ public:
|
|||
@note You cannot call this function from ISR context.
|
||||
*/
|
||||
MBED_DEPRECATED_SINCE("mbed-os-5.1",
|
||||
"Thread-spawning constructors hide errors. "
|
||||
"Replaced by thread.start(task).")
|
||||
"Thread-spawning constructors hide errors. "
|
||||
"Replaced by thread.start(task).")
|
||||
Thread(mbed::Callback<void()> task,
|
||||
osPriority priority=osPriorityNormal,
|
||||
uint32_t stack_size=OS_STACK_SIZE,
|
||||
unsigned char *stack_mem=NULL) {
|
||||
osPriority priority = osPriorityNormal,
|
||||
uint32_t stack_size = OS_STACK_SIZE,
|
||||
unsigned char *stack_mem = NULL)
|
||||
{
|
||||
constructor(task, priority, stack_size, stack_mem);
|
||||
}
|
||||
|
||||
|
|
@ -171,12 +174,13 @@ public:
|
|||
*/
|
||||
template <typename T>
|
||||
MBED_DEPRECATED_SINCE("mbed-os-5.1",
|
||||
"Thread-spawning constructors hide errors. "
|
||||
"Replaced by thread.start(callback(task, argument)).")
|
||||
"Thread-spawning constructors hide errors. "
|
||||
"Replaced by thread.start(callback(task, argument)).")
|
||||
Thread(T *argument, void (T::*task)(),
|
||||
osPriority priority=osPriorityNormal,
|
||||
uint32_t stack_size=OS_STACK_SIZE,
|
||||
unsigned char *stack_mem=NULL) {
|
||||
osPriority priority = osPriorityNormal,
|
||||
uint32_t stack_size = OS_STACK_SIZE,
|
||||
unsigned char *stack_mem = NULL)
|
||||
{
|
||||
constructor(mbed::callback(task, argument),
|
||||
priority, stack_size, stack_mem);
|
||||
}
|
||||
|
|
@ -203,12 +207,13 @@ public:
|
|||
*/
|
||||
template <typename T>
|
||||
MBED_DEPRECATED_SINCE("mbed-os-5.1",
|
||||
"Thread-spawning constructors hide errors. "
|
||||
"Replaced by thread.start(callback(task, argument)).")
|
||||
"Thread-spawning constructors hide errors. "
|
||||
"Replaced by thread.start(callback(task, argument)).")
|
||||
Thread(T *argument, void (*task)(T *),
|
||||
osPriority priority=osPriorityNormal,
|
||||
uint32_t stack_size=OS_STACK_SIZE,
|
||||
unsigned char *stack_mem=NULL) {
|
||||
osPriority priority = osPriorityNormal,
|
||||
uint32_t stack_size = OS_STACK_SIZE,
|
||||
unsigned char *stack_mem = NULL)
|
||||
{
|
||||
constructor(mbed::callback(task, argument),
|
||||
priority, stack_size, stack_mem);
|
||||
}
|
||||
|
|
@ -235,12 +240,13 @@ public:
|
|||
@note You cannot call this function from ISR context.
|
||||
*/
|
||||
MBED_DEPRECATED_SINCE("mbed-os-5.1",
|
||||
"Thread-spawning constructors hide errors. "
|
||||
"Replaced by thread.start(callback(task, argument)).")
|
||||
Thread(void (*task)(void const *argument), void *argument=NULL,
|
||||
osPriority priority=osPriorityNormal,
|
||||
uint32_t stack_size=OS_STACK_SIZE,
|
||||
unsigned char *stack_mem=NULL) {
|
||||
"Thread-spawning constructors hide errors. "
|
||||
"Replaced by thread.start(callback(task, argument)).")
|
||||
Thread(void (*task)(void const *argument), void *argument = NULL,
|
||||
osPriority priority = osPriorityNormal,
|
||||
uint32_t stack_size = OS_STACK_SIZE,
|
||||
unsigned char *stack_mem = NULL)
|
||||
{
|
||||
constructor(mbed::callback((void (*)(void *))task, argument),
|
||||
priority, stack_size, stack_mem);
|
||||
}
|
||||
|
|
@ -265,9 +271,10 @@ public:
|
|||
*/
|
||||
template <typename T, typename M>
|
||||
MBED_DEPRECATED_SINCE("mbed-os-5.1",
|
||||
"The start function does not support cv-qualifiers. "
|
||||
"Replaced by thread.start(callback(obj, method)).")
|
||||
osStatus start(T *obj, M method) {
|
||||
"The start function does not support cv-qualifiers. "
|
||||
"Replaced by thread.start(callback(obj, method)).")
|
||||
osStatus start(T *obj, M method)
|
||||
{
|
||||
return start(mbed::callback(obj, method));
|
||||
}
|
||||
|
||||
|
|
@ -338,28 +345,28 @@ public:
|
|||
@note You cannot call this function from ISR context.
|
||||
*/
|
||||
State get_state();
|
||||
|
||||
|
||||
/** Get the total stack memory size for this Thread
|
||||
@return the total stack memory size in bytes
|
||||
|
||||
@note You cannot call this function from ISR context.
|
||||
*/
|
||||
uint32_t stack_size();
|
||||
|
||||
|
||||
/** Get the currently unused stack memory for this Thread
|
||||
@return the currently unused stack memory in bytes
|
||||
|
||||
@note You cannot call this function from ISR context.
|
||||
*/
|
||||
uint32_t free_stack();
|
||||
|
||||
|
||||
/** Get the currently used stack memory for this Thread
|
||||
@return the currently used stack memory in bytes
|
||||
|
||||
@note You cannot call this function from ISR context.
|
||||
*/
|
||||
uint32_t used_stack();
|
||||
|
||||
|
||||
/** Get the maximum stack memory usage to date for this Thread
|
||||
@return the maximum stack memory usage to date in bytes
|
||||
|
||||
|
|
@ -389,7 +396,7 @@ public:
|
|||
|
||||
@note You cannot call this function from ISR context.
|
||||
*/
|
||||
static osEvent signal_wait(int32_t signals, uint32_t millisec=osWaitForever);
|
||||
static osEvent signal_wait(int32_t signals, uint32_t millisec = osWaitForever);
|
||||
|
||||
/** Wait for a specified time period in milliseconds
|
||||
Being tick-based, the delay will be up to the specified time - eg for
|
||||
|
|
@ -455,21 +462,21 @@ public:
|
|||
private:
|
||||
// Required to share definitions without
|
||||
// delegated constructors
|
||||
void constructor(osPriority priority=osPriorityNormal,
|
||||
uint32_t stack_size=OS_STACK_SIZE,
|
||||
unsigned char *stack_mem=NULL,
|
||||
const char *name=NULL);
|
||||
void constructor(osPriority priority = osPriorityNormal,
|
||||
uint32_t stack_size = OS_STACK_SIZE,
|
||||
unsigned char *stack_mem = NULL,
|
||||
const char *name = NULL);
|
||||
void constructor(mbed::Callback<void()> task,
|
||||
osPriority priority=osPriorityNormal,
|
||||
uint32_t stack_size=OS_STACK_SIZE,
|
||||
unsigned char *stack_mem=NULL,
|
||||
const char *name=NULL);
|
||||
osPriority priority = osPriorityNormal,
|
||||
uint32_t stack_size = OS_STACK_SIZE,
|
||||
unsigned char *stack_mem = NULL,
|
||||
const char *name = NULL);
|
||||
void constructor(uint32_t tz_module,
|
||||
osPriority priority=osPriorityNormal,
|
||||
uint32_t stack_size=OS_STACK_SIZE,
|
||||
unsigned char *stack_mem=NULL,
|
||||
const char *name=NULL);
|
||||
static void _thunk(void * thread_ptr);
|
||||
osPriority priority = osPriorityNormal,
|
||||
uint32_t stack_size = OS_STACK_SIZE,
|
||||
unsigned char *stack_mem = NULL,
|
||||
const char *name = NULL);
|
||||
static void _thunk(void *thread_ptr);
|
||||
|
||||
mbed::Callback<void()> _task;
|
||||
osThreadId_t _tid;
|
||||
|
|
|
|||
Loading…
Reference in New Issue