Skip to content

Commit cf91c94

Browse files
electretmikeMichiel van Leeuwenjonenz
authored
Allow deletionof Tasks (#7)
* un-delete operator delete This operator does not need to be deleted. It prevents object from being deleted after destruction. There is no use-case for that. * Move delete functions into base class destructors. --------- Co-authored-by: Michiel van Leeuwen <[email protected]> Co-authored-by: Jon Enz <[email protected]>
1 parent 96d2b3e commit cf91c94

File tree

8 files changed

+123
-167
lines changed

8 files changed

+123
-167
lines changed

FreeRTOS-Cpp/include/FreeRTOS/EventGroups.hpp

Lines changed: 16 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -56,8 +56,6 @@ class EventGroupBase {
5656
static void* operator new[](size_t, void* ptr) { return ptr; }
5757
static void* operator new(size_t) = delete;
5858
static void* operator new[](size_t) = delete;
59-
static void operator delete(void*) = delete;
60-
static void operator delete[](void*) = delete;
6159

6260
// NOLINTNEXTLINE
6361
using EventBits = std::bitset<((configUSE_16_BIT_TICKS == 1) ? 8 : 24)>;
@@ -380,7 +378,21 @@ class EventGroupBase {
380378
* FreeRTOS::EventGroup or FreeRTOS::StaticEventGroup.
381379
*/
382380
EventGroupBase() = default;
383-
~EventGroupBase() = default;
381+
382+
/**
383+
* EventGroup.hpp
384+
*
385+
* @brief Destroy the EventGroupBase object by calling <tt>void
386+
* vEventGroupDelete( EventGroupHandle_t xEventGroup )</tt>
387+
*
388+
* @see <https://www.freertos.org/vEventGroupDelete.html>
389+
*
390+
* Delete an event group.
391+
*
392+
* Tasks that are blocked on the event group being deleted will be unblocked,
393+
* and report an event group value of 0.
394+
*/
395+
~EventGroupBase() { vEventGroupDelete(this->handle); };
384396

385397
EventGroupBase(EventGroupBase&&) noexcept = default;
386398
EventGroupBase& operator=(EventGroupBase&&) noexcept = default;
@@ -425,21 +437,7 @@ class EventGroup : public EventGroupBase {
425437
* @include EventGroups/eventGroup.cpp
426438
*/
427439
EventGroup() { this->handle = xEventGroupCreate(); }
428-
429-
/**
430-
* EventGroup.hpp
431-
*
432-
* @brief Destroy the EventGroup object by calling <tt>void vEventGroupDelete(
433-
* EventGroupHandle_t xEventGroup )</tt>
434-
*
435-
* @see <https://www.freertos.org/vEventGroupDelete.html>
436-
*
437-
* Delete an event group.
438-
*
439-
* Tasks that are blocked on the event group being deleted will be unblocked,
440-
* and report an event group value of 0.
441-
*/
442-
~EventGroup() { vEventGroupDelete(this->handle); }
440+
~EventGroup() = default;
443441

444442
EventGroup(const EventGroup&) = delete;
445443
EventGroup& operator=(const EventGroup&) = delete;

FreeRTOS-Cpp/include/FreeRTOS/MessageBuffer.hpp

Lines changed: 14 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -69,8 +69,6 @@ class MessageBufferBase {
6969
static void* operator new[](size_t, void* ptr) { return ptr; }
7070
static void* operator new(size_t) = delete;
7171
static void* operator new[](size_t) = delete;
72-
static void operator delete(void*) = delete;
73-
static void operator delete[](void*) = delete;
7472

7573
/**
7674
* MessageBuffer.hpp
@@ -391,7 +389,19 @@ class MessageBufferBase {
391389

392390
private:
393391
MessageBufferBase() = default;
394-
~MessageBufferBase() = default;
392+
393+
/**
394+
* MessageBuffer.hpp
395+
*
396+
* @brief Destroy the MessageBufferBase object by calling <tt>void
397+
* vMessageBufferDelete( MessageBufferHandle_t xMessageBuffer )</tt>
398+
*
399+
* @see <https://www.freertos.org/vMessageBufferDelete.html>
400+
*
401+
* Delete a queue - freeing all the memory allocated for storing of items
402+
* placed on the queue.
403+
*/
404+
~MessageBufferBase() { vMessageBufferDelete(this->handle); }
395405

396406
MessageBufferBase(MessageBufferBase&&) noexcept = default;
397407
MessageBufferBase& operator=(MessageBufferBase&&) noexcept = default;
@@ -439,19 +449,7 @@ class MessageBuffer : public MessageBufferBase {
439449
explicit MessageBuffer(size_t size) {
440450
this->handle = xMessageBufferCreate(size);
441451
}
442-
443-
/**
444-
* MessageBuffer.hpp
445-
*
446-
* @brief Destroy the MessageBuffer object by calling <tt>void
447-
* vMessageBufferDelete( MessageBufferHandle_t xMessageBuffer )</tt>
448-
*
449-
* @see <https://www.freertos.org/vMessageBufferDelete.html>
450-
*
451-
* Delete a queue - freeing all the memory allocated for storing of items
452-
* placed on the queue.
453-
*/
454-
~MessageBuffer() { vMessageBufferDelete(this->handle); }
452+
~MessageBuffer() = default;
455453

456454
MessageBuffer(const MessageBuffer&) = delete;
457455
MessageBuffer& operator=(const MessageBuffer&) = delete;

FreeRTOS-Cpp/include/FreeRTOS/Mutex.hpp

Lines changed: 15 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -59,8 +59,6 @@ class MutexBase {
5959
static void* operator new[](size_t, void* ptr) { return ptr; }
6060
static void* operator new(size_t) = delete;
6161
static void* operator new[](size_t) = delete;
62-
static void operator delete(void*) = delete;
63-
static void operator delete[](void*) = delete;
6462

6563
/**
6664
* Mutex.hpp
@@ -159,7 +157,19 @@ class MutexBase {
159157

160158
private:
161159
MutexBase() = default;
162-
~MutexBase() = default;
160+
161+
/**
162+
* Mutex.hpp
163+
*
164+
* @brief Destroy the MutexBase object by calling <tt>void vSemaphoreDelete(
165+
* SemaphoreHandle_t xSemaphore )</tt>
166+
*
167+
* @see <https://www.freertos.org/a00113.html#vSemaphoreDelete>
168+
*
169+
* @note Do not delete a mutex that has tasks blocked on it (tasks that are in
170+
* the Blocked state waiting for the mutex to become available).
171+
*/
172+
~MutexBase() { vSemaphoreDelete(this->handle); }
163173

164174
MutexBase(MutexBase&&) noexcept = default;
165175
MutexBase& operator=(MutexBase&&) noexcept = default;
@@ -194,8 +204,6 @@ class RecursiveMutexBase : public MutexBase {
194204
static void* operator new[](size_t, void*);
195205
static void* operator new(size_t) = delete;
196206
static void* operator new[](size_t) = delete;
197-
static void operator delete(void*) = delete;
198-
static void operator delete[](void*) = delete;
199207

200208
/**
201209
* Mutex.hpp
@@ -298,19 +306,7 @@ class Mutex : public MutexBase {
298306
* @include Mutex/mutex.cpp
299307
*/
300308
Mutex() { this->handle = xSemaphoreCreateMutex(); }
301-
302-
/**
303-
* Mutex.hpp
304-
*
305-
* @brief Destroy the Mutex object by calling <tt>void vSemaphoreDelete(
306-
* SemaphoreHandle_t xSemaphore )</tt>
307-
*
308-
* @see <https://www.freertos.org/a00113.html#vSemaphoreDelete>
309-
*
310-
* @note Do not delete a mutex that has tasks blocked on it (tasks that are in
311-
* the Blocked state waiting for the mutex to become available).
312-
*/
313-
~Mutex() { vSemaphoreDelete(this->handle); }
309+
~Mutex() = default;
314310

315311
Mutex(const Mutex&) = delete;
316312
Mutex& operator=(const Mutex&) = delete;
@@ -363,19 +359,7 @@ class RecursiveMutex : public RecursiveMutexBase {
363359
* @include Mutex/recursiveMutex.cpp
364360
*/
365361
RecursiveMutex() { this->handle = xSemaphoreCreateRecursiveMutex(); }
366-
367-
/**
368-
* Mutex.hpp
369-
*
370-
* @brief Destroy the RecursiveMutex object by calling <tt>void
371-
* vSemaphoreDelete( SemaphoreHandle_t xSemaphore )</tt>
372-
*
373-
* @see <https://www.freertos.org/a00113.html#vSemaphoreDelete>
374-
*
375-
* @note Do not delete a mutex that has tasks blocked on it (tasks that are in
376-
* the Blocked state waiting for the mutex to become available).
377-
*/
378-
~RecursiveMutex() { vSemaphoreDelete(this->handle); }
362+
~RecursiveMutex() = default;
379363

380364
RecursiveMutex(const RecursiveMutex&) = delete;
381365
RecursiveMutex& operator=(const RecursiveMutex&) = delete;

FreeRTOS-Cpp/include/FreeRTOS/Queue.hpp

Lines changed: 14 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -62,8 +62,6 @@ class QueueBase {
6262
static void* operator new[](size_t, void* ptr) { return ptr; }
6363
static void* operator new(size_t) = delete;
6464
static void* operator new[](size_t) = delete;
65-
static void operator delete(void*) = delete;
66-
static void operator delete[](void*) = delete;
6765

6866
/**
6967
* Queue.hpp
@@ -610,7 +608,19 @@ class QueueBase {
610608
* FreeRTOS::Queue or FreeRTOS::StaticQueue.
611609
*/
612610
QueueBase() = default;
613-
~QueueBase() = default;
611+
612+
/**
613+
* Queue.hpp
614+
*
615+
* @brief Destroy the QueueBase object by calling <tt>void vQueueDelete(
616+
* QueueHandle_t xQueue )</tt>
617+
*
618+
* @see <https://www.freertos.org/a00018.html#vQueueDelete>
619+
*
620+
* Delete a queue - freeing all the memory allocated for storing of items
621+
* placed on the queue.
622+
*/
623+
~QueueBase() { vQueueDelete(this->handle); }
614624

615625
QueueBase(QueueBase&&) noexcept = default;
616626
QueueBase& operator=(QueueBase&&) noexcept = default;
@@ -659,19 +669,7 @@ class Queue : public QueueBase<T> {
659669
explicit Queue(const UBaseType_t length) {
660670
this->handle = xQueueCreate(length, sizeof(T));
661671
}
662-
663-
/**
664-
* Queue.hpp
665-
*
666-
* @brief Destroy the Queue object by calling <tt>void vQueueDelete(
667-
* QueueHandle_t xQueue )</tt>
668-
*
669-
* @see <https://www.freertos.org/a00018.html#vQueueDelete>
670-
*
671-
* Delete a queue - freeing all the memory allocated for storing of items
672-
* placed on the queue.
673-
*/
674-
~Queue() { vQueueDelete(this->handle); }
672+
~Queue() = default;
675673

676674
Queue(const Queue&) = delete;
677675
Queue& operator=(const Queue&) = delete;

FreeRTOS-Cpp/include/FreeRTOS/Semaphore.hpp

Lines changed: 15 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -58,8 +58,6 @@ class SemaphoreBase {
5858
static void* operator new[](size_t, void* ptr) { return ptr; }
5959
static void* operator new(size_t) = delete;
6060
static void* operator new[](size_t) = delete;
61-
static void operator delete(void*) = delete;
62-
static void operator delete[](void*) = delete;
6361

6462
/**
6563
* Semaphore.hpp
@@ -241,7 +239,19 @@ class SemaphoreBase {
241239

242240
private:
243241
SemaphoreBase() = default;
244-
~SemaphoreBase() = default;
242+
243+
/**
244+
* Semaphore.hpp
245+
*
246+
* @brief Destroy the SemaphoreBase object by calling <tt>void
247+
* vSemaphoreDelete( SemaphoreHandle_t xSemaphore )</tt>
248+
*
249+
* @see <https://www.freertos.org/a00113.html#vSemaphoreDelete>
250+
*
251+
* @note Do not delete a semaphore that has tasks blocked on it (tasks that
252+
* are in the Blocked state waiting for the semaphore to become available).
253+
*/
254+
~SemaphoreBase() { vSemaphoreDelete(this->handle); }
245255

246256
SemaphoreBase(SemaphoreBase&&) noexcept = default;
247257
SemaphoreBase& operator=(SemaphoreBase&&) noexcept = default;
@@ -314,19 +324,7 @@ class BinarySemaphore : public SemaphoreBase {
314324
* @include Semaphore/binarySemaphore.cpp
315325
*/
316326
BinarySemaphore() { this->handle = xSemaphoreCreateBinary(); }
317-
318-
/**
319-
* Semaphore.hpp
320-
*
321-
* @brief Destroy the BinarySemaphore object by calling <tt>void
322-
* vSemaphoreDelete( SemaphoreHandle_t xSemaphore )</tt>
323-
*
324-
* @see <https://www.freertos.org/a00113.html#vSemaphoreDelete>
325-
*
326-
* @note Do not delete a semaphore that has tasks blocked on it (tasks that
327-
* are in the Blocked state waiting for the semaphore to become available).
328-
*/
329-
~BinarySemaphore() { vSemaphoreDelete(this->handle); }
327+
~BinarySemaphore() = default;
330328

331329
BinarySemaphore(const BinarySemaphore&) = delete;
332330
BinarySemaphore& operator=(const BinarySemaphore&) = delete;
@@ -391,22 +389,7 @@ class CountingSemaphore : public SemaphoreBase {
391389
const UBaseType_t initialCount = 0) {
392390
this->handle = xSemaphoreCreateCounting(maxCount, initialCount);
393391
}
394-
395-
/**
396-
* Semaphore.hpp
397-
*
398-
* @brief Destroy the CountingSemaphore object by calling
399-
* <tt>void vSemaphoreDelete( SemaphoreHandle_t xSemaphore )</tt>
400-
*
401-
* @see <https://www.freertos.org/a00113.html#vSemaphoreDelete>
402-
*
403-
* @note Do not delete a semaphore that has tasks blocked on it (tasks that
404-
* are in the Blocked state waiting for the semaphore to become available).
405-
*
406-
* <b>Example Usage</b>
407-
* @include Semaphore/countingSemaphore.cpp
408-
*/
409-
~CountingSemaphore() { vSemaphoreDelete(this->handle); }
392+
~CountingSemaphore() = default;
410393

411394
CountingSemaphore(const CountingSemaphore&) = delete;
412395
CountingSemaphore& operator=(const CountingSemaphore&) = delete;

FreeRTOS-Cpp/include/FreeRTOS/StreamBuffer.hpp

Lines changed: 13 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -69,8 +69,6 @@ class StreamBufferBase {
6969
static void* operator new[](size_t, void* ptr) { return ptr; }
7070
static void* operator new(size_t) = delete;
7171
static void* operator new[](size_t) = delete;
72-
static void operator delete(void*) = delete;
73-
static void operator delete[](void*) = delete;
7472

7573
/**
7674
* StreamBuffer.hpp
@@ -422,7 +420,18 @@ class StreamBufferBase {
422420

423421
private:
424422
StreamBufferBase() = default;
425-
~StreamBufferBase() = default;
423+
424+
/**
425+
* StreamBuffer.hpp
426+
*
427+
* @brief Destroy the StreamBufferBase object by calling
428+
* <tt>void vStreamBufferDelete( StreamBufferHandle_t xStreamBuffer )</tt>
429+
*
430+
* @see <https://www.freertos.org/vStreamBufferDelete.html>
431+
*
432+
* Deletes a stream buffer and free the allocated memory.
433+
*/
434+
~StreamBufferBase() { vStreamBufferDelete(this->handle); }
426435

427436
StreamBufferBase(StreamBufferBase&&) noexcept = default;
428437
StreamBufferBase& operator=(StreamBufferBase&&) noexcept = default;
@@ -478,18 +487,7 @@ class StreamBuffer : public StreamBufferBase {
478487
explicit StreamBuffer(const size_t size, const size_t triggerLevel = 0) {
479488
this->handle = xStreamBufferCreate(size, triggerLevel);
480489
}
481-
482-
/**
483-
* StreamBuffer.hpp
484-
*
485-
* @brief Destroy the StreamBuffer object by calling
486-
* <tt>void vStreamBufferDelete( StreamBufferHandle_t xStreamBuffer )</tt>
487-
*
488-
* @see <https://www.freertos.org/vStreamBufferDelete.html>
489-
*
490-
* Deletes a stream buffer and free the allocated memory.
491-
*/
492-
~StreamBuffer() { vStreamBufferDelete(this->handle); }
490+
~StreamBuffer() = default;
493491

494492
StreamBuffer(const StreamBuffer&) = delete;
495493
StreamBuffer& operator=(const StreamBuffer&) = delete;

0 commit comments

Comments
 (0)