Skip to content

Commit ab49061

Browse files
committed
rtos: NULL -> nullptr
Some build errors seen with NULL not being defined. Rather than add cstddef includes, switch to C++11 nullptr.
1 parent d3de67f commit ab49061

13 files changed

+82
-82
lines changed

rtos/ConditionVariable.cpp

+9-9
Original file line numberDiff line numberDiff line change
@@ -30,12 +30,12 @@
3030

3131
namespace rtos {
3232

33-
ConditionVariable::Waiter::Waiter(): sem(0), prev(NULL), next(NULL), in_list(false)
33+
ConditionVariable::Waiter::Waiter(): sem(0), prev(nullptr), next(nullptr), in_list(false)
3434
{
3535
// No initialization to do
3636
}
3737

38-
ConditionVariable::ConditionVariable(Mutex &mutex): _mutex(mutex), _wait_list(NULL)
38+
ConditionVariable::ConditionVariable(Mutex &mutex): _mutex(mutex), _wait_list(nullptr)
3939
{
4040
// No initialization to do
4141
}
@@ -86,7 +86,7 @@ bool ConditionVariable::wait_until(uint64_t millisec)
8686
void ConditionVariable::notify_one()
8787
{
8888
MBED_ASSERT(_mutex.get_owner() == ThisThread::get_id());
89-
if (_wait_list != NULL) {
89+
if (_wait_list != nullptr) {
9090
_wait_list->sem.release();
9191
_remove_wait_list(&_wait_list, _wait_list);
9292
}
@@ -95,15 +95,15 @@ void ConditionVariable::notify_one()
9595
void ConditionVariable::notify_all()
9696
{
9797
MBED_ASSERT(_mutex.get_owner() == ThisThread::get_id());
98-
while (_wait_list != NULL) {
98+
while (_wait_list != nullptr) {
9999
_wait_list->sem.release();
100100
_remove_wait_list(&_wait_list, _wait_list);
101101
}
102102
}
103103

104104
void ConditionVariable::_add_wait_list(Waiter **wait_list, Waiter *waiter)
105105
{
106-
if (NULL == *wait_list) {
106+
if (nullptr == *wait_list) {
107107
// Nothing in the list so add it directly.
108108
// Update prev and next pointer to reference self
109109
*wait_list = waiter;
@@ -137,18 +137,18 @@ void ConditionVariable::_remove_wait_list(Waiter **wait_list, Waiter *waiter)
137137

138138
if (*wait_list == waiter) {
139139
// This was the last element in the list
140-
*wait_list = NULL;
140+
*wait_list = nullptr;
141141
}
142142

143143
// Invalidate pointers
144-
waiter->next = NULL;
145-
waiter->prev = NULL;
144+
waiter->next = nullptr;
145+
waiter->prev = nullptr;
146146
waiter->in_list = false;
147147
}
148148

149149
ConditionVariable::~ConditionVariable()
150150
{
151-
MBED_ASSERT(NULL == _wait_list);
151+
MBED_ASSERT(nullptr == _wait_list);
152152
}
153153

154154
}

rtos/EventFlags.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,7 @@ class EventFlags : private mbed::NonCopyable<EventFlags> {
112112
~EventFlags();
113113

114114
private:
115-
void constructor(const char *name = NULL);
115+
void constructor(const char *name = nullptr);
116116
uint32_t wait(uint32_t flags, uint32_t opt, uint32_t millisec, bool clear);
117117
#if MBED_CONF_RTOS_PRESENT
118118
osEventFlagsId_t _id;

rtos/Mail.h

+6-6
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ class Mail : private mbed::NonCopyable<Mail<T, queue_sz> > {
9797
*
9898
* @param millisec Not used (see note).
9999
*
100-
* @return Pointer to memory block that you can fill with mail or NULL in case error.
100+
* @return Pointer to memory block that you can fill with mail or nullptr in case error.
101101
*
102102
* @note You may call this function from ISR context.
103103
* @note If blocking is required, use Mail::alloc_for or Mail::alloc_until
@@ -111,7 +111,7 @@ class Mail : private mbed::NonCopyable<Mail<T, queue_sz> > {
111111
*
112112
* @param millisec Timeout value, or osWaitForever.
113113
*
114-
* @return Pointer to memory block that you can fill with mail or NULL in case error.
114+
* @return Pointer to memory block that you can fill with mail or nullptr in case error.
115115
*
116116
* @note You may call this function from ISR context if the millisec parameter is set to 0.
117117
*/
@@ -124,7 +124,7 @@ class Mail : private mbed::NonCopyable<Mail<T, queue_sz> > {
124124
*
125125
* @param millisec Absolute timeout time, referenced to Kernel::get_ms_count().
126126
*
127-
* @return Pointer to memory block that you can fill with mail or NULL in case error.
127+
* @return Pointer to memory block that you can fill with mail or nullptr in case error.
128128
*
129129
* @note You cannot call this function from ISR context.
130130
* @note the underlying RTOS may have a limit to the maximum wait time
@@ -141,7 +141,7 @@ class Mail : private mbed::NonCopyable<Mail<T, queue_sz> > {
141141
*
142142
* @param millisec Not used (see note).
143143
*
144-
* @return Pointer to memory block that you can fill with mail or NULL in case error.
144+
* @return Pointer to memory block that you can fill with mail or nullptr in case error.
145145
*
146146
* @note You may call this function from ISR context if the millisec parameter is set to 0.
147147
* @note If blocking is required, use Mail::calloc_for or Mail::calloc_until
@@ -155,7 +155,7 @@ class Mail : private mbed::NonCopyable<Mail<T, queue_sz> > {
155155
*
156156
* @param millisec Timeout value, or osWaitForever.
157157
*
158-
* @return Pointer to memory block that you can fill with mail or NULL in case error.
158+
* @return Pointer to memory block that you can fill with mail or nullptr in case error.
159159
*
160160
* @note You may call this function from ISR context if the millisec parameter is set to 0.
161161
*/
@@ -168,7 +168,7 @@ class Mail : private mbed::NonCopyable<Mail<T, queue_sz> > {
168168
*
169169
* @param millisec Absolute timeout time, referenced to Kernel::get_ms_count().
170170
*
171-
* @return Pointer to memory block that you can fill with mail or NULL in case error.
171+
* @return Pointer to memory block that you can fill with mail or nullptr in case error.
172172
*
173173
* @note You cannot call this function from ISR context.
174174
* @note the underlying RTOS may have a limit to the maximum wait time

rtos/MemoryPool.h

+10-10
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ class MemoryPool : private mbed::NonCopyable<MemoryPool<T, pool_sz> > {
7777
}
7878

7979
/** Allocate a memory block from a memory pool, without blocking.
80-
@return address of the allocated memory block or NULL in case of no memory available.
80+
@return address of the allocated memory block or nullptr in case of no memory available.
8181
8282
@note You may call this function from ISR context.
8383
*/
@@ -88,7 +88,7 @@ class MemoryPool : private mbed::NonCopyable<MemoryPool<T, pool_sz> > {
8888

8989
/** Allocate a memory block from a memory pool, optionally blocking.
9090
@param millisec timeout value (osWaitForever to wait forever)
91-
@return address of the allocated memory block or NULL in case of no memory available.
91+
@return address of the allocated memory block or nullptr in case of no memory available.
9292
9393
@note You may call this function from ISR context if the millisec parameter is set to 0.
9494
*/
@@ -99,7 +99,7 @@ class MemoryPool : private mbed::NonCopyable<MemoryPool<T, pool_sz> > {
9999

100100
/** Allocate a memory block from a memory pool, blocking.
101101
@param millisec absolute timeout time, referenced to Kernel::get_ms_count().
102-
@return address of the allocated memory block or NULL in case of no memory available.
102+
@return address of the allocated memory block or nullptr in case of no memory available.
103103
104104
@note You cannot call this function from ISR context.
105105
@note the underlying RTOS may have a limit to the maximum wait time
@@ -122,37 +122,37 @@ class MemoryPool : private mbed::NonCopyable<MemoryPool<T, pool_sz> > {
122122
}
123123

124124
/** Allocate a memory block from a memory pool, without blocking, and set memory block to zero.
125-
@return address of the allocated memory block or NULL in case of no memory available.
125+
@return address of the allocated memory block or nullptr in case of no memory available.
126126
127127
@note You may call this function from ISR context.
128128
*/
129129
T *calloc(void)
130130
{
131131
T *item = alloc();
132-
if (item != NULL) {
132+
if (item != nullptr) {
133133
memset(item, 0, sizeof(T));
134134
}
135135
return item;
136136
}
137137

138138
/** Allocate a memory block from a memory pool, optionally blocking, and set memory block to zero.
139139
@param millisec timeout value (osWaitForever to wait forever)
140-
@return address of the allocated memory block or NULL in case of no memory available.
140+
@return address of the allocated memory block or nullptr in case of no memory available.
141141
142142
@note You may call this function from ISR context if the millisec parameter is set to 0.
143143
*/
144144
T *calloc_for(uint32_t millisec)
145145
{
146146
T *item = alloc_for(millisec);
147-
if (item != NULL) {
147+
if (item != nullptr) {
148148
memset(item, 0, sizeof(T));
149149
}
150150
return item;
151151
}
152152

153153
/** Allocate a memory block from a memory pool, blocking, and set memory block to zero.
154154
@param millisec absolute timeout time, referenced to Kernel::get_ms_count().
155-
@return address of the allocated memory block or NULL in case of no memory available.
155+
@return address of the allocated memory block or nullptr in case of no memory available.
156156
157157
@note You cannot call this function from ISR context.
158158
@note the underlying RTOS may have a limit to the maximum wait time
@@ -163,7 +163,7 @@ class MemoryPool : private mbed::NonCopyable<MemoryPool<T, pool_sz> > {
163163
T *calloc_until(uint64_t millisec)
164164
{
165165
T *item = alloc_until(millisec);
166-
if (item != NULL) {
166+
if (item != nullptr) {
167167
memset(item, 0, sizeof(T));
168168
}
169169
return item;
@@ -172,7 +172,7 @@ class MemoryPool : private mbed::NonCopyable<MemoryPool<T, pool_sz> > {
172172
/** Free a memory block.
173173
@param block address of the allocated memory block to be freed.
174174
@return osOK on successful deallocation, osErrorParameter if given memory block id
175-
is NULL or invalid, or osErrorResource if given memory block is in an
175+
is nullptr or invalid, or osErrorResource if given memory block is in an
176176
invalid memory pool state.
177177
178178
@note You may call this function from ISR context.

rtos/Mutex.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -177,7 +177,7 @@ class Mutex : private mbed::NonCopyable<Mutex> {
177177

178178
private:
179179
#if MBED_CONF_RTOS_PRESENT
180-
void constructor(const char *name = NULL);
180+
void constructor(const char *name = nullptr);
181181
friend class ConditionVariable;
182182

183183
osMutexId_t _id;

rtos/Queue.h

+2-2
Original file line numberDiff line numberDiff line change
@@ -187,8 +187,8 @@ class Queue : private mbed::NonCopyable<Queue<T, queue_sz> > {
187187
osEvent get(uint32_t millisec = osWaitForever)
188188
{
189189
osEvent event;
190-
T *data = NULL;
191-
osStatus_t res = osMessageQueueGet(_id, &data, NULL, millisec);
190+
T *data = nullptr;
191+
osStatus_t res = osMessageQueueGet(_id, &data, nullptr, millisec);
192192

193193
switch (res) {
194194
case osOK:

rtos/RtosTimer.h

+2-2
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ class RtosTimer : private mbed::NonCopyable<RtosTimer> {
9191
/** Create timer.
9292
@param func function to be executed by this timer.
9393
@param type osTimerOnce for one-shot or osTimerPeriodic for periodic behavior. (default: osTimerPeriodic)
94-
@param argument argument to the timer call back function. (default: NULL)
94+
@param argument argument to the timer call back function. (default: nullptr)
9595
@deprecated Replaced with RtosTimer(Callback<void()>, os_timer_type)
9696
@deprecated
9797
The RtosTimer has been superseded by the EventQueue. See RtosTimer.h for more details
@@ -102,7 +102,7 @@ class RtosTimer : private mbed::NonCopyable<RtosTimer> {
102102
"Replaced with RtosTimer(Callback<void()>, os_timer_type)")
103103
MBED_DEPRECATED_SINCE("mbed-os-5.2",
104104
"The RtosTimer has been superseded by the EventQueue. See RtosTimer.h for more details")
105-
RtosTimer(void (*func)(void const *argument), os_timer_type type = osTimerPeriodic, void *argument = NULL)
105+
RtosTimer(void (*func)(void const *argument), os_timer_type type = osTimerPeriodic, void *argument = nullptr)
106106
{
107107
constructor(mbed::callback((void (*)(void *))func, argument), type);
108108
}

rtos/Semaphore.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ void Semaphore::constructor(int32_t count, uint16_t max_count)
4747
attr.cb_mem = &_obj_mem;
4848
attr.cb_size = sizeof(_obj_mem);
4949
_id = osSemaphoreNew(max_count, count, &attr);
50-
MBED_ASSERT(_id != NULL);
50+
MBED_ASSERT(_id != nullptr);
5151
#else
5252
_count = count;
5353
_max_count = max_count;

rtos/TARGET_CORTEX/mbed_rtx_idle.cpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -159,8 +159,8 @@ extern "C" {
159159

160160
void rtos_attach_idle_hook(void (*fptr)(void))
161161
{
162-
//Attach the specified idle hook, or the default idle hook in case of a NULL pointer
163-
if (fptr != NULL) {
162+
//Attach the specified idle hook, or the default idle hook in case of a null pointer
163+
if (fptr != nullptr) {
164164
idle_hook_fptr = fptr;
165165
} else {
166166
idle_hook_fptr = default_idle_hook;

rtos/ThisThread.cpp

+3-3
Original file line numberDiff line numberDiff line change
@@ -242,12 +242,12 @@ const char *get_name()
242242
{
243243
#if MBED_CONF_RTOS_PRESENT
244244
osThreadId_t id = osThreadGetId();
245-
if (id == NULL) {
246-
return NULL;
245+
if (id == nullptr) {
246+
return nullptr;
247247
}
248248
return osThreadGetName(id);
249249
#else
250-
return NULL;
250+
return nullptr;
251251
#endif
252252
}
253253

rtos/ThisThread.h

+2-2
Original file line numberDiff line numberDiff line change
@@ -169,13 +169,13 @@ void sleep_until(uint64_t millisec);
169169
void yield();
170170

171171
/** Get the thread id of the current running thread.
172-
@return thread ID for reference by other functions or NULL in case of error or in ISR context.
172+
@return thread ID for reference by other functions or nullptr in case of error or in ISR context.
173173
@note You may call this function from ISR context.
174174
*/
175175
osThreadId_t get_id();
176176

177177
/** Get the thread name of the current running thread.
178-
@return thread name pointer or NULL if thread has no name or in case of error.
178+
@return thread name pointer or nullptr if thread has no name or in case of error.
179179
@note You cannot call this function from ISR context.
180180
*/
181181
const char *get_name();

0 commit comments

Comments
 (0)