mirror of https://github.com/ARMmbed/mbed-os.git
rtos: NULL -> nullptr
Some build errors seen with NULL not being defined. Rather than add cstddef includes, switch to C++11 nullptr.pull/10104/head
parent
7442da30f9
commit
ed4bf5220e
|
@ -30,12 +30,12 @@
|
||||||
|
|
||||||
namespace rtos {
|
namespace rtos {
|
||||||
|
|
||||||
ConditionVariable::Waiter::Waiter(): sem(0), prev(NULL), next(NULL), in_list(false)
|
ConditionVariable::Waiter::Waiter(): sem(0), prev(nullptr), next(nullptr), in_list(false)
|
||||||
{
|
{
|
||||||
// No initialization to do
|
// No initialization to do
|
||||||
}
|
}
|
||||||
|
|
||||||
ConditionVariable::ConditionVariable(Mutex &mutex): _mutex(mutex), _wait_list(NULL)
|
ConditionVariable::ConditionVariable(Mutex &mutex): _mutex(mutex), _wait_list(nullptr)
|
||||||
{
|
{
|
||||||
// No initialization to do
|
// No initialization to do
|
||||||
}
|
}
|
||||||
|
@ -86,7 +86,7 @@ bool ConditionVariable::wait_until(uint64_t millisec)
|
||||||
void ConditionVariable::notify_one()
|
void ConditionVariable::notify_one()
|
||||||
{
|
{
|
||||||
MBED_ASSERT(_mutex.get_owner() == ThisThread::get_id());
|
MBED_ASSERT(_mutex.get_owner() == ThisThread::get_id());
|
||||||
if (_wait_list != NULL) {
|
if (_wait_list != nullptr) {
|
||||||
_wait_list->sem.release();
|
_wait_list->sem.release();
|
||||||
_remove_wait_list(&_wait_list, _wait_list);
|
_remove_wait_list(&_wait_list, _wait_list);
|
||||||
}
|
}
|
||||||
|
@ -95,7 +95,7 @@ void ConditionVariable::notify_one()
|
||||||
void ConditionVariable::notify_all()
|
void ConditionVariable::notify_all()
|
||||||
{
|
{
|
||||||
MBED_ASSERT(_mutex.get_owner() == ThisThread::get_id());
|
MBED_ASSERT(_mutex.get_owner() == ThisThread::get_id());
|
||||||
while (_wait_list != NULL) {
|
while (_wait_list != nullptr) {
|
||||||
_wait_list->sem.release();
|
_wait_list->sem.release();
|
||||||
_remove_wait_list(&_wait_list, _wait_list);
|
_remove_wait_list(&_wait_list, _wait_list);
|
||||||
}
|
}
|
||||||
|
@ -103,7 +103,7 @@ void ConditionVariable::notify_all()
|
||||||
|
|
||||||
void ConditionVariable::_add_wait_list(Waiter **wait_list, Waiter *waiter)
|
void ConditionVariable::_add_wait_list(Waiter **wait_list, Waiter *waiter)
|
||||||
{
|
{
|
||||||
if (NULL == *wait_list) {
|
if (nullptr == *wait_list) {
|
||||||
// Nothing in the list so add it directly.
|
// Nothing in the list so add it directly.
|
||||||
// Update prev and next pointer to reference self
|
// Update prev and next pointer to reference self
|
||||||
*wait_list = waiter;
|
*wait_list = waiter;
|
||||||
|
@ -137,18 +137,18 @@ void ConditionVariable::_remove_wait_list(Waiter **wait_list, Waiter *waiter)
|
||||||
|
|
||||||
if (*wait_list == waiter) {
|
if (*wait_list == waiter) {
|
||||||
// This was the last element in the list
|
// This was the last element in the list
|
||||||
*wait_list = NULL;
|
*wait_list = nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Invalidate pointers
|
// Invalidate pointers
|
||||||
waiter->next = NULL;
|
waiter->next = nullptr;
|
||||||
waiter->prev = NULL;
|
waiter->prev = nullptr;
|
||||||
waiter->in_list = false;
|
waiter->in_list = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
ConditionVariable::~ConditionVariable()
|
ConditionVariable::~ConditionVariable()
|
||||||
{
|
{
|
||||||
MBED_ASSERT(NULL == _wait_list);
|
MBED_ASSERT(nullptr == _wait_list);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -112,7 +112,7 @@ public:
|
||||||
~EventFlags();
|
~EventFlags();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
void constructor(const char *name = NULL);
|
void constructor(const char *name = nullptr);
|
||||||
uint32_t wait(uint32_t flags, uint32_t opt, uint32_t millisec, bool clear);
|
uint32_t wait(uint32_t flags, uint32_t opt, uint32_t millisec, bool clear);
|
||||||
#if MBED_CONF_RTOS_PRESENT
|
#if MBED_CONF_RTOS_PRESENT
|
||||||
osEventFlagsId_t _id;
|
osEventFlagsId_t _id;
|
||||||
|
|
12
rtos/Mail.h
12
rtos/Mail.h
|
@ -97,7 +97,7 @@ public:
|
||||||
*
|
*
|
||||||
* @param millisec Not used (see note).
|
* @param millisec Not used (see note).
|
||||||
*
|
*
|
||||||
* @return Pointer to memory block that you can fill with mail or NULL in case error.
|
* @return Pointer to memory block that you can fill with mail or nullptr in case error.
|
||||||
*
|
*
|
||||||
* @note You may call this function from ISR context.
|
* @note You may call this function from ISR context.
|
||||||
* @note If blocking is required, use Mail::alloc_for or Mail::alloc_until
|
* @note If blocking is required, use Mail::alloc_for or Mail::alloc_until
|
||||||
|
@ -111,7 +111,7 @@ public:
|
||||||
*
|
*
|
||||||
* @param millisec Timeout value, or osWaitForever.
|
* @param millisec Timeout value, or osWaitForever.
|
||||||
*
|
*
|
||||||
* @return Pointer to memory block that you can fill with mail or NULL in case error.
|
* @return Pointer to memory block that you can fill with mail or nullptr in case error.
|
||||||
*
|
*
|
||||||
* @note You may call this function from ISR context if the millisec parameter is set to 0.
|
* @note You may call this function from ISR context if the millisec parameter is set to 0.
|
||||||
*/
|
*/
|
||||||
|
@ -124,7 +124,7 @@ public:
|
||||||
*
|
*
|
||||||
* @param millisec Absolute timeout time, referenced to Kernel::get_ms_count().
|
* @param millisec Absolute timeout time, referenced to Kernel::get_ms_count().
|
||||||
*
|
*
|
||||||
* @return Pointer to memory block that you can fill with mail or NULL in case error.
|
* @return Pointer to memory block that you can fill with mail or nullptr in case error.
|
||||||
*
|
*
|
||||||
* @note You cannot call this function from ISR context.
|
* @note You cannot call this function from ISR context.
|
||||||
* @note the underlying RTOS may have a limit to the maximum wait time
|
* @note the underlying RTOS may have a limit to the maximum wait time
|
||||||
|
@ -141,7 +141,7 @@ public:
|
||||||
*
|
*
|
||||||
* @param millisec Not used (see note).
|
* @param millisec Not used (see note).
|
||||||
*
|
*
|
||||||
* @return Pointer to memory block that you can fill with mail or NULL in case error.
|
* @return Pointer to memory block that you can fill with mail or nullptr in case error.
|
||||||
*
|
*
|
||||||
* @note You may call this function from ISR context if the millisec parameter is set to 0.
|
* @note You may call this function from ISR context if the millisec parameter is set to 0.
|
||||||
* @note If blocking is required, use Mail::calloc_for or Mail::calloc_until
|
* @note If blocking is required, use Mail::calloc_for or Mail::calloc_until
|
||||||
|
@ -155,7 +155,7 @@ public:
|
||||||
*
|
*
|
||||||
* @param millisec Timeout value, or osWaitForever.
|
* @param millisec Timeout value, or osWaitForever.
|
||||||
*
|
*
|
||||||
* @return Pointer to memory block that you can fill with mail or NULL in case error.
|
* @return Pointer to memory block that you can fill with mail or nullptr in case error.
|
||||||
*
|
*
|
||||||
* @note You may call this function from ISR context if the millisec parameter is set to 0.
|
* @note You may call this function from ISR context if the millisec parameter is set to 0.
|
||||||
*/
|
*/
|
||||||
|
@ -168,7 +168,7 @@ public:
|
||||||
*
|
*
|
||||||
* @param millisec Absolute timeout time, referenced to Kernel::get_ms_count().
|
* @param millisec Absolute timeout time, referenced to Kernel::get_ms_count().
|
||||||
*
|
*
|
||||||
* @return Pointer to memory block that you can fill with mail or NULL in case error.
|
* @return Pointer to memory block that you can fill with mail or nullptr in case error.
|
||||||
*
|
*
|
||||||
* @note You cannot call this function from ISR context.
|
* @note You cannot call this function from ISR context.
|
||||||
* @note the underlying RTOS may have a limit to the maximum wait time
|
* @note the underlying RTOS may have a limit to the maximum wait time
|
||||||
|
|
|
@ -77,7 +77,7 @@ public:
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Allocate a memory block from a memory pool, without blocking.
|
/** Allocate a memory block from a memory pool, without blocking.
|
||||||
@return address of the allocated memory block or NULL in case of no memory available.
|
@return address of the allocated memory block or nullptr in case of no memory available.
|
||||||
|
|
||||||
@note You may call this function from ISR context.
|
@note You may call this function from ISR context.
|
||||||
*/
|
*/
|
||||||
|
@ -88,7 +88,7 @@ public:
|
||||||
|
|
||||||
/** Allocate a memory block from a memory pool, optionally blocking.
|
/** Allocate a memory block from a memory pool, optionally blocking.
|
||||||
@param millisec timeout value (osWaitForever to wait forever)
|
@param millisec timeout value (osWaitForever to wait forever)
|
||||||
@return address of the allocated memory block or NULL in case of no memory available.
|
@return address of the allocated memory block or nullptr in case of no memory available.
|
||||||
|
|
||||||
@note You may call this function from ISR context if the millisec parameter is set to 0.
|
@note You may call this function from ISR context if the millisec parameter is set to 0.
|
||||||
*/
|
*/
|
||||||
|
@ -99,7 +99,7 @@ public:
|
||||||
|
|
||||||
/** Allocate a memory block from a memory pool, blocking.
|
/** Allocate a memory block from a memory pool, blocking.
|
||||||
@param millisec absolute timeout time, referenced to Kernel::get_ms_count().
|
@param millisec absolute timeout time, referenced to Kernel::get_ms_count().
|
||||||
@return address of the allocated memory block or NULL in case of no memory available.
|
@return address of the allocated memory block or nullptr in case of no memory available.
|
||||||
|
|
||||||
@note You cannot call this function from ISR context.
|
@note You cannot call this function from ISR context.
|
||||||
@note the underlying RTOS may have a limit to the maximum wait time
|
@note the underlying RTOS may have a limit to the maximum wait time
|
||||||
|
@ -122,14 +122,14 @@ public:
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Allocate a memory block from a memory pool, without blocking, and set memory block to zero.
|
/** Allocate a memory block from a memory pool, without blocking, and set memory block to zero.
|
||||||
@return address of the allocated memory block or NULL in case of no memory available.
|
@return address of the allocated memory block or nullptr in case of no memory available.
|
||||||
|
|
||||||
@note You may call this function from ISR context.
|
@note You may call this function from ISR context.
|
||||||
*/
|
*/
|
||||||
T *calloc(void)
|
T *calloc(void)
|
||||||
{
|
{
|
||||||
T *item = alloc();
|
T *item = alloc();
|
||||||
if (item != NULL) {
|
if (item != nullptr) {
|
||||||
memset(item, 0, sizeof(T));
|
memset(item, 0, sizeof(T));
|
||||||
}
|
}
|
||||||
return item;
|
return item;
|
||||||
|
@ -137,14 +137,14 @@ public:
|
||||||
|
|
||||||
/** Allocate a memory block from a memory pool, optionally blocking, and set memory block to zero.
|
/** Allocate a memory block from a memory pool, optionally blocking, and set memory block to zero.
|
||||||
@param millisec timeout value (osWaitForever to wait forever)
|
@param millisec timeout value (osWaitForever to wait forever)
|
||||||
@return address of the allocated memory block or NULL in case of no memory available.
|
@return address of the allocated memory block or nullptr in case of no memory available.
|
||||||
|
|
||||||
@note You may call this function from ISR context if the millisec parameter is set to 0.
|
@note You may call this function from ISR context if the millisec parameter is set to 0.
|
||||||
*/
|
*/
|
||||||
T *calloc_for(uint32_t millisec)
|
T *calloc_for(uint32_t millisec)
|
||||||
{
|
{
|
||||||
T *item = alloc_for(millisec);
|
T *item = alloc_for(millisec);
|
||||||
if (item != NULL) {
|
if (item != nullptr) {
|
||||||
memset(item, 0, sizeof(T));
|
memset(item, 0, sizeof(T));
|
||||||
}
|
}
|
||||||
return item;
|
return item;
|
||||||
|
@ -152,7 +152,7 @@ public:
|
||||||
|
|
||||||
/** Allocate a memory block from a memory pool, blocking, and set memory block to zero.
|
/** Allocate a memory block from a memory pool, blocking, and set memory block to zero.
|
||||||
@param millisec absolute timeout time, referenced to Kernel::get_ms_count().
|
@param millisec absolute timeout time, referenced to Kernel::get_ms_count().
|
||||||
@return address of the allocated memory block or NULL in case of no memory available.
|
@return address of the allocated memory block or nullptr in case of no memory available.
|
||||||
|
|
||||||
@note You cannot call this function from ISR context.
|
@note You cannot call this function from ISR context.
|
||||||
@note the underlying RTOS may have a limit to the maximum wait time
|
@note the underlying RTOS may have a limit to the maximum wait time
|
||||||
|
@ -163,7 +163,7 @@ public:
|
||||||
T *calloc_until(uint64_t millisec)
|
T *calloc_until(uint64_t millisec)
|
||||||
{
|
{
|
||||||
T *item = alloc_until(millisec);
|
T *item = alloc_until(millisec);
|
||||||
if (item != NULL) {
|
if (item != nullptr) {
|
||||||
memset(item, 0, sizeof(T));
|
memset(item, 0, sizeof(T));
|
||||||
}
|
}
|
||||||
return item;
|
return item;
|
||||||
|
@ -172,7 +172,7 @@ public:
|
||||||
/** Free a memory block.
|
/** Free a memory block.
|
||||||
@param block address of the allocated memory block to be freed.
|
@param block address of the allocated memory block to be freed.
|
||||||
@return osOK on successful deallocation, osErrorParameter if given memory block id
|
@return osOK on successful deallocation, osErrorParameter if given memory block id
|
||||||
is NULL or invalid, or osErrorResource if given memory block is in an
|
is nullptr or invalid, or osErrorResource if given memory block is in an
|
||||||
invalid memory pool state.
|
invalid memory pool state.
|
||||||
|
|
||||||
@note You may call this function from ISR context.
|
@note You may call this function from ISR context.
|
||||||
|
|
|
@ -177,7 +177,7 @@ public:
|
||||||
|
|
||||||
private:
|
private:
|
||||||
#if MBED_CONF_RTOS_PRESENT
|
#if MBED_CONF_RTOS_PRESENT
|
||||||
void constructor(const char *name = NULL);
|
void constructor(const char *name = nullptr);
|
||||||
friend class ConditionVariable;
|
friend class ConditionVariable;
|
||||||
|
|
||||||
osMutexId_t _id;
|
osMutexId_t _id;
|
||||||
|
|
|
@ -187,8 +187,8 @@ public:
|
||||||
osEvent get(uint32_t millisec = osWaitForever)
|
osEvent get(uint32_t millisec = osWaitForever)
|
||||||
{
|
{
|
||||||
osEvent event;
|
osEvent event;
|
||||||
T *data = NULL;
|
T *data = nullptr;
|
||||||
osStatus_t res = osMessageQueueGet(_id, &data, NULL, millisec);
|
osStatus_t res = osMessageQueueGet(_id, &data, nullptr, millisec);
|
||||||
|
|
||||||
switch (res) {
|
switch (res) {
|
||||||
case osOK:
|
case osOK:
|
||||||
|
|
|
@ -91,7 +91,7 @@ public:
|
||||||
/** Create timer.
|
/** Create timer.
|
||||||
@param func function to be executed by this timer.
|
@param func function to be executed by this timer.
|
||||||
@param type osTimerOnce for one-shot or osTimerPeriodic for periodic behavior. (default: osTimerPeriodic)
|
@param type osTimerOnce for one-shot or osTimerPeriodic for periodic behavior. (default: osTimerPeriodic)
|
||||||
@param argument argument to the timer call back function. (default: NULL)
|
@param argument argument to the timer call back function. (default: nullptr)
|
||||||
@deprecated Replaced with RtosTimer(Callback<void()>, os_timer_type)
|
@deprecated Replaced with RtosTimer(Callback<void()>, os_timer_type)
|
||||||
@deprecated
|
@deprecated
|
||||||
The RtosTimer has been superseded by the EventQueue. See RtosTimer.h for more details
|
The RtosTimer has been superseded by the EventQueue. See RtosTimer.h for more details
|
||||||
|
@ -102,7 +102,7 @@ public:
|
||||||
"Replaced with RtosTimer(Callback<void()>, os_timer_type)")
|
"Replaced with RtosTimer(Callback<void()>, os_timer_type)")
|
||||||
MBED_DEPRECATED_SINCE("mbed-os-5.2",
|
MBED_DEPRECATED_SINCE("mbed-os-5.2",
|
||||||
"The RtosTimer has been superseded by the EventQueue. See RtosTimer.h for more details")
|
"The RtosTimer has been superseded by the EventQueue. See RtosTimer.h for more details")
|
||||||
RtosTimer(void (*func)(void const *argument), os_timer_type type = osTimerPeriodic, void *argument = NULL)
|
RtosTimer(void (*func)(void const *argument), os_timer_type type = osTimerPeriodic, void *argument = nullptr)
|
||||||
{
|
{
|
||||||
constructor(mbed::callback((void (*)(void *))func, argument), type);
|
constructor(mbed::callback((void (*)(void *))func, argument), type);
|
||||||
}
|
}
|
||||||
|
|
|
@ -47,7 +47,7 @@ void Semaphore::constructor(int32_t count, uint16_t max_count)
|
||||||
attr.cb_mem = &_obj_mem;
|
attr.cb_mem = &_obj_mem;
|
||||||
attr.cb_size = sizeof(_obj_mem);
|
attr.cb_size = sizeof(_obj_mem);
|
||||||
_id = osSemaphoreNew(max_count, count, &attr);
|
_id = osSemaphoreNew(max_count, count, &attr);
|
||||||
MBED_ASSERT(_id != NULL);
|
MBED_ASSERT(_id != nullptr);
|
||||||
#else
|
#else
|
||||||
_count = count;
|
_count = count;
|
||||||
_max_count = max_count;
|
_max_count = max_count;
|
||||||
|
|
|
@ -159,8 +159,8 @@ extern "C" {
|
||||||
|
|
||||||
void rtos_attach_idle_hook(void (*fptr)(void))
|
void rtos_attach_idle_hook(void (*fptr)(void))
|
||||||
{
|
{
|
||||||
//Attach the specified idle hook, or the default idle hook in case of a NULL pointer
|
//Attach the specified idle hook, or the default idle hook in case of a null pointer
|
||||||
if (fptr != NULL) {
|
if (fptr != nullptr) {
|
||||||
idle_hook_fptr = fptr;
|
idle_hook_fptr = fptr;
|
||||||
} else {
|
} else {
|
||||||
idle_hook_fptr = default_idle_hook;
|
idle_hook_fptr = default_idle_hook;
|
||||||
|
|
|
@ -242,12 +242,12 @@ const char *get_name()
|
||||||
{
|
{
|
||||||
#if MBED_CONF_RTOS_PRESENT
|
#if MBED_CONF_RTOS_PRESENT
|
||||||
osThreadId_t id = osThreadGetId();
|
osThreadId_t id = osThreadGetId();
|
||||||
if (id == NULL) {
|
if (id == nullptr) {
|
||||||
return NULL;
|
return nullptr;
|
||||||
}
|
}
|
||||||
return osThreadGetName(id);
|
return osThreadGetName(id);
|
||||||
#else
|
#else
|
||||||
return NULL;
|
return nullptr;
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -169,13 +169,13 @@ void sleep_until(uint64_t millisec);
|
||||||
void yield();
|
void yield();
|
||||||
|
|
||||||
/** Get the thread id of the current running thread.
|
/** Get the thread id of the current running thread.
|
||||||
@return thread ID for reference by other functions or NULL in case of error or in ISR context.
|
@return thread ID for reference by other functions or nullptr in case of error or in ISR context.
|
||||||
@note You may call this function from ISR context.
|
@note You may call this function from ISR context.
|
||||||
*/
|
*/
|
||||||
osThreadId_t get_id();
|
osThreadId_t get_id();
|
||||||
|
|
||||||
/** Get the thread name of the current running thread.
|
/** Get the thread name of the current running thread.
|
||||||
@return thread name pointer or NULL if thread has no name or in case of error.
|
@return thread name pointer or nullptr if thread has no name or in case of error.
|
||||||
@note You cannot call this function from ISR context.
|
@note You cannot call this function from ISR context.
|
||||||
*/
|
*/
|
||||||
const char *get_name();
|
const char *get_name();
|
||||||
|
|
|
@ -52,7 +52,7 @@ void Thread::constructor(uint32_t tz_module, osPriority priority,
|
||||||
const uint32_t aligned_size = ALIGN_DOWN(stack_size - offset, 8);
|
const uint32_t aligned_size = ALIGN_DOWN(stack_size - offset, 8);
|
||||||
|
|
||||||
_tid = 0;
|
_tid = 0;
|
||||||
_dynamic_stack = (stack_mem == NULL);
|
_dynamic_stack = (stack_mem == nullptr);
|
||||||
_finished = false;
|
_finished = false;
|
||||||
memset(&_attr, 0, sizeof(_attr));
|
memset(&_attr, 0, sizeof(_attr));
|
||||||
_attr.priority = priority;
|
_attr.priority = priority;
|
||||||
|
@ -96,9 +96,9 @@ osStatus Thread::start(mbed::Callback<void()> task)
|
||||||
return osErrorParameter;
|
return osErrorParameter;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (_attr.stack_mem == NULL) {
|
if (_attr.stack_mem == nullptr) {
|
||||||
_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);
|
MBED_ASSERT(_attr.stack_mem != nullptr);
|
||||||
}
|
}
|
||||||
|
|
||||||
//Fill the stack with a magic word for maximum usage checking
|
//Fill the stack with a magic word for maximum usage checking
|
||||||
|
@ -111,10 +111,10 @@ osStatus Thread::start(mbed::Callback<void()> task)
|
||||||
_attr.cb_mem = &_obj_mem;
|
_attr.cb_mem = &_obj_mem;
|
||||||
_task = task;
|
_task = task;
|
||||||
_tid = osThreadNew(Thread::_thunk, this, &_attr);
|
_tid = osThreadNew(Thread::_thunk, this, &_attr);
|
||||||
if (_tid == NULL) {
|
if (_tid == nullptr) {
|
||||||
if (_dynamic_stack) {
|
if (_dynamic_stack) {
|
||||||
delete[](uint32_t *)(_attr.stack_mem);
|
delete[] _attr.stack_mem;
|
||||||
_attr.stack_mem = (uint32_t *)NULL;
|
_attr.stack_mem = nullptr;
|
||||||
}
|
}
|
||||||
_mutex.unlock();
|
_mutex.unlock();
|
||||||
_join_sem.release();
|
_join_sem.release();
|
||||||
|
@ -130,12 +130,12 @@ osStatus Thread::terminate()
|
||||||
osStatus_t ret = osOK;
|
osStatus_t ret = osOK;
|
||||||
_mutex.lock();
|
_mutex.lock();
|
||||||
|
|
||||||
// Set the Thread's tid to NULL and
|
// Set the Thread's tid to nullptr and
|
||||||
// release the semaphore before terminating
|
// release the semaphore before terminating
|
||||||
// since this thread could be terminating itself
|
// since this thread could be terminating itself
|
||||||
osThreadId_t local_id = _tid;
|
osThreadId_t local_id = _tid;
|
||||||
_join_sem.release();
|
_join_sem.release();
|
||||||
_tid = (osThreadId_t)NULL;
|
_tid = nullptr;
|
||||||
if (!_finished) {
|
if (!_finished) {
|
||||||
_finished = true;
|
_finished = true;
|
||||||
// if local_id == 0 Thread was not started in first place
|
// if local_id == 0 Thread was not started in first place
|
||||||
|
@ -156,7 +156,7 @@ osStatus Thread::join()
|
||||||
// terminated or has been terminated. Once the mutex has
|
// terminated or has been terminated. Once the mutex has
|
||||||
// been locked it is ensured that the thread is deleted.
|
// been locked it is ensured that the thread is deleted.
|
||||||
_mutex.lock();
|
_mutex.lock();
|
||||||
MBED_ASSERT(NULL == _tid);
|
MBED_ASSERT(nullptr == _tid);
|
||||||
_mutex.unlock();
|
_mutex.unlock();
|
||||||
|
|
||||||
// Release sem so any other threads joining this thread wake up
|
// Release sem so any other threads joining this thread wake up
|
||||||
|
@ -204,7 +204,7 @@ Thread::State Thread::get_state() const
|
||||||
|
|
||||||
_mutex.lock();
|
_mutex.lock();
|
||||||
|
|
||||||
if (_tid != NULL) {
|
if (_tid != nullptr) {
|
||||||
#if defined(MBED_OS_BACKEND_RTX5)
|
#if defined(MBED_OS_BACKEND_RTX5)
|
||||||
state = _obj_mem.state;
|
state = _obj_mem.state;
|
||||||
#else
|
#else
|
||||||
|
@ -269,7 +269,7 @@ uint32_t Thread::stack_size() const
|
||||||
uint32_t size = 0;
|
uint32_t size = 0;
|
||||||
_mutex.lock();
|
_mutex.lock();
|
||||||
|
|
||||||
if (_tid != NULL) {
|
if (_tid != nullptr) {
|
||||||
size = osThreadGetStackSize(_tid);
|
size = osThreadGetStackSize(_tid);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -283,7 +283,7 @@ uint32_t Thread::free_stack() const
|
||||||
_mutex.lock();
|
_mutex.lock();
|
||||||
|
|
||||||
#if defined(MBED_OS_BACKEND_RTX5)
|
#if defined(MBED_OS_BACKEND_RTX5)
|
||||||
if (_tid != NULL) {
|
if (_tid != nullptr) {
|
||||||
mbed_rtos_storage_thread_t *thread = (mbed_rtos_storage_thread_t *)_tid;
|
mbed_rtos_storage_thread_t *thread = (mbed_rtos_storage_thread_t *)_tid;
|
||||||
size = (uint32_t)thread->sp - (uint32_t)thread->stack_mem;
|
size = (uint32_t)thread->sp - (uint32_t)thread->stack_mem;
|
||||||
}
|
}
|
||||||
|
@ -299,7 +299,7 @@ uint32_t Thread::used_stack() const
|
||||||
_mutex.lock();
|
_mutex.lock();
|
||||||
|
|
||||||
#if defined(MBED_OS_BACKEND_RTX5)
|
#if defined(MBED_OS_BACKEND_RTX5)
|
||||||
if (_tid != NULL) {
|
if (_tid != nullptr) {
|
||||||
mbed_rtos_storage_thread_t *thread = (mbed_rtos_storage_thread_t *)_tid;
|
mbed_rtos_storage_thread_t *thread = (mbed_rtos_storage_thread_t *)_tid;
|
||||||
size = ((uint32_t)thread->stack_mem + thread->stack_size) - thread->sp;
|
size = ((uint32_t)thread->stack_mem + thread->stack_size) - thread->sp;
|
||||||
}
|
}
|
||||||
|
@ -314,7 +314,7 @@ uint32_t Thread::max_stack() const
|
||||||
uint32_t size = 0;
|
uint32_t size = 0;
|
||||||
_mutex.lock();
|
_mutex.lock();
|
||||||
|
|
||||||
if (_tid != NULL) {
|
if (_tid != nullptr) {
|
||||||
#if defined(MBED_OS_BACKEND_RTX5)
|
#if defined(MBED_OS_BACKEND_RTX5)
|
||||||
mbed_rtos_storage_thread_t *thread = (mbed_rtos_storage_thread_t *)_tid;
|
mbed_rtos_storage_thread_t *thread = (mbed_rtos_storage_thread_t *)_tid;
|
||||||
uint32_t high_mark = 0;
|
uint32_t high_mark = 0;
|
||||||
|
@ -417,8 +417,8 @@ Thread::~Thread()
|
||||||
// terminate is thread safe
|
// terminate is thread safe
|
||||||
terminate();
|
terminate();
|
||||||
if (_dynamic_stack) {
|
if (_dynamic_stack) {
|
||||||
delete[](uint32_t *)(_attr.stack_mem);
|
delete[] _attr.stack_mem;
|
||||||
_attr.stack_mem = (uint32_t *)NULL;
|
_attr.stack_mem = nullptr;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -427,7 +427,7 @@ void Thread::_thunk(void *thread_ptr)
|
||||||
Thread *t = (Thread *)thread_ptr;
|
Thread *t = (Thread *)thread_ptr;
|
||||||
t->_task();
|
t->_task();
|
||||||
t->_mutex.lock();
|
t->_mutex.lock();
|
||||||
t->_tid = (osThreadId)NULL;
|
t->_tid = nullptr;
|
||||||
t->_finished = true;
|
t->_finished = true;
|
||||||
t->_join_sem.release();
|
t->_join_sem.release();
|
||||||
// rtos will release the mutex automatically
|
// rtos will release the mutex automatically
|
||||||
|
|
|
@ -89,8 +89,8 @@ public:
|
||||||
/** Allocate a new thread without starting execution
|
/** Allocate a new thread without starting execution
|
||||||
@param priority initial priority of the thread function. (default: osPriorityNormal).
|
@param priority initial priority of the thread function. (default: osPriorityNormal).
|
||||||
@param stack_size stack size (in bytes) requirements for the thread function. (default: OS_STACK_SIZE).
|
@param stack_size stack size (in bytes) requirements for the thread function. (default: OS_STACK_SIZE).
|
||||||
@param stack_mem pointer to the stack area to be used by this thread (default: NULL).
|
@param stack_mem pointer to the stack area to be used by this thread (default: nullptr).
|
||||||
@param name name to be used for this thread. It has to stay allocated for the lifetime of the thread (default: NULL)
|
@param name name to be used for this thread. It has to stay allocated for the lifetime of the thread (default: nullptr)
|
||||||
|
|
||||||
@note Default value of tz_module will be MBED_TZ_DEFAULT_ACCESS
|
@note Default value of tz_module will be MBED_TZ_DEFAULT_ACCESS
|
||||||
@note You cannot call this function from ISR context.
|
@note You cannot call this function from ISR context.
|
||||||
|
@ -98,7 +98,7 @@ public:
|
||||||
|
|
||||||
Thread(osPriority priority = osPriorityNormal,
|
Thread(osPriority priority = osPriorityNormal,
|
||||||
uint32_t stack_size = OS_STACK_SIZE,
|
uint32_t stack_size = OS_STACK_SIZE,
|
||||||
unsigned char *stack_mem = NULL, const char *name = NULL)
|
unsigned char *stack_mem = nullptr, const char *name = nullptr)
|
||||||
{
|
{
|
||||||
constructor(priority, stack_size, stack_mem, name);
|
constructor(priority, stack_size, stack_mem, name);
|
||||||
}
|
}
|
||||||
|
@ -110,15 +110,15 @@ public:
|
||||||
threads not using secure calls at all. See "TrustZone RTOS Context Management" for more details.
|
threads not using secure calls at all. See "TrustZone RTOS Context Management" for more details.
|
||||||
@param priority initial priority of the thread function. (default: osPriorityNormal).
|
@param priority initial priority of the thread function. (default: osPriorityNormal).
|
||||||
@param stack_size stack size (in bytes) requirements for the thread function. (default: OS_STACK_SIZE).
|
@param stack_size stack size (in bytes) requirements for the thread function. (default: OS_STACK_SIZE).
|
||||||
@param stack_mem pointer to the stack area to be used by this thread (default: NULL).
|
@param stack_mem pointer to the stack area to be used by this thread (default: nullptr).
|
||||||
@param name name to be used for this thread. It has to stay allocated for the lifetime of the thread (default: NULL)
|
@param name name to be used for this thread. It has to stay allocated for the lifetime of the thread (default: nullptr)
|
||||||
|
|
||||||
@note You cannot call this function from ISR context.
|
@note You cannot call this function from ISR context.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
Thread(uint32_t tz_module, osPriority priority = osPriorityNormal,
|
Thread(uint32_t tz_module, osPriority priority = osPriorityNormal,
|
||||||
uint32_t stack_size = OS_STACK_SIZE,
|
uint32_t stack_size = OS_STACK_SIZE,
|
||||||
unsigned char *stack_mem = NULL, const char *name = NULL)
|
unsigned char *stack_mem = nullptr, const char *name = nullptr)
|
||||||
{
|
{
|
||||||
constructor(tz_module, priority, stack_size, stack_mem, name);
|
constructor(tz_module, priority, stack_size, stack_mem, name);
|
||||||
}
|
}
|
||||||
|
@ -128,7 +128,7 @@ public:
|
||||||
@param task function to be executed by this thread.
|
@param task function to be executed by this thread.
|
||||||
@param priority initial priority of the thread function. (default: osPriorityNormal).
|
@param priority initial priority of the thread function. (default: osPriorityNormal).
|
||||||
@param stack_size stack size (in bytes) requirements for the thread function. (default: OS_STACK_SIZE).
|
@param stack_size stack size (in bytes) requirements for the thread function. (default: OS_STACK_SIZE).
|
||||||
@param stack_mem pointer to the stack area to be used by this thread (default: NULL).
|
@param stack_mem pointer to the stack area to be used by this thread (default: nullptr).
|
||||||
@deprecated
|
@deprecated
|
||||||
Thread-spawning constructors hide errors. Replaced by thread.start(task).
|
Thread-spawning constructors hide errors. Replaced by thread.start(task).
|
||||||
|
|
||||||
|
@ -149,17 +149,17 @@ public:
|
||||||
Thread(mbed::Callback<void()> task,
|
Thread(mbed::Callback<void()> task,
|
||||||
osPriority priority = osPriorityNormal,
|
osPriority priority = osPriorityNormal,
|
||||||
uint32_t stack_size = OS_STACK_SIZE,
|
uint32_t stack_size = OS_STACK_SIZE,
|
||||||
unsigned char *stack_mem = NULL)
|
unsigned char *stack_mem = nullptr)
|
||||||
{
|
{
|
||||||
constructor(task, priority, stack_size, stack_mem);
|
constructor(task, priority, stack_size, stack_mem);
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Create a new thread, and start it executing the specified function.
|
/** Create a new thread, and start it executing the specified function.
|
||||||
@param argument pointer that is passed to the thread function as start argument. (default: NULL).
|
@param argument pointer that is passed to the thread function as start argument. (default: nullptr).
|
||||||
@param task argument to task.
|
@param task argument to task.
|
||||||
@param priority initial priority of the thread function. (default: osPriorityNormal).
|
@param priority initial priority of the thread function. (default: osPriorityNormal).
|
||||||
@param stack_size stack size (in bytes) requirements for the thread function. (default: OS_STACK_SIZE).
|
@param stack_size stack size (in bytes) requirements for the thread function. (default: OS_STACK_SIZE).
|
||||||
@param stack_mem pointer to the stack area to be used by this thread (default: NULL).
|
@param stack_mem pointer to the stack area to be used by this thread (default: nullptr).
|
||||||
@deprecated
|
@deprecated
|
||||||
Thread-spawning constructors hide errors. Replaced by thread.start(callback(task, argument)).
|
Thread-spawning constructors hide errors. Replaced by thread.start(callback(task, argument)).
|
||||||
|
|
||||||
|
@ -181,18 +181,18 @@ public:
|
||||||
Thread(T *argument, void (T::*task)(),
|
Thread(T *argument, void (T::*task)(),
|
||||||
osPriority priority = osPriorityNormal,
|
osPriority priority = osPriorityNormal,
|
||||||
uint32_t stack_size = OS_STACK_SIZE,
|
uint32_t stack_size = OS_STACK_SIZE,
|
||||||
unsigned char *stack_mem = NULL)
|
unsigned char *stack_mem = nullptr)
|
||||||
{
|
{
|
||||||
constructor(mbed::callback(task, argument),
|
constructor(mbed::callback(task, argument),
|
||||||
priority, stack_size, stack_mem);
|
priority, stack_size, stack_mem);
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Create a new thread, and start it executing the specified function.
|
/** Create a new thread, and start it executing the specified function.
|
||||||
@param argument pointer that is passed to the thread function as start argument. (default: NULL).
|
@param argument pointer that is passed to the thread function as start argument. (default: nullptr).
|
||||||
@param task argument to task.
|
@param task argument to task.
|
||||||
@param priority initial priority of the thread function. (default: osPriorityNormal).
|
@param priority initial priority of the thread function. (default: osPriorityNormal).
|
||||||
@param stack_size stack size (in bytes) requirements for the thread function. (default: OS_STACK_SIZE).
|
@param stack_size stack size (in bytes) requirements for the thread function. (default: OS_STACK_SIZE).
|
||||||
@param stack_mem pointer to the stack area to be used by this thread (default: NULL).
|
@param stack_mem pointer to the stack area to be used by this thread (default: nullptr).
|
||||||
@deprecated
|
@deprecated
|
||||||
Thread-spawning constructors hide errors. Replaced by thread.start(callback(task, argument)).
|
Thread-spawning constructors hide errors. Replaced by thread.start(callback(task, argument)).
|
||||||
|
|
||||||
|
@ -214,7 +214,7 @@ public:
|
||||||
Thread(T *argument, void (*task)(T *),
|
Thread(T *argument, void (*task)(T *),
|
||||||
osPriority priority = osPriorityNormal,
|
osPriority priority = osPriorityNormal,
|
||||||
uint32_t stack_size = OS_STACK_SIZE,
|
uint32_t stack_size = OS_STACK_SIZE,
|
||||||
unsigned char *stack_mem = NULL)
|
unsigned char *stack_mem = nullptr)
|
||||||
{
|
{
|
||||||
constructor(mbed::callback(task, argument),
|
constructor(mbed::callback(task, argument),
|
||||||
priority, stack_size, stack_mem);
|
priority, stack_size, stack_mem);
|
||||||
|
@ -223,10 +223,10 @@ public:
|
||||||
/** Create a new thread, and start it executing the specified function.
|
/** Create a new thread, and start it executing the specified function.
|
||||||
Provided for backwards compatibility
|
Provided for backwards compatibility
|
||||||
@param task function to be executed by this thread.
|
@param task function to be executed by this thread.
|
||||||
@param argument pointer that is passed to the thread function as start argument. (default: NULL).
|
@param argument pointer that is passed to the thread function as start argument. (default: nullptr).
|
||||||
@param priority initial priority of the thread function. (default: osPriorityNormal).
|
@param priority initial priority of the thread function. (default: osPriorityNormal).
|
||||||
@param stack_size stack size (in bytes) requirements for the thread function. (default: OS_STACK_SIZE).
|
@param stack_size stack size (in bytes) requirements for the thread function. (default: OS_STACK_SIZE).
|
||||||
@param stack_mem pointer to the stack area to be used by this thread (default: NULL).
|
@param stack_mem pointer to the stack area to be used by this thread (default: nullptr).
|
||||||
@deprecated
|
@deprecated
|
||||||
Thread-spawning constructors hide errors. Replaced by thread.start(callback(task, argument)).
|
Thread-spawning constructors hide errors. Replaced by thread.start(callback(task, argument)).
|
||||||
|
|
||||||
|
@ -244,10 +244,10 @@ public:
|
||||||
MBED_DEPRECATED_SINCE("mbed-os-5.1",
|
MBED_DEPRECATED_SINCE("mbed-os-5.1",
|
||||||
"Thread-spawning constructors hide errors. "
|
"Thread-spawning constructors hide errors. "
|
||||||
"Replaced by thread.start(callback(task, argument)).")
|
"Replaced by thread.start(callback(task, argument)).")
|
||||||
Thread(void (*task)(void const *argument), void *argument = NULL,
|
Thread(void (*task)(void const *argument), void *argument = nullptr,
|
||||||
osPriority priority = osPriorityNormal,
|
osPriority priority = osPriorityNormal,
|
||||||
uint32_t stack_size = OS_STACK_SIZE,
|
uint32_t stack_size = OS_STACK_SIZE,
|
||||||
unsigned char *stack_mem = NULL)
|
unsigned char *stack_mem = nullptr)
|
||||||
{
|
{
|
||||||
constructor(mbed::callback((void (*)(void *))task, argument),
|
constructor(mbed::callback((void (*)(void *))task, argument),
|
||||||
priority, stack_size, stack_mem);
|
priority, stack_size, stack_mem);
|
||||||
|
@ -389,7 +389,7 @@ public:
|
||||||
uint32_t max_stack() const;
|
uint32_t max_stack() const;
|
||||||
|
|
||||||
/** Get thread name
|
/** Get thread name
|
||||||
@return thread name or NULL if the name was not set.
|
@return thread name or nullptr if the name was not set.
|
||||||
|
|
||||||
@note You may call this function from ISR context.
|
@note You may call this function from ISR context.
|
||||||
*/
|
*/
|
||||||
|
@ -475,7 +475,7 @@ public:
|
||||||
static osStatus yield();
|
static osStatus yield();
|
||||||
|
|
||||||
/** Get the thread id of the current running thread.
|
/** Get the thread id of the current running thread.
|
||||||
@return thread ID for reference by other functions or NULL in case of error.
|
@return thread ID for reference by other functions or nullptr in case of error.
|
||||||
|
|
||||||
@note You may call this function from ISR context.
|
@note You may call this function from ISR context.
|
||||||
@deprecated Static methods only affecting current thread cause confusion. Replaced by ThisThread::get_id.
|
@deprecated Static methods only affecting current thread cause confusion. Replaced by ThisThread::get_id.
|
||||||
|
@ -519,18 +519,18 @@ private:
|
||||||
// delegated constructors
|
// delegated constructors
|
||||||
void constructor(osPriority priority = osPriorityNormal,
|
void constructor(osPriority priority = osPriorityNormal,
|
||||||
uint32_t stack_size = OS_STACK_SIZE,
|
uint32_t stack_size = OS_STACK_SIZE,
|
||||||
unsigned char *stack_mem = NULL,
|
unsigned char *stack_mem = nullptr,
|
||||||
const char *name = NULL);
|
const char *name = nullptr);
|
||||||
void constructor(mbed::Callback<void()> task,
|
void constructor(mbed::Callback<void()> task,
|
||||||
osPriority priority = osPriorityNormal,
|
osPriority priority = osPriorityNormal,
|
||||||
uint32_t stack_size = OS_STACK_SIZE,
|
uint32_t stack_size = OS_STACK_SIZE,
|
||||||
unsigned char *stack_mem = NULL,
|
unsigned char *stack_mem = nullptr,
|
||||||
const char *name = NULL);
|
const char *name = nullptr);
|
||||||
void constructor(uint32_t tz_module,
|
void constructor(uint32_t tz_module,
|
||||||
osPriority priority = osPriorityNormal,
|
osPriority priority = osPriorityNormal,
|
||||||
uint32_t stack_size = OS_STACK_SIZE,
|
uint32_t stack_size = OS_STACK_SIZE,
|
||||||
unsigned char *stack_mem = NULL,
|
unsigned char *stack_mem = nullptr,
|
||||||
const char *name = NULL);
|
const char *name = nullptr);
|
||||||
static void _thunk(void *thread_ptr);
|
static void _thunk(void *thread_ptr);
|
||||||
|
|
||||||
mbed::Callback<void()> _task;
|
mbed::Callback<void()> _task;
|
||||||
|
|
Loading…
Reference in New Issue