ChibiOS/RT
2.5.1
Dynamic Threads
Collaboration diagram for Dynamic Threads:

Detailed Description

Dynamic threads related APIs and services.

Functions

ThreadchThdAddRef (Thread *tp)
 Adds a reference to a thread object.
void chThdRelease (Thread *tp)
 Releases a reference to a thread object.
ThreadchThdCreateFromHeap (MemoryHeap *heapp, size_t size, tprio_t prio, tfunc_t pf, void *arg)
 Creates a new thread allocating the memory from the heap.
ThreadchThdCreateFromMemoryPool (MemoryPool *mp, tprio_t prio, tfunc_t pf, void *arg)
 Creates a new thread allocating the memory from the specified memory pool.

Function Documentation

Thread * chThdAddRef ( Thread tp)

Adds a reference to a thread object.

Precondition:
The configuration option CH_USE_DYNAMIC must be enabled in order to use this function.
Parameters:
[in]tppointer to the thread
Returns:
The same thread pointer passed as parameter representing the new reference.
Function Class:
Normal API, this function can be invoked by regular system threads but not from within a lock zone.

Definition at line 45 of file chdynamic.c.

References chDbgAssert, chSysLock, chSysUnlock, and Thread::p_refs.

void chThdRelease ( Thread tp)

Releases a reference to a thread object.

If the references counter reaches zero and the thread is in the THD_STATE_FINAL state then the thread's memory is returned to the proper allocator.

Precondition:
The configuration option CH_USE_DYNAMIC must be enabled in order to use this function.
Note:
Static threads are not affected.
Parameters:
[in]tppointer to the thread
Function Class:
Normal API, this function can be invoked by regular system threads but not from within a lock zone.

Definition at line 67 of file chdynamic.c.

References chDbgAssert, chHeapFree(), chPoolFree(), chSysLock, chSysUnlock, Thread::p_flags, Thread::p_mpool, Thread::p_refs, Thread::p_state, REG_REMOVE, THD_MEM_MODE_HEAP, THD_MEM_MODE_MASK, THD_MEM_MODE_MEMPOOL, and THD_STATE_FINAL.

Referenced by chRegNextThread(), and chThdWait().

Here is the call graph for this function:

Thread * chThdCreateFromHeap ( MemoryHeap heapp,
size_t  size,
tprio_t  prio,
tfunc_t  pf,
void *  arg 
)

Creates a new thread allocating the memory from the heap.

Precondition:
The configuration options CH_USE_DYNAMIC and CH_USE_HEAP must be enabled in order to use this function.
Note:
A thread can terminate by calling chThdExit() or by simply returning from its main function.
The memory allocated for the thread is not released when the thread terminates but when a chThdWait() is performed.
Parameters:
[in]heappheap from which allocate the memory or NULL for the default heap
[in]sizesize of the working area to be allocated
[in]priothe priority level for the new thread
[in]pfthe thread function
[in]argan argument passed to the thread function. It can be NULL.
Returns:
The pointer to the Thread structure allocated for the thread into the working space area.
Return values:
NULLif the memory cannot be allocated.
Function Class:
Normal API, this function can be invoked by regular system threads but not from within a lock zone.

Definition at line 123 of file chdynamic.c.

References _thread_memfill(), CH_STACK_FILL_VALUE, CH_THREAD_FILL_VALUE, chHeapAlloc(), chSchWakeupS(), chSysLock, chSysUnlock, chThdCreateI(), Thread::p_flags, RDY_OK, and THD_MEM_MODE_HEAP.

Here is the call graph for this function:

Thread * chThdCreateFromMemoryPool ( MemoryPool mp,
tprio_t  prio,
tfunc_t  pf,
void *  arg 
)

Creates a new thread allocating the memory from the specified memory pool.

Precondition:
The configuration options CH_USE_DYNAMIC and CH_USE_MEMPOOLS must be enabled in order to use this function.
Note:
A thread can terminate by calling chThdExit() or by simply returning from its main function.
The memory allocated for the thread is not released when the thread terminates but when a chThdWait() is performed.
Parameters:
[in]mppointer to the memory pool object
[in]priothe priority level for the new thread
[in]pfthe thread function
[in]argan argument passed to the thread function. It can be NULL.
Returns:
The pointer to the Thread structure allocated for the thread into the working space area.
Return values:
NULLif the memory pool is empty.
Function Class:
Normal API, this function can be invoked by regular system threads but not from within a lock zone.

Definition at line 172 of file chdynamic.c.

References _thread_memfill(), CH_STACK_FILL_VALUE, CH_THREAD_FILL_VALUE, chDbgCheck, chPoolAlloc(), chSchWakeupS(), chSysLock, chSysUnlock, chThdCreateI(), MemoryPool::mp_object_size, Thread::p_flags, Thread::p_mpool, RDY_OK, and THD_MEM_MODE_MEMPOOL.

Here is the call graph for this function: