DeferredThreadDeleter class can be used to defer deletion of dynamic detached threads.
More...
#include "distortos/internal/memory/DeferredThreadDeleter.hpp"
DeferredThreadDeleter class can be used to defer deletion of dynamic detached threads.
◆ DeferredThreadDeleter()
constexpr distortos::internal::DeferredThreadDeleter::DeferredThreadDeleter |
( |
| ) |
|
|
inline |
◆ lock()
int distortos::internal::DeferredThreadDeleter::lock |
( |
| ) |
|
Locks the object, preparing it for adding thread to internal list.
Locks the mutex that synchronizes access to internal list. Locking (performed in this function) and unlocking (performed at the end of function call operator) are separated, because the locking must be done while the thread is still runnable, while the transfer to internal list is performed when the thread is not in this state.
- Note
- This function must be called before function call operator is used!
- Returns
- 0 on success, error code otherwise:
◆ operator()()
int distortos::internal::DeferredThreadDeleter::operator() |
( |
ThreadControlBlock & |
threadControlBlock | ) |
|
DeferredThreadDeleter's function call operator.
Adds thread to internal list of threads scheduled for deferred deletion and marks the list as "not empty".
- Note
- The object must be locked (with a successful call to DeferredThreadDeleter::lock()) before this function is used!
- Parameters
-
[in] | threadControlBlock | is a reference to ThreadControlBlock object associated with dynamic and detached thread that has terminated its execution |
- Returns
- 0 on success, error code otherwise:
◆ tryCleanup()
int distortos::internal::DeferredThreadDeleter::tryCleanup |
( |
| ) |
|
Tries to perform deferred deletion of threads.
Does nothing is the list is not marked as "not empty". Otherwise this function first tries to lock following two mutexes:
- mutex that protects dynamic memory allocator;
- mutex that synchronizes access to list of threads scheduled for deferred deletion; If any Mutex::tryLock() call fails, this function just returns (unlocking any mutexes is necessary). Otherwise the threads are removed from the list and deleted, while the list's "not empty" marker is cleared.
- Returns
- 0 on success, error code otherwise:
◆ tryCleanupInternal()
int distortos::internal::DeferredThreadDeleter::tryCleanupInternal |
( |
| ) |
|
|
private |
Internals of tryCleanup().
- Returns
- 0 on success, error code otherwise:
◆ list_
list of threads scheduled for deferred deletion
◆ mutex_
Mutex distortos::internal::DeferredThreadDeleter::mutex_ |
|
private |
mutex that synchronizes access to the list_
◆ notEmpty_
volatile bool distortos::internal::DeferredThreadDeleter::notEmpty_ |
|
private |
true if list_ is not empty, false otherwise
The documentation for this class was generated from the following files: