HTL_thread_scheduler_create
Creates a scheduler.
Interface Definition
int HTL_thread_scheduler_create(HTL_thread_scheduler_t *scheduler, HTL_thread_scheduler_param_t *sched_param, HTL_thread_pool_t *thread_pools, int pool_count, HTL_thread_scheduler_config_t sched_config);
Description
HTL_thread_scheduler_create() creates a scheduler defined by the scheduler parameter sched_param and configuration parameter sched_config, and returns the scheduler handle through scheduler.
All non-optional functions must be set for the scheduler parameter sched_param. For details, see HTL_thread_scheduler_param_t.
scheduler is associated with the thread_pools array. The array contains num_pools HTL_thread_pool_t handles. If the i-th element of thread_pools is HTL_THREAD_POOL_NULL, a default FIFO pool with the default pool configuration is created and used as the i-th element.
scheduler can be set through the config parameter. If config is set to HTL_THREAD_POOL_CONFIG_NULL, the default configuration is used. If the scheduler initialization function init() in sched_param is not NULL, config is passed to the init() function as its second parameter. If init() does not return HTL_SUCCESS, HTL_thread_scheduler_create returns the return value of init().
This function copies the contents of sched_param, config, and thread_pools. Users can release def, config, and pools after the function returns a value.
Parameters
Parameter |
Type |
Description |
Input/Output |
|---|---|---|---|
scheduler |
HTL_thread_scheduler_t * |
Address of the handle to the scheduler. |
Output |
sched_param |
HTL_thread_scheduler_param_t * |
Scheduler parameters. |
Input |
thread_pools |
HTL_thread_pool_t * |
Pools associated with this scheduler. |
Input |
pool_count |
int |
Number of pools associated with this scheduler. |
Input |
sched_config |
HTL_thread_scheduler_config_t |
Scheduler configuration used to create a scheduler. |
Input |
Return Value
- HTL_THREAD_SUCCESS: success.
- Other values: failure. For details, see the error code descriptions.
Example
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 | HTL_thread_pool_t *my_pools; HTL_thread_scheduler_param_t sched_def = { .type = HTL_SCHEDULER_TARGET_ULT, .init = sched_init, .run = sched_run, .free = sched_free, .get_migr_pool = NULL }; my_pools = (HTL_thread_pool_t *)malloc(num * sizeof(HTL_thread_pool_t)); for (i = 0; i < num; i++) { for (k = 0; k < num; k++) { my_pools[k] = pools[(i + k) % num]; } HTL_thread_scheduler_create(&sched_def, num, my_pools, HTL_THREAD_POOL_CONFIG_NULL, &scheds[i]); } free(my_pools); |