AWS IoT Device SDK C: Task Pool
Task pool library
Return to main page ↑
iot_taskpool.h
Go to the documentation of this file.
1 /*
2  * IoT Common V1.1.0
3  * Copyright (C) 2019 Amazon.com, Inc. or its affiliates. All Rights Reserved.
4  *
5  * Permission is hereby granted, free of charge, to any person obtaining a copy of
6  * this software and associated documentation files (the "Software"), to deal in
7  * the Software without restriction, including without limitation the rights to
8  * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
9  * the Software, and to permit persons to whom the Software is furnished to do so,
10  * subject to the following conditions:
11  *
12  * The above copyright notice and this permission notice shall be included in all
13  * copies or substantial portions of the Software.
14  *
15  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
17  * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
18  * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
19  * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
20  * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
21  */
22 
28 #ifndef IOT_TASKPOOL_H_
29 #define IOT_TASKPOOL_H_
30 
31 /* The config header is always included first. */
32 #include "iot_config.h"
33 
34 /* Standard includes. */
35 #include <stdbool.h>
36 #include <stdint.h>
37 #include <stddef.h>
38 
39 /* Task pool types. */
41 
42 /*------------------------- Task Pool library functions --------------------------*/
43 
106 /* @[declare_taskpool_createsystemtaskpool] */
108 /* @[declare_taskpool_createsystemtaskpool] */
109 
123 /* @[declare_taskpool_getsystemtaskpool] */
125 /* @[declare_taskpool_getsystemtaskpool] */
126 
149 /* @[declare_taskpool_create] */
151  IotTaskPool_t * const pTaskPool );
152 /* @[declare_taskpool_create] */
153 
172 /* @[declare_taskpool_destroy] */
174 /* @[declare_taskpool_destroy] */
175 
195 /* @[declare_taskpool_setmaxthreads] */
197  uint32_t maxThreads );
198 /* @[declare_taskpool_setmaxthreads] */
199 
218 /* @[declare_taskpool_createjob] */
220  void * pUserContext,
221  IotTaskPoolJobStorage_t * const pJobStorage,
222  IotTaskPoolJob_t * const pJob );
223 /* @[declare_taskpool_createjob] */
224 
247 /* @[declare_taskpool_createrecyclablejob] */
249  IotTaskPoolRoutine_t userCallback,
250  void * pUserContext,
251  IotTaskPoolJob_t * const pJob );
252 /* @[declare_taskpool_createrecyclablejob] */
253 
280 /* @[declare_taskpool_destroyrecyclablejob] */
282  IotTaskPoolJob_t job );
283 /* @[declare_taskpool_destroyrecyclablejob] */
284 
315 /* @[declare_taskpool_recyclejob] */
317  IotTaskPoolJob_t job );
318 /* @[declare_taskpool_recyclejob] */
319 
406 /* @[declare_taskpool_schedule] */
408  IotTaskPoolJob_t job,
409  uint32_t flags );
410 /* @[declare_taskpool_schedule] */
411 
437 /* @[declare_taskpool_scheduledeferred] */
439  IotTaskPoolJob_t job,
440  uint32_t timeMs );
441 /* @[declare_taskpool_scheduledeferred] */
442 
459 /* @[declare_taskpool_getstatus] */
461  IotTaskPoolJob_t job,
462  IotTaskPoolJobStatus_t * const pStatus );
463 /* @[declare_taskpool_getstatus] */
464 
488 /* @[declare_taskpool_trycancel] */
490  IotTaskPoolJob_t job,
491  IotTaskPoolJobStatus_t * const pStatus );
492 /* @[declare_taskpool_trycancel] */
493 
505 /* @[declare_taskpool_getjobstoragefromhandle] */
507 /* @[declare_taskpool_getjobstoragefromhandle] */
508 
526 /* @[declare_taskpool_strerror] */
527 const char * IotTaskPool_strerror( IotTaskPoolError_t status );
528 /* @[declare_taskpool_strerror] */
529 
534 #ifndef IOT_TASKPOOLS
535 #define IOT_TASKPOOLS ( 4 )
536 #endif
537 
541 #ifndef IOT_TASKPOOL_JOBS_RECYCLE_LIMIT
542  #define IOT_TASKPOOL_JOBS_RECYCLE_LIMIT ( 8UL )
543 #endif
544 
550 #ifndef IOT_TASKPOOL_JOB_WAIT_TIMEOUT_MS
551  #define IOT_TASKPOOL_JOB_WAIT_TIMEOUT_MS ( 60 * 1000UL )
552 #endif
553 
554 #endif /* ifndef IOT_TASKPOOL_H_ */
const char * IotTaskPool_strerror(IotTaskPoolError_t status)
Returns a string that describes an IotTaskPoolError_t.
Definition: iot_taskpool.c:895
IotTaskPoolJobStorage_t * IotTaskPool_GetJobStorageFromHandle(IotTaskPoolJob_t job)
Returns a pointer to the job storage from an instance of a job handle of type IotTaskPoolJob_t. This function is guaranteed to succeed for a valid job handle.
Definition: iot_taskpool.c:888
Types of the task pool.
IotTaskPoolError_t IotTaskPool_TryCancel(IotTaskPool_t taskPool, IotTaskPoolJob_t job, IotTaskPoolJobStatus_t *const pStatus)
This function tries to cancel a job that was previously scheduled with IotTaskPool_Schedule.
Definition: iot_taskpool.c:851
IotTaskPoolError_t IotTaskPool_RecycleJob(IotTaskPool_t taskPool, IotTaskPoolJob_t job)
Recycles a job into the task pool job cache.
Definition: iot_taskpool.c:644
struct _taskPoolJob * IotTaskPoolJob_t
Opaque handle of a Task Pool Job.
Definition: iot_taskpool_types.h:190
IotTaskPoolError_t IotTaskPool_DestroyRecyclableJob(IotTaskPool_t taskPool, IotTaskPoolJob_t job)
This function un-initializes a job.
Definition: iot_taskpool.c:596
IotTaskPoolJobStatus_t
Status codes of task pool Job.
Definition: iot_taskpool_types.h:98
IotTaskPool_t IotTaskPool_GetSystemTaskPool(void)
Retrieves the one and only instance of a system task pool.
Definition: iot_taskpool.c:267
IotTaskPoolError_t IotTaskPool_GetStatus(IotTaskPool_t taskPool, IotTaskPoolJob_t job, IotTaskPoolJobStatus_t *const pStatus)
This function retrieves the current status of a job.
Definition: iot_taskpool.c:816
IotTaskPoolError_t IotTaskPool_CreateRecyclableJob(IotTaskPool_t taskPool, IotTaskPoolRoutine_t userCallback, void *pUserContext, IotTaskPoolJob_t *const pJob)
Creates a job for the task pool by allocating the job dynamically.
Definition: iot_taskpool.c:546
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:524
struct _taskPool * IotTaskPool_t
Opaque handle of a Task Pool instance.
Definition: iot_taskpool_types.h:156
IotTaskPoolError_t
Return codes of task pool functions.
Definition: iot_taskpool_types.h:50
IotTaskPoolError_t IotTaskPool_SetMaxThreads(IotTaskPool_t taskPool, uint32_t maxThreads)
Sets the maximum number of threads for one instance of a task pool.
Definition: iot_taskpool.c:469
IotTaskPoolError_t IotTaskPool_ScheduleDeferred(IotTaskPool_t taskPool, IotTaskPoolJob_t job, uint32_t timeMs)
This function schedules a job created with IotTaskPool_CreateJob against the task pool pointed to by ...
Definition: iot_taskpool.c:730
The job storage data structure provides the storage for a statically allocated Task Pool Job instance...
Definition: iot_taskpool_types.h:166
Initialization information to create one task pool instance.
Definition: iot_taskpool_types.h:218
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:691
IotTaskPoolError_t IotTaskPool_Create(const IotTaskPoolInfo_t *pInfo, IotTaskPool_t *const pTaskPool)
Creates one instance of a task pool.
Definition: iot_taskpool.c:289
IotTaskPoolError_t IotTaskPool_CreateSystemTaskPool(const IotTaskPoolInfo_t *pInfo)
Creates the one single instance of the system task pool.
Definition: iot_taskpool.c:274
void(* IotTaskPoolRoutine_t)(IotTaskPool_t pTaskPool, IotTaskPoolJob_t pJob, void *pUserContext)
Callback type for a user callback.
Definition: iot_taskpool_types.h:203
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...
Definition: iot_taskpool.c:333