diff options
author | José Bollo <jose.bollo@iot.bzh> | 2017-03-30 14:22:03 +0200 |
---|---|---|
committer | José Bollo <jose.bollo@iot.bzh> | 2017-03-30 14:24:01 +0200 |
commit | c710a0da4ebcc126275c42a0387ff85b2557e3ae (patch) | |
tree | ef27fc3cb68c93475c37965fbcf0b2f8236370ca /src/jobs.c | |
parent | 89c44a872117fb8f64d38cbccf8f36776f2623f6 (diff) |
Overall integration of job initialisation
Move the job initialisation from main to jobs.
Change-Id: I8f5b54adb62e60592884ff1e3fad9811b5934d47
Signed-off-by: José Bollo <jose.bollo@iot.bzh>
Diffstat (limited to 'src/jobs.c')
-rw-r--r-- | src/jobs.c | 31 |
1 files changed, 31 insertions, 0 deletions
@@ -911,3 +911,34 @@ struct sd_event *jobs_get_sd_event() return events ? events->event : NULL; } +/** + * run the jobs as + * @param allowed_count Maximum count of thread for jobs including this one + * @param start_count Count of thread to start now, must be lower. + * @param waiter_count Maximum count of jobs that can be waiting. + * @param start The start routine to activate (can't be NULL) + * @return 0 in case of success or -1 in case of error. + */ +int jobs_enter(int allowed_count, int start_count, int waiter_count, void (*start)()) +{ + /* start */ + if (sig_monitor_init() < 0) { + ERROR("failed to initialise signal handlers"); + return -1; + } + + /* init job processing */ + if (jobs_init(allowed_count, start_count, waiter_count) < 0) { + ERROR("failed to initialise threading"); + return -1; + } + + /* queue the start job */ + if (jobs_queue0(NULL, 0, (void(*)(int))start) < 0) { + ERROR("failed to start runnning jobs"); + return -1; + } + + /* turn as processing thread */ + return jobs_add_me(); +}; |