Task Pool API Reference
Task pool library
iot_taskpool.h
Go to the documentation of this file.
1 /*
2  * Amazon FreeRTOS Common V1.0.0
3  * Copyright (C) 2018 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  * http://aws.amazon.com/freertos
23  * http://www.FreeRTOS.org
24  */
25 
31 #ifndef IOT_TASKPOOL_H_
32 #define IOT_TASKPOOL_H_
33 
34 /* The config header is always included first. */
35 #include "iot_config.h"
36 
37 /* Standard includes. */
38 #include <stdbool.h>
39 #include <stdint.h>
40 #include <stddef.h>
41 
42 /* Task pool types. */
44 
45 /*------------------------- Task Pool library functions --------------------------*/
46 
108 /* @[declare_taskpool_createsystemtaskpool] */
110 /* @[declare_taskpool_createsystemtaskpool] */
111 
125 /* @[declare_taskpool_getsystemtaskpool] */
127 /* @[declare_taskpool_getsystemtaskpool] */
128 
151 /* @[declare_taskpool_create] */
153  IotTaskPool_t * const pTaskPool );
154 /* @[declare_taskpool_create] */
155 
174 /* @[declare_taskpool_destroy] */
176 /* @[declare_taskpool_destroy] */
177 
197 /* @[declare_taskpool_setmaxthreads] */
199  uint32_t maxThreads );
200 /* @[declare_taskpool_setmaxthreads] */
201 
220 /* @[declare_taskpool_createjob] */
222  void * pUserContext,
223  IotTaskPoolJobStorage_t * const pJobStorage,
224  IotTaskPoolJob_t * const pJob );
225 /* @[declare_taskpool_createjob] */
226 
249 /* @[declare_taskpool_createrecyclablejob] */
251  IotTaskPoolRoutine_t userCallback,
252  void * pUserContext,
253  IotTaskPoolJob_t * const pJob );
254 /* @[declare_taskpool_createrecyclablejob] */
255 
282 /* @[declare_taskpool_destroyrecyclablejob] */
284  IotTaskPoolJob_t job );
285 /* @[declare_taskpool_destroyrecyclablejob] */
286 
317 /* @[declare_taskpool_recyclejob] */
319  IotTaskPoolJob_t job );
320 /* @[declare_taskpool_recyclejob] */
321 
408 /* @[declare_taskpool_schedule] */
410  IotTaskPoolJob_t job,
411  uint32_t flags );
412 /* @[declare_taskpool_schedule] */
413 
439 /* @[declare_taskpool_scheduledeferred] */
441  IotTaskPoolJob_t job,
442  uint32_t timeMs );
443 /* @[declare_taskpool_scheduledeferred] */
444 
461 /* @[declare_taskpool_getstatus] */
463  IotTaskPoolJob_t job,
464  IotTaskPoolJobStatus_t * const pStatus );
465 /* @[declare_taskpool_getstatus] */
466 
490 /* @[declare_taskpool_trycancel] */
492  IotTaskPoolJob_t job,
493  IotTaskPoolJobStatus_t * const pStatus );
494 /* @[declare_taskpool_trycancel] */
495 
507 /* @[declare_taskpool_getjobstoragefromhandle] */
509 /* @[declare_taskpool_getjobstoragefromhandle] */
510 
528 /* @[declare_taskpool_strerror] */
529 const char * IotTaskPool_strerror( IotTaskPoolError_t status );
530 /* @[declare_taskpool_strerror] */
531 
536 #ifndef IOT_TASKPOOLS
537 #define IOT_TASKPOOLS ( 4 )
538 #endif
539 
543 #ifndef IOT_TASKPOOL_JOBS_RECYCLE_LIMIT
544  #define IOT_TASKPOOL_JOBS_RECYCLE_LIMIT ( 8UL )
545 #endif
546 
552 #ifndef IOT_TASKPOOL_JOB_WAIT_TIMEOUT_MS
553  #define IOT_TASKPOOL_JOB_WAIT_TIMEOUT_MS ( 60 * 1000UL )
554 #endif
555 
556 #endif /* ifndef IOT_TASKPOOL_H_ */
IotTaskPoolRoutine_t
void(* IotTaskPoolRoutine_t)(IotTaskPool_t pTaskPool, IotTaskPoolJob_t pJob, void *pUserContext)
Callback type for a user callback.
Definition: iot_taskpool_types.h:259
IotTaskPool_GetJobStorageFromHandle
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....
Definition: iot_taskpool.c:582
IotTaskPool_strerror
const char * IotTaskPool_strerror(IotTaskPoolError_t status)
Returns a string that describes an IotTaskPoolError_t.
Definition: iot_taskpool.c:589
IotTaskPool_TryCancel
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:550
IotTaskPool_t
struct _taskPool * IotTaskPool_t
Opaque handle of a Task Pool instance.
Definition: iot_taskpool_types.h:213
IotTaskPool_RecycleJob
IotTaskPoolError_t IotTaskPool_RecycleJob(IotTaskPool_t taskPool, IotTaskPoolJob_t job)
Recycles a job into the task pool job cache.
Definition: iot_taskpool.c:381
iot_taskpool_types.h
Types of the task pool.
IotTaskPoolJobStatus_t
IotTaskPoolJobStatus_t
Status codes of task pool Job.
Definition: iot_taskpool_types.h:156
IotTaskPool_GetStatus
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:520
IotTaskPool_DestroyRecyclableJob
IotTaskPoolError_t IotTaskPool_DestroyRecyclableJob(IotTaskPool_t taskPool, IotTaskPoolJob_t job)
This function un-initializes a job.
Definition: iot_taskpool.c:351
IotTaskPoolInfo_t
Initialization information to create one task pool instance.
Definition: iot_taskpool_types.h:273
IotTaskPool_CreateSystemTaskPool
IotTaskPoolError_t IotTaskPool_CreateSystemTaskPool(const IotTaskPoolInfo_t *const pInfo)
Creates the one single instance of the system task pool.
Definition: iot_taskpool.c:255
IotTaskPool_GetSystemTaskPool
IotTaskPool_t IotTaskPool_GetSystemTaskPool(void)
Retrieves the one and only instance of a system task pool.
IotTaskPool_Create
IotTaskPoolError_t IotTaskPool_Create(const IotTaskPoolInfo_t *const pInfo, IotTaskPool_t *const pTaskPool)
Creates one instance of a task pool.
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
IotTaskPool_CreateRecyclableJob
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:303
IotTaskPoolJobStorage_t
The job storage data structure provides the storage for a statically allocated Task Pool Job instance...
Definition: iot_taskpool_types.h:223
IotTaskPool_SetMaxThreads
IotTaskPoolError_t IotTaskPool_SetMaxThreads(IotTaskPool_t taskPool, uint32_t maxThreads)
Sets the maximum number of threads for one instance of a task pool.
IotTaskPoolError_t
IotTaskPoolError_t
Return codes of task pool functions.
Definition: iot_taskpool_types.h:50
IotTaskPool_ScheduleDeferred
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:451
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...