Task Pool API Reference
Task pool library
IotTaskPool_Schedule

This function schedules a job created with IotTaskPool_CreateJob or IotTaskPool_CreateRecyclableJob against the task pool pointed to by taskPool.

See Design for a description of the jobs lifetime and interaction with the threads used in the task pool library.

Parameters
[in]taskPoolA handle to the task pool that must have been previously initialized with. a call to IotTaskPool_Create.
[in]jobA job to schedule for execution. This must be first initialized with a call to IotTaskPool_CreateJob.
[in]flagsFlags to be passed by the user, e.g. to identify the job as high priority by specifying IOT_TASKPOOL_JOB_HIGH_PRIORITY.
Returns
One of the following:
Note
This function will not allocate memory, so it is guaranteed to succeed if the paramters are correct and the task pool was correctly initialized, and not yet destroyed.
Warning
The taskPool used in this function should be the same used to create the job pointed to by job, or the results will be undefined.

Example

// An example of a user context to pass to a callback through a task pool thread.
typedef struct JobUserContext
{
uint32_t counter;
} JobUserContext_t;
// An example of a user callback to invoke through a task pool thread.
static void ExecutionCb( IotTaskPool_t taskPool, IotTaskPoolJob_t job, void * context )
{
( void )taskPool;
( void )job;
JobUserContext_t * pUserContext = ( JobUserContext_t * )context;
pUserContext->counter++;
}
void TaskPoolExample( )
{
JobUserContext_t userContext = { 0 };
IotTaskPool_t taskPool;
// Configure the task pool to hold at least two threads and three at the maximum.
// Provide proper stack size and priority per the application needs.
const IotTaskPoolInfo_t tpInfo = { .minThreads = 2, .maxThreads = 3, .stackSize = 512, .priority = 0 };
// Create a task pool.
IotTaskPool_Create( &tpInfo, &taskPool );
// Statically allocate one job, schedule it.
IotTaskPool_CreateJob( &ExecutionCb, &userContext, &job );
IotTaskPoolError_t errorSchedule = IotTaskPool_Schedule( taskPool, &job, 0 );
switch ( errorSchedule )
{
break;
case IOT_TASKPOOL_BAD_PARAMETER: // Invalid parameters, such as a NULL handle, can trigger this error.
case IOT_TASKPOOL_ILLEGAL_OPERATION: // Scheduling a job that was previously scheduled or destroyed could trigger this error.
case IOT_TASKPOOL_NO_MEMORY: // Scheduling a with flag #IOT_TASKPOOL_JOB_HIGH_PRIORITY could trigger this error.
case IOT_TASKPOOL_SHUTDOWN_IN_PROGRESS: // Scheduling a job after trying to destroy the task pool could trigger this error.
// ASSERT
break;
default:
// ASSERT
}
//
// ... Perform other operations ...
//
IotTaskPool_Destroy( taskPool );
}
IOT_TASKPOOL_SHUTDOWN_IN_PROGRESS
Task pool operation failed because of an invalid parameter.
Definition: iot_taskpool_types.h:135
IOT_TASKPOOL_BAD_PARAMETER
Task pool operation failed because at least one parameter is invalid.
Definition: iot_taskpool_types.h:90
IotTaskPool_t
struct _taskPool * IotTaskPool_t
Opaque handle of a Task Pool instance.
Definition: iot_taskpool_types.h:213
IOT_TASKPOOL_ILLEGAL_OPERATION
Task pool operation failed because it is illegal.
Definition: iot_taskpool_types.h:105
IotTaskPoolInfo_t
Initialization information to create one task pool instance.
Definition: iot_taskpool_types.h:273
IotTaskPool_Create
IotTaskPoolError_t IotTaskPool_Create(const IotTaskPoolInfo_t *const pInfo, IotTaskPool_t *const pTaskPool)
Creates one instance of a task pool.
IOT_TASKPOOL_SUCCESS
Task pool operation completed successfully.
Definition: iot_taskpool_types.h:70
IOT_TASKPOOL_NO_MEMORY
Task pool operation failed because allocating memory failed.
Definition: iot_taskpool_types.h:119
IotTaskPool_CreateJob
IotTaskPoolError_t IotTaskPool_CreateJob(IotTaskPoolRoutine_t userCallback, void *pUserContext, IotTaskPoolJobStorage_t *const pJobStorage, IotTaskPoolJob_t *const pJob)
Creates a job for the task pool around a user-provided storage.
Definition: iot_taskpool.c:281
IotTaskPoolInfo_t::minThreads
uint32_t minThreads
Specifies the operating parameters for a task pool.
Definition: iot_taskpool_types.h:284
IotTaskPoolError_t
IotTaskPoolError_t
Return codes of task pool functions.
Definition: iot_taskpool_types.h:50
IotTaskPool_Schedule
IotTaskPoolError_t IotTaskPool_Schedule(IotTaskPool_t taskPool, IotTaskPoolJob_t job, uint32_t flags)
This function schedules a job created with IotTaskPool_CreateJob or IotTaskPool_CreateRecyclableJob a...
Definition: iot_taskpool.c:414
IotTaskPoolJob_t
struct _taskPoolJob * IotTaskPoolJob_t
Opaque handle of a Task Pool Job.
Definition: iot_taskpool_types.h:246
IotTaskPool_Destroy
IotTaskPoolError_t IotTaskPool_Destroy(IotTaskPool_t taskPool)
Destroys a task pool instance and collects all memory associated with a task pool and its satellite d...