distortos  v0.4.0
object-oriented C++ RTOS for microcontrollers
distortos::internal::DeferredThreadDeleter Class Reference

DeferredThreadDeleter class can be used to defer deletion of dynamic detached threads. More...

#include <DeferredThreadDeleter.hpp>

Collaboration diagram for distortos::internal::DeferredThreadDeleter:
[legend]

Public Member Functions

constexpr DeferredThreadDeleter ()
 DeferredThreadDeleter's constructor. More...
 
int operator() (ThreadControlBlock &threadControlBlock)
 DeferredThreadDeleter's function call operator. More...
 
int lock ()
 Locks the object, preparing it for adding thread to internal list. More...
 
int tryCleanup ()
 Tries to perform deferred deletion of threads. More...
 

Private Member Functions

int tryCleanupInternal ()
 Internals of tryCleanup(). More...
 

Private Attributes

ThreadList::UnsortedIntrusiveList list_
 list of threads scheduled for deferred deletion More...
 
Mutex mutex_
 mutex that synchronizes access to the list_ More...
 
bool notEmpty_
 true if list_ is not empty, false otherwise More...
 

Detailed Description

DeferredThreadDeleter class can be used to defer deletion of dynamic detached threads.

Constructor & Destructor Documentation

◆ DeferredThreadDeleter()

constexpr distortos::internal::DeferredThreadDeleter::DeferredThreadDeleter ( )
inline

DeferredThreadDeleter's constructor.

Here is the call graph for this function:

Member Function Documentation

◆ 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:
Here is the call graph for this function:
Here is the caller graph for this function:

◆ 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]threadControlBlockis a reference to ThreadControlBlock object associated with dynamic and detached thread that has terminated its execution
Returns
0 on success, error code otherwise:
Here is the call graph for this function:
Here is the caller graph for this function:

◆ 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:
Here is the call graph for this function:
Here is the caller graph for this function:

◆ tryCleanupInternal()

int distortos::internal::DeferredThreadDeleter::tryCleanupInternal ( )
private

Internals of tryCleanup().

Returns
0 on success, error code otherwise:
Here is the call graph for this function:
Here is the caller graph for this function:

Member Data Documentation

◆ list_

ThreadList::UnsortedIntrusiveList distortos::internal::DeferredThreadDeleter::list_
private

list of threads scheduled for deferred deletion

◆ mutex_

Mutex distortos::internal::DeferredThreadDeleter::mutex_
private

mutex that synchronizes access to the list_

◆ notEmpty_

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: