]> git.sur5r.net Git - freertos/blob - FreeRTOS-Plus/Source/FreeRTOS-IoT-Libraries/c_sdk/standard/common/include/iot_taskpool.h
Correct an err in queue.c introduced when previously updating behaviour when queue...
[freertos] / FreeRTOS-Plus / Source / FreeRTOS-IoT-Libraries / c_sdk / standard / common / include / iot_taskpool.h
1 /*\r
2  * Amazon FreeRTOS Common V1.0.0\r
3  * Copyright (C) 2018 Amazon.com, Inc. or its affiliates.  All Rights Reserved.\r
4  *\r
5  * Permission is hereby granted, free of charge, to any person obtaining a copy of\r
6  * this software and associated documentation files (the "Software"), to deal in\r
7  * the Software without restriction, including without limitation the rights to\r
8  * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of\r
9  * the Software, and to permit persons to whom the Software is furnished to do so,\r
10  * subject to the following conditions:\r
11  *\r
12  * The above copyright notice and this permission notice shall be included in all\r
13  * copies or substantial portions of the Software.\r
14  *\r
15  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\r
16  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS\r
17  * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR\r
18  * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER\r
19  * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN\r
20  * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.\r
21  *\r
22  * http://aws.amazon.com/freertos\r
23  * http://www.FreeRTOS.org\r
24  */\r
25 \r
26 /**\r
27  * @file iot_taskpool.h\r
28  * @brief User-facing functions of the task pool library.\r
29  */\r
30 \r
31 #ifndef IOT_TASKPOOL_H_\r
32 #define IOT_TASKPOOL_H_\r
33 \r
34 /* The config header is always included first. */\r
35 #include "iot_config.h"\r
36 \r
37 /* Standard includes. */\r
38 #include <stdbool.h>\r
39 #include <stdint.h>\r
40 #include <stddef.h>\r
41 \r
42 /* Task pool types. */\r
43 #include "types/iot_taskpool_types.h"\r
44 \r
45 /*------------------------- Task Pool library functions --------------------------*/\r
46 \r
47 /**\r
48  * @functionspage{taskpool,task pool library}\r
49  * - @functionname{taskpool_function_createsystemtaskpool}\r
50  * - @functionname{taskpool_function_getsystemtaskpool}\r
51  * - @functionname{taskpool_function_create}\r
52  * - @functionname{taskpool_function_destroy}\r
53  * - @functionname{taskpool_function_setmaxthreads}\r
54  * - @functionname{taskpool_function_createjob}\r
55  * - @functionname{taskpool_function_createrecyclablejob}\r
56  * - @functionname{taskpool_function_destroyrecyclablejob}\r
57  * - @functionname{taskpool_function_recyclejob}\r
58  * - @functionname{taskpool_function_schedule}\r
59  * - @functionname{taskpool_function_scheduledeferred}\r
60  * - @functionname{taskpool_function_getstatus}\r
61  * - @functionname{taskpool_function_trycancel}\r
62  * - @functionname{taskpool_function_getjobstoragefromhandle}\r
63  * - @functionname{taskpool_function_strerror}\r
64  */\r
65 \r
66 /**\r
67  * @functionpage{IotTaskPool_CreateSystemTaskPool,taskpool,createsystemtaskpool}\r
68  * @functionpage{IotTaskPool_GetSystemTaskPool,taskpool,getsystemtaskpool}\r
69  * @functionpage{IotTaskPool_Create,taskpool,create}\r
70  * @functionpage{IotTaskPool_Destroy,taskpool,destroy}\r
71  * @functionpage{IotTaskPool_SetMaxThreads,taskpool,setmaxthreads}\r
72  * @functionpage{IotTaskPool_CreateJob,taskpool,createjob}\r
73  * @functionpage{IotTaskPool_CreateRecyclableJob,taskpool,createrecyclablejob}\r
74  * @functionpage{IotTaskPool_DestroyRecyclableJob,taskpool,destroyrecyclablejob}\r
75  * @functionpage{IotTaskPool_RecycleJob,taskpool,recyclejob}\r
76  * @functionpage{IotTaskPool_Schedule,taskpool,schedule}\r
77  * @functionpage{IotTaskPool_ScheduleDeferred,taskpool,scheduledeferred}\r
78  * @functionpage{IotTaskPool_GetStatus,taskpool,getstatus}\r
79  * @functionpage{IotTaskPool_TryCancel,taskpool,trycancel}\r
80  * @functionpage{IotTaskPool_GetJobStorageFromHandle,taskpool,getjobstoragefromhandle}\r
81  * @functionpage{IotTaskPool_strerror,taskpool,strerror}\r
82  */\r
83 \r
84 /**\r
85  * @brief Creates the one single instance of the system task pool.\r
86  *\r
87  * This function should be called once by the application to initialize the one single instance of the system task pool.\r
88  * An application should initialize the system task pool early in the boot sequence, before initializing any other library\r
89  * and before posting any jobs. Early initialization it typically easy to accomplish by creating the system task pool\r
90  * before starting the scheduler.\r
91  *\r
92  * This function does not allocate memory to hold the task pool data structures and state, but it\r
93  * may allocate memory to hold the dependent entities and data structures, e.g. the threads of the task\r
94  * pool. The system task pool handle is recoverable for later use by calling @ref IotTaskPool_GetSystemTaskPool or\r
95  * the shortcut @ref IOT_SYSTEM_TASKPOOL.\r
96  *\r
97  * @param[in] pInfo A pointer to the task pool initialization data.\r
98  *\r
99  * @return One of the following:\r
100  * - #IOT_TASKPOOL_SUCCESS\r
101  * - #IOT_TASKPOOL_BAD_PARAMETER\r
102  * - #IOT_TASKPOOL_NO_MEMORY\r
103  *\r
104  * @warning This function should be called only once. Calling this function more that once will result in\r
105  * undefined behavior.\r
106  *\r
107  */\r
108 /* @[declare_taskpool_createsystemtaskpool] */\r
109 IotTaskPoolError_t IotTaskPool_CreateSystemTaskPool( const IotTaskPoolInfo_t * const pInfo );\r
110 /* @[declare_taskpool_createsystemtaskpool] */\r
111 \r
112 /**\r
113  * @brief Retrieves the one and only instance of a system task pool\r
114  *\r
115  * This function retrieves the system task pool created with @ref IotTaskPool_CreateSystemTaskPool, and it is functionally\r
116  * equivalent to using the shortcut @ref IOT_SYSTEM_TASKPOOL.\r
117  *\r
118  * @return The system task pool handle.\r
119  *\r
120  * @warning This function should be called after creating the system task pool with @ref IotTaskPool_CreateSystemTaskPool.\r
121  * Calling this function before creating the system task pool may return a pointer to an uninitialized task pool, NULL, or otherwise\r
122  * fail with undefined behaviour.\r
123  *\r
124  */\r
125 /* @[declare_taskpool_getsystemtaskpool] */\r
126 IotTaskPool_t IotTaskPool_GetSystemTaskPool( void );\r
127 /* @[declare_taskpool_getsystemtaskpool] */\r
128 \r
129 /**\r
130  * @brief Creates one instance of a task pool.\r
131  *\r
132  * This function should be called by the user to initialize one instance of a task\r
133  * pool. The task pool instance will be created around the storage pointed to by the `pTaskPool`\r
134  * parameter. This function will create the minimum number of threads requested by the user\r
135  * through an instance of the #IotTaskPoolInfo_t type specified with the `pInfo` parameter.\r
136  * This function does not allocate memory to hold the task pool data structures and state, but it\r
137  * may allocates memory to hold the dependent data structures, e.g. the threads of the task\r
138  * pool.\r
139  *\r
140  * @param[in] pInfo A pointer to the task pool initialization data.\r
141  * @param[out] pTaskPool A pointer to the task pool handle to be used after initialization.\r
142  * The pointer `pTaskPool` will hold a valid handle only if (@ref IotTaskPool_Create)\r
143  * completes successfully.\r
144  *\r
145  * @return One of the following:\r
146  * - #IOT_TASKPOOL_SUCCESS\r
147  * - #IOT_TASKPOOL_BAD_PARAMETER\r
148  * - #IOT_TASKPOOL_NO_MEMORY\r
149  *\r
150  */\r
151 /* @[declare_taskpool_create] */\r
152 IotTaskPoolError_t IotTaskPool_Create( const IotTaskPoolInfo_t * const pInfo,\r
153                                        IotTaskPool_t * const pTaskPool );\r
154 /* @[declare_taskpool_create] */\r
155 \r
156 /**\r
157  * @brief Destroys a task pool instance and collects all memory associated with a task pool and its\r
158  * satellite data structures.\r
159  *\r
160  * This function should be called to destroy one instance of a task pool previously created with a call\r
161  * to @ref IotTaskPool_Create or @ref IotTaskPool_CreateSystemTaskPool.\r
162  * Calling this fuction release all underlying resources. After calling this function, any job scheduled but not yet executed\r
163  * will be canceled and destroyed.\r
164  * The `taskPool` instance will no longer be valid after this function returns.\r
165  *\r
166  * @param[in] taskPool A handle to the task pool, e.g. as returned by a call to @ref IotTaskPool_Create or\r
167  * @ref IotTaskPool_CreateSystemTaskPool. The `taskPool` instance will no longer be valid after this function returns.\r
168  *\r
169  * @return One of the following:\r
170  * - #IOT_TASKPOOL_SUCCESS\r
171  * - #IOT_TASKPOOL_BAD_PARAMETER\r
172  *\r
173  */\r
174 /* @[declare_taskpool_destroy] */\r
175 IotTaskPoolError_t IotTaskPool_Destroy( IotTaskPool_t taskPool );\r
176 /* @[declare_taskpool_destroy] */\r
177 \r
178 /**\r
179  * @brief Sets the maximum number of threads for one instance of a task pool.\r
180  *\r
181  * This function sets the maximum number of threads for the task pool\r
182  * pointed to by `taskPool`.\r
183  *\r
184  * If the number of currently active threads in the task pool is greater than `maxThreads`, this\r
185  * function causes the task pool to shrink the number of active threads.\r
186  *\r
187  * @param[in] taskPool A handle to the task pool that must have been previously initialized with\r
188  * a call to @ref IotTaskPool_Create or @ref IotTaskPool_CreateSystemTaskPool.\r
189  * @param[in] maxThreads The maximum number of threads for the task pool.\r
190  *\r
191  * @return One of the following:\r
192  * - #IOT_TASKPOOL_SUCCESS\r
193  * - #IOT_TASKPOOL_BAD_PARAMETER\r
194  * - #IOT_TASKPOOL_SHUTDOWN_IN_PROGRESS\r
195  *\r
196  */\r
197 /* @[declare_taskpool_setmaxthreads] */\r
198 IotTaskPoolError_t IotTaskPool_SetMaxThreads( IotTaskPool_t taskPool,\r
199                                               uint32_t maxThreads );\r
200 /* @[declare_taskpool_setmaxthreads] */\r
201 \r
202 /**\r
203  * @brief Creates a job for the task pool around a user-provided storage.\r
204  *\r
205  * This function may allocate memory to hold the state for a job.\r
206  *\r
207  * @param[in] userCallback A user-specified callback for the job.\r
208  * @param[in] pUserContext A user-specified context for the callback.\r
209  * @param[in] pJobStorage The storage for the job data structure.\r
210  * @param[out] pJob A pointer to an instance of @ref IotTaskPoolJob_t that will be initialized when this\r
211  * function returns successfully. This handle can be used to inspect the job status with\r
212  * @ref IotTaskPool_GetStatus or cancel the job with @ref IotTaskPool_TryCancel, etc....\r
213  *\r
214  * @return One of the following:\r
215  * - #IOT_TASKPOOL_SUCCESS\r
216  * - #IOT_TASKPOOL_BAD_PARAMETER\r
217  *\r
218  *\r
219  */\r
220 /* @[declare_taskpool_createjob] */\r
221 IotTaskPoolError_t IotTaskPool_CreateJob( IotTaskPoolRoutine_t userCallback,\r
222                                           void * pUserContext,\r
223                                           IotTaskPoolJobStorage_t * const pJobStorage,\r
224                                           IotTaskPoolJob_t * const pJob );\r
225 /* @[declare_taskpool_createjob] */\r
226 \r
227 /**\r
228  * brief Creates a job for the task pool by allocating the job dynamically.\r
229  *\r
230  * A recyclable job does not need to be allocated twice, but it can rather be reused through\r
231  * subsequent calls to @ref IotTaskPool_CreateRecyclableJob.\r
232  *\r
233  * @param[in] taskPool A handle to the task pool for which to create a recyclable job.\r
234  * @param[in] userCallback A user-specified callback for the job.\r
235  * @param[in] pUserContext A user-specified context for the callback.\r
236  * @param[out] pJob A pointer to an instance of @ref IotTaskPoolJob_t that will be initialized when this\r
237  * function returns successfully. This handle can be used to inspect the job status with\r
238  * @ref IotTaskPool_GetStatus or cancel the job with @ref IotTaskPool_TryCancel, etc....\r
239  *\r
240  * @return One of the following:\r
241  * - #IOT_TASKPOOL_SUCCESS\r
242  * - #IOT_TASKPOOL_BAD_PARAMETER\r
243  * - #IOT_TASKPOOL_NO_MEMORY\r
244  * - #IOT_TASKPOOL_SHUTDOWN_IN_PROGRESS\r
245  *\r
246  * @note This function will not allocate memory. //_RB_ Incorrect comment.\r
247  *\r
248  * @warning A recyclable job should be recycled with a call to @ref IotTaskPool_RecycleJob rather than destroyed.\r
249  *\r
250  */\r
251 /* @[declare_taskpool_createrecyclablejob] */\r
252 IotTaskPoolError_t IotTaskPool_CreateRecyclableJob( IotTaskPool_t taskPool,\r
253                                                     IotTaskPoolRoutine_t userCallback,\r
254                                                     void * pUserContext,\r
255                                                     IotTaskPoolJob_t * const pJob );\r
256 /* @[declare_taskpool_createrecyclablejob] */\r
257 \r
258 /**\r
259  * @brief This function un-initializes a job.\r
260  *\r
261  * This function will destroy a job created with @ref IotTaskPool_CreateRecyclableJob.\r
262  * A job should not be destroyed twice. A job that was previously scheduled but has not completed yet should not be destroyed,\r
263  * but rather the application should attempt to cancel it first by calling @ref IotTaskPool_TryCancel.\r
264  * An attempt to destroy a job that was scheduled but not yet executed or canceled, may result in a\r
265  * @ref IOT_TASKPOOL_ILLEGAL_OPERATION error.\r
266  *\r
267  * @param[in] taskPool A handle to the task pool, e.g. as returned by a call to @ref IotTaskPool_Create or @ref IotTaskPool_CreateSystemTaskPool.\r
268  * @param[in] job A handle to a job that was create with a call to @ref IotTaskPool_CreateJob.\r
269  *\r
270  * @return One of the following:\r
271  * - #IOT_TASKPOOL_SUCCESS\r
272  * - #IOT_TASKPOOL_BAD_PARAMETER\r
273  * - #IOT_TASKPOOL_ILLEGAL_OPERATION\r
274  * - #IOT_TASKPOOL_SHUTDOWN_IN_PROGRESS\r
275  *\r
276  * @warning The task pool will try and prevent destroying jobs that are currently queued for execution, but does\r
277  * not enforce strict ordering of operations. It is up to the user to make sure @ref IotTaskPool_DestroyRecyclableJob is not called\r
278  * our of order.\r
279  *\r
280  * @warning Calling this function on job that was not previously created with @ref IotTaskPool_CreateRecyclableJob\r
281  * will result in a @ref IOT_TASKPOOL_ILLEGAL_OPERATION error.\r
282  *\r
283  */\r
284 /* @[declare_taskpool_destroyrecyclablejob] */\r
285 IotTaskPoolError_t IotTaskPool_DestroyRecyclableJob( IotTaskPool_t taskPool,\r
286                                                      IotTaskPoolJob_t job );\r
287 /* @[declare_taskpool_destroyrecyclablejob] */\r
288 \r
289 /**\r
290  * @brief Recycles a job into the task pool job cache.\r
291  *\r
292  * This function will try and recycle the job into the task pool cache. If the cache is full,\r
293  * the job memory is destroyed as if the user called @ref IotTaskPool_DestroyRecyclableJob. The job should be recycled into\r
294  * the task pool instance from where it was allocated.\r
295  * Failure to do so will yield undefined results. A job should not be recycled twice. A job\r
296  * that was previously scheduled but not completed or canceled cannot be safely recycled. An attempt to do so will result\r
297  * in an @ref IOT_TASKPOOL_ILLEGAL_OPERATION error.\r
298  *\r
299  * @param[in] taskPool A handle to the task pool, e.g. as returned by a call to @ref IotTaskPool_Create.\r
300  * @param[out] job A pointer to a job that was create with a call to @ref IotTaskPool_CreateJob.\r
301  *\r
302  * @return One of the following:\r
303  * - #IOT_TASKPOOL_SUCCESS\r
304  * - #IOT_TASKPOOL_BAD_PARAMETER\r
305  * - #IOT_TASKPOOL_ILLEGAL_OPERATION\r
306  * - #IOT_TASKPOOL_SHUTDOWN_IN_PROGRESS\r
307  *\r
308  * @warning The `taskPool` used in this function should be the same\r
309  * used to create the job pointed to by `job`, or the results will be undefined.\r
310  *\r
311  * @warning Attempting to call this function on a statically allocated job will result in @ref IOT_TASKPOOL_ILLEGAL_OPERATION\r
312  * error.\r
313  *\r
314  * @warning This function should be used to recycle a job in the task pool cache when after the job executed.\r
315  * Failing to call either this function or @ref IotTaskPool_DestroyRecyclableJob will result is a memory leak. Statically\r
316  * allocated jobs do not need to be recycled or destroyed.\r
317  *\r
318  */\r
319 /* @[declare_taskpool_recyclejob] */\r
320 IotTaskPoolError_t IotTaskPool_RecycleJob( IotTaskPool_t taskPool,\r
321                                            IotTaskPoolJob_t job );\r
322 /* @[declare_taskpool_recyclejob] */\r
323 \r
324 /**\r
325  * @brief This function schedules a job created with @ref IotTaskPool_CreateJob or @ref IotTaskPool_CreateRecyclableJob\r
326  * against the task pool pointed to by `taskPool`.\r
327  *\r
328  * See @ref taskpool_design for a description of the jobs lifetime and interaction with the threads used in the task pool\r
329  * library.\r
330  *\r
331  * @param[in] taskPool A handle to the task pool that must have been previously initialized with.\r
332  * a call to @ref IotTaskPool_Create.\r
333  * @param[in] job A job to schedule for execution. This must be first initialized with a call to @ref IotTaskPool_CreateJob.\r
334  * @param[in] flags Flags to be passed by the user, e.g. to identify the job as high priority by specifying #IOT_TASKPOOL_JOB_HIGH_PRIORITY.\r
335  *\r
336  * @return One of the following:\r
337  * - #IOT_TASKPOOL_SUCCESS\r
338  * - #IOT_TASKPOOL_BAD_PARAMETER\r
339  * - #IOT_TASKPOOL_ILLEGAL_OPERATION\r
340  * - #IOT_TASKPOOL_NO_MEMORY\r
341  * - #IOT_TASKPOOL_SHUTDOWN_IN_PROGRESS\r
342  *\r
343  *\r
344  * @note This function will not allocate memory, so it is guaranteed to succeed if the paramters are correct and the task pool\r
345  * was correctly initialized, and not yet destroyed.\r
346  *\r
347  * @warning The `taskPool` used in this function should be the same used to create the job pointed to by `job`, or the\r
348  * results will be undefined.\r
349  *\r
350  * <b>Example</b>\r
351  * @code{c}\r
352  * // An example of a user context to pass to a callback through a task pool thread.\r
353  * typedef struct JobUserContext\r
354  * {\r
355  *     uint32_t counter;\r
356  * } JobUserContext_t;\r
357  *\r
358  * // An example of a user callback to invoke through a task pool thread.\r
359  * static void ExecutionCb( IotTaskPool_t taskPool, IotTaskPoolJob_t job, void * context )\r
360  * {\r
361  *     ( void )taskPool;\r
362  *     ( void )job;\r
363  *\r
364  *     JobUserContext_t * pUserContext = ( JobUserContext_t * )context;\r
365  *\r
366  *     pUserContext->counter++;\r
367  * }\r
368  *\r
369  * void TaskPoolExample( )\r
370  * {\r
371  *     JobUserContext_t userContext = { 0 };\r
372  *     IotTaskPoolJob_t job;\r
373  *     IotTaskPool_t taskPool;\r
374  *\r
375  *     // Configure the task pool to hold at least two threads and three at the maximum.\r
376  *     // Provide proper stack size and priority per the application needs.\r
377  *\r
378  *     const IotTaskPoolInfo_t tpInfo = { .minThreads = 2, .maxThreads = 3, .stackSize = 512, .priority = 0 };\r
379  *\r
380  *     // Create a task pool.\r
381  *     IotTaskPool_Create( &tpInfo, &taskPool );\r
382  *\r
383  *     // Statically allocate one job, schedule it.\r
384  *     IotTaskPool_CreateJob( &ExecutionCb, &userContext, &job );\r
385  *\r
386  *     IotTaskPoolError_t errorSchedule = IotTaskPool_Schedule( taskPool, &job, 0 );\r
387  *\r
388  *     switch ( errorSchedule )\r
389  *     {\r
390  *     case IOT_TASKPOOL_SUCCESS:\r
391  *         break;\r
392  *     case IOT_TASKPOOL_BAD_PARAMETER:          // Invalid parameters, such as a NULL handle, can trigger this error.\r
393  *     case IOT_TASKPOOL_ILLEGAL_OPERATION:      // Scheduling a job that was previously scheduled or destroyed could trigger this error.\r
394  *     case IOT_TASKPOOL_NO_MEMORY:              // Scheduling a with flag #IOT_TASKPOOL_JOB_HIGH_PRIORITY could trigger this error.\r
395  *     case IOT_TASKPOOL_SHUTDOWN_IN_PROGRESS:   // Scheduling a job after trying to destroy the task pool could trigger this error.\r
396  *         // ASSERT\r
397  *         break;\r
398  *     default:\r
399  *         // ASSERT\r
400  *     }\r
401  *\r
402  *     //\r
403  *     // ... Perform other operations ...\r
404  *     //\r
405  *\r
406  *     IotTaskPool_Destroy( taskPool );\r
407  * }\r
408  * @endcode\r
409  */\r
410 /* @[declare_taskpool_schedule] */\r
411 IotTaskPoolError_t IotTaskPool_Schedule( IotTaskPool_t taskPool,\r
412                                          IotTaskPoolJob_t job,\r
413                                          uint32_t flags );\r
414 /* @[declare_taskpool_schedule] */\r
415 \r
416 /**\r
417  * @brief This function schedules a job created with @ref IotTaskPool_CreateJob against the task pool\r
418  * pointed to by `taskPool` to be executed after a user-defined time interval.\r
419  *\r
420  * See @ref taskpool_design for a description of the jobs lifetime and interaction with the threads used in the task pool\r
421  * library.\r
422  *\r
423  * @param[in] taskPool A handle to the task pool that must have been previously initialized with.\r
424  * a call to @ref IotTaskPool_Create.\r
425  * @param[in] job A job to schedule for execution. This must be first initialized with a call to @ref IotTaskPool_CreateJob.\r
426  * @param[in] timeMs The time in milliseconds to wait before scheduling the job.\r
427  *\r
428  * @return One of the following:\r
429  * - #IOT_TASKPOOL_SUCCESS\r
430  * - #IOT_TASKPOOL_BAD_PARAMETER\r
431  * - #IOT_TASKPOOL_ILLEGAL_OPERATION\r
432  * - #IOT_TASKPOOL_SHUTDOWN_IN_PROGRESS\r
433  *\r
434  *\r
435  * @note This function will not allocate memory.\r
436  *\r
437  * @warning The `taskPool` used in this function should be the same\r
438  * used to create the job pointed to by `job`, or the results will be undefined.\r
439  *\r
440  */\r
441 /* @[declare_taskpool_scheduledeferred] */\r
442 IotTaskPoolError_t IotTaskPool_ScheduleDeferred( IotTaskPool_t taskPool,\r
443                                                  IotTaskPoolJob_t job,\r
444                                                  uint32_t timeMs );\r
445 /* @[declare_taskpool_scheduledeferred] */\r
446 \r
447 /**\r
448  * @brief This function retrieves the current status of a job.\r
449  *\r
450  * @param[in] taskPool A handle to the task pool that must have been previously initialized with\r
451  * a call to @ref IotTaskPool_Create or @ref IotTaskPool_CreateSystemTaskPool.\r
452  * @param[in] job The job to cancel.\r
453  * @param[out] pStatus The status of the job at the time of cancellation.\r
454  *\r
455  * @return One of the following:\r
456  * - #IOT_TASKPOOL_SUCCESS\r
457  * - #IOT_TASKPOOL_BAD_PARAMETER\r
458  * - #IOT_TASKPOOL_SHUTDOWN_IN_PROGRESS\r
459  *\r
460  * @warning This function is not thread safe and the job status returned in `pStatus` may be invalid by the time\r
461  * the calling thread has a chance to inspect it.\r
462  */\r
463 /* @[declare_taskpool_getstatus] */\r
464 IotTaskPoolError_t IotTaskPool_GetStatus( IotTaskPool_t taskPool,\r
465                                           IotTaskPoolJob_t job,\r
466                                           IotTaskPoolJobStatus_t * const pStatus );\r
467 /* @[declare_taskpool_getstatus] */\r
468 \r
469 /**\r
470  * @brief This function tries to cancel a job that was previously scheduled with @ref IotTaskPool_Schedule.\r
471  *\r
472  * A job can be canceled only if it is not yet executing, i.e. if its status is\r
473  * @ref IOT_TASKPOOL_STATUS_READY or @ref IOT_TASKPOOL_STATUS_SCHEDULED. Calling\r
474  * @ref IotTaskPool_TryCancel on a job whose status is @ref IOT_TASKPOOL_STATUS_COMPLETED,\r
475  * or #IOT_TASKPOOL_STATUS_CANCELED will yield a #IOT_TASKPOOL_CANCEL_FAILED return result.\r
476  *\r
477  * @param[in] taskPool A handle to the task pool that must have been previously initialized with\r
478  * a call to @ref IotTaskPool_Create.\r
479  * @param[in] job The job to cancel.\r
480  * @param[out] pStatus The status of the job at the time of cancellation.\r
481  *\r
482  * @return One of the following:\r
483  * - #IOT_TASKPOOL_SUCCESS\r
484  * - #IOT_TASKPOOL_BAD_PARAMETER\r
485  * - #IOT_TASKPOOL_SHUTDOWN_IN_PROGRESS\r
486  * - #IOT_TASKPOOL_CANCEL_FAILED\r
487  *\r
488  * @warning The `taskPool` used in this function should be the same\r
489  * used to create the job pointed to by `job`, or the results will be undefined.\r
490  *\r
491  */\r
492 /* @[declare_taskpool_trycancel] */\r
493 IotTaskPoolError_t IotTaskPool_TryCancel( IotTaskPool_t taskPool,\r
494                                           IotTaskPoolJob_t job,\r
495                                           IotTaskPoolJobStatus_t * const pStatus );\r
496 /* @[declare_taskpool_trycancel] */\r
497 \r
498 /**\r
499  * @brief Returns a pointer to the job storage from an instance of a job handle\r
500  * of type @ref IotTaskPoolJob_t. This function is guaranteed to succeed for a\r
501  * valid job handle.\r
502  *\r
503  * @param[in] job The job handle.\r
504  *\r
505  * @return A pointer to the storage associated with the job handle `job`.\r
506  *\r
507  * @warning If the `job` handle used is invalid, the results will be undefined.\r
508  */\r
509 /* @[declare_taskpool_getjobstoragefromhandle] */\r
510 IotTaskPoolJobStorage_t * IotTaskPool_GetJobStorageFromHandle( IotTaskPoolJob_t job );\r
511 /* @[declare_taskpool_getjobstoragefromhandle] */\r
512 \r
513 /**\r
514  * @brief Returns a string that describes an @ref IotTaskPoolError_t.\r
515  *\r
516  * Like the POSIX's `strerror`, this function returns a string describing a\r
517  * return code. In this case, the return code is a task pool library error code,\r
518  * `status`.\r
519  *\r
520  * The string returned by this function <b>MUST</b> be treated as read-only: any\r
521  * attempt to modify its contents may result in a crash. Therefore, this function\r
522  * is limited to usage in logging.\r
523  *\r
524  * @param[in] status The status to describe.\r
525  *\r
526  * @return A read-only string that describes `status`.\r
527  *\r
528  * @warning The string returned by this function must never be modified.\r
529  */\r
530 /* @[declare_taskpool_strerror] */\r
531 const char * IotTaskPool_strerror( IotTaskPoolError_t status );\r
532 /* @[declare_taskpool_strerror] */\r
533 \r
534 /**\r
535  * @brief The maximum number of task pools to be created when using\r
536  * a memory pool.\r
537  */\r
538 #ifndef IOT_TASKPOOLS\r
539 #define IOT_TASKPOOLS                          ( 4 )\r
540 #endif\r
541 \r
542 /**\r
543  * @brief The maximum number of jobs to cache.\r
544  */\r
545 #ifndef IOT_TASKPOOL_JOBS_RECYCLE_LIMIT\r
546     #define IOT_TASKPOOL_JOBS_RECYCLE_LIMIT    ( 8UL )\r
547 #endif\r
548 \r
549 /**\r
550  * @brief The maximum timeout in milliseconds to wait for a job to be scheduled before waking up a worker thread.\r
551  * A worker thread that wakes up as a result of a timeout may exit to allow the task pool to fold back to its\r
552  * minimum number of threads.\r
553  */\r
554 #ifndef IOT_TASKPOOL_JOB_WAIT_TIMEOUT_MS\r
555     #define IOT_TASKPOOL_JOB_WAIT_TIMEOUT_MS    ( 60 * 1000UL )\r
556 #endif\r
557 \r
558 #endif /* ifndef IOT_TASKPOOL_H_ */\r