29 #ifndef IOT_TASKPOOL_INTERNAL_H_ 30 #define IOT_TASKPOOL_INTERNAL_H_ 33 #include "iot_config.h" 36 #include "iot_error.h" 44 #define TASKPOOL_SUCCEEDED( x ) ( ( x ) == IOT_TASKPOOL_SUCCESS ) 49 #define TASKPOOL_FAILED( x ) ( ( x ) != IOT_TASKPOOL_SUCCESS ) 54 #define TASKPOOL_GOTO_CLEANUP() IOT_GOTO_CLEANUP() 59 #define TASKPOOL_FUNCTION_ENTRY( result ) IOT_FUNCTION_ENTRY( IotTaskPoolError_t, result ) 64 #define TASKPOOL_ON_ERROR_GOTO_CLEANUP( expr ) \ 65 { if( TASKPOOL_FAILED( status = ( expr ) ) ) { IOT_GOTO_CLEANUP(); } \ 71 #define TASKPOOL_ON_NULL_ARG_GOTO_CLEANUP( ptr ) IOT_VALIDATE_PARAMETER( IOT_TASKPOOL, ( ptr != NULL ) ) 76 #define TASKPOOL_ON_ARG_ERROR_GOTO_CLEANUP( expr ) IOT_VALIDATE_PARAMETER( IOT_TASKPOOL, ( ( expr ) == false ) ) 81 #define TASKPOOL_SET_AND_GOTO_CLEANUP( expr ) IOT_SET_AND_GOTO_CLEANUP( expr ) 86 #define TASKPOOL_FUNCTION_CLEANUP() IOT_FUNCTION_CLEANUP_BEGIN() 91 #define TASKPOOL_FUNCTION_CLEANUP_END() IOT_FUNCTION_CLEANUP_END() 96 #define TASKPOOL_NO_FUNCTION_CLEANUP() IOT_FUNCTION_EXIT_NO_CLEANUP() 101 #define TASKPOOL_NO_FUNCTION_CLEANUP_NOLABEL() return status 112 #if IOT_TASKPOOL_ENABLE_ASSERTS == 1 113 #ifndef IotTaskPool_Assert 114 #ifdef Iot_DefaultAssert 115 #define IotTaskPool_Assert( expression ) Iot_DefaultAssert( expression ) 117 #error "Asserts are enabled for Task Pool, but IotTaskPool_Assert is not defined" 121 #define IotTaskPool_Assert( expression ) 125 #ifdef IOT_LOG_LEVEL_TASKPOOL 126 #define LIBRARY_LOG_LEVEL IOT_LOG_LEVEL_TASKPOOL 128 #ifdef IOT_LOG_LEVEL_GLOBAL 129 #define LIBRARY_LOG_LEVEL IOT_LOG_LEVEL_GLOBAL 131 #define LIBRARY_LOG_LEVEL IOT_LOG_NONE 135 #define LIBRARY_LOG_NAME ( "TASKPOOL" ) 142 #if IOT_STATIC_MEMORY_ONLY == 1 185 #ifndef IotTaskPool_MallocTaskPool 186 #ifdef Iot_DefaultMalloc 187 #define IotTaskPool_MallocTaskPool Iot_DefaultMalloc 189 #error "No malloc function defined for IotTaskPool_MallocTaskPool" 193 #ifndef IotTaskPool_FreeTaskPool 194 #ifdef Iot_DefaultFree 195 #define IotTaskPool_FreeTaskPool Iot_DefaultFree 197 #error "No free function defined for IotTaskPool_FreeTaskPool" 201 #ifndef IotTaskPool_MallocJob 202 #ifdef Iot_DefaultMalloc 203 #define IotTaskPool_MallocJob Iot_DefaultMalloc 205 #error "No malloc function defined for IotTaskPool_MallocJob" 209 #ifndef IotTaskPool_FreeJob 210 #ifdef Iot_DefaultFree 211 #define IotTaskPool_FreeJob Iot_DefaultFree 213 #error "No free function defined for IotTaskPool_FreeJob" 217 #ifndef IotTaskPool_MallocTimerEvent 218 #ifdef Iot_DefaultMalloc 219 #define IotTaskPool_MallocTimerEvent Iot_DefaultMalloc 221 #error "No malloc function defined for IotTaskPool_MallocTimerEvent" 225 #ifndef IotTaskPool_FreeTimerEvent 226 #ifdef Iot_DefaultFree 227 #define IotTaskPool_FreeTimerEvent Iot_DefaultFree 229 #error "No free function defined for IotTaskPool_FreeTimerEvent" 242 #define IOT_TASK_POOL_INTERNAL_STATIC ( ( uint32_t ) 0x00000001 ) 252 typedef struct _taskPoolCache
267 typedef struct _taskPool
291 typedef struct _taskPoolJob
306 typedef struct _taskPoolTimerEvent
_taskPoolCache_t jobsCache
A cache to re-use jobs in order to limit memory allocations.
Definition: iot_taskpool_internal.h:271
IotLink_t link
List link member.
Definition: iot_taskpool_internal.h:308
_taskPoolJob_t * pJob
The task pool job associated with this event.
Definition: iot_taskpool_internal.h:310
uint32_t maxThreads
The maximum number of threads for the task pool.
Definition: iot_taskpool_internal.h:273
The task pool data structure keeps track of the internal state and the signals for the dispatcher thr...
Definition: iot_taskpool_internal.h:267
User-facing functions of the task pool library.
IotDeQueue_t dispatchQueue
The queue for the jobs waiting to be executed.
Definition: iot_taskpool_internal.h:269
int32_t priority
The priority for all task pool threads.
Definition: iot_taskpool_internal.h:277
Task pool jobs cache.
Definition: iot_taskpool_internal.h:252
void IotTaskPool_FreeTaskPool(void *ptr)
Free an _taskPool_t. This function should have the same signature as [malloc].
Definition: iot_taskpool_static_memory.c:89
void IotTaskPool_FreeJob(void *ptr)
Free an IotTaskPoolJob_t. This function should have the same same signature as [malloc]. (http://pubs.opengroup.org/onlinepubs/9699919799/functions/malloc.html).
Definition: iot_taskpool_static_memory.c:124
IotTaskPoolJobStatus_t status
The status for the job.
Definition: iot_taskpool_internal.h:297
void IotTaskPool_FreeTimerEvent(void *ptr)
Free an _taskPoolTimerEvent_t. This function should have the same signature as[ free ]...
Definition: iot_taskpool_static_memory.c:159
IotTaskPoolJobStatus_t
Status codes of task pool Job.
Definition: iot_taskpool_types.h:98
void * pUserContext
The user provided context.
Definition: iot_taskpool_internal.h:295
uint32_t flags
Internal flags.
Definition: iot_taskpool_internal.h:296
uint32_t activeJobs
The number of active jobs in the task pool at any given time.
Definition: iot_taskpool_internal.h:275
The job data structure keeps track of the user callback and context, as well as the status of the job...
Definition: iot_taskpool_internal.h:291
void * IotTaskPool_MallocTaskPool(size_t size)
Allocate an _taskPool_t. This function should have the same signature as [malloc].
Definition: iot_taskpool_static_memory.c:67
IotTaskPoolRoutine_t userCallback
The user provided callback.
Definition: iot_taskpool_internal.h:294
IotListDouble_t freeList
A list of hold cached jobs.
Definition: iot_taskpool_internal.h:254
uint32_t freeCount
A counter to track the number of jobs in the cache.
Definition: iot_taskpool_internal.h:256
void * IotTaskPool_MallocJob(size_t size)
Allocate an IotTaskPoolJob_t. This function should have the same signature as [malloc].
Definition: iot_taskpool_static_memory.c:101
IotListDouble_t timerEventsList
The timeouts queue for all deferred jobs waiting to be executed.
Definition: iot_taskpool_internal.h:270
uint64_t expirationTime
When this event should be processed.
Definition: iot_taskpool_internal.h:309
IotLink_t link
The link to insert the job in the dispatch queue.
Definition: iot_taskpool_internal.h:293
IotTimer_t timer
The timer for deferred jobs.
Definition: iot_taskpool_internal.h:280
IotMutex_t lock
The lock to protect the task pool data structure access.
Definition: iot_taskpool_internal.h:281
Represents an operation that is subject to a timer.
Definition: iot_taskpool_internal.h:306
void * IotTaskPool_MallocTimerEvent(size_t size)
Allocate an _taskPoolTimerEvent_t. This function should have the same signature as [malloc]...
Definition: iot_taskpool_static_memory.c:136
IotSemaphore_t dispatchSignal
The synchronization object on which threads are waiting for incoming jobs.
Definition: iot_taskpool_internal.h:278
uint32_t minThreads
The minimum number of threads for the task pool.
Definition: iot_taskpool_internal.h:272
IotSemaphore_t startStopSignal
The synchronization object for threads to signal start and stop condition.
Definition: iot_taskpool_internal.h:279
void(* IotTaskPoolRoutine_t)(IotTaskPool_t pTaskPool, IotTaskPoolJob_t pJob, void *pUserContext)
Callback type for a user callback.
Definition: iot_taskpool_types.h:203
uint32_t activeThreads
The number of threads in the task pool at any given time.
Definition: iot_taskpool_internal.h:274
uint32_t stackSize
The stack size for all task pool threads.
Definition: iot_taskpool_internal.h:276