X-Git-Url: https://gerrit.automotivelinux.org/gerrit/gitweb?a=blobdiff_plain;f=src%2Fjobs.c;h=3d912a54c1307f5c8d7d253a3b151a558a730be1;hb=6797f9722dd3e5463e0f7c118397955bb59a40c7;hp=8ffd6b61468b3b2c5799e565ef19777da30bf24e;hpb=89c44a872117fb8f64d38cbccf8f36776f2623f6;p=src%2Fapp-framework-binder.git diff --git a/src/jobs.c b/src/jobs.c index 8ffd6b61..3d912a54 100644 --- a/src/jobs.c +++ b/src/jobs.c @@ -847,7 +847,10 @@ int jobs_add_me() return 0; } - +/** + * Gets a sd_event item for the current thread. + * @return a sd_event or NULL in case of error + */ struct sd_event *jobs_get_sd_event() { struct events *events; @@ -885,9 +888,10 @@ struct sd_event *jobs_get_sd_event() events = NULL; } } else { - if (!events) + if (!events) { ERROR("out of memory"); - else { + errno = ENOMEM; + } else { free(events); ERROR("creation of sd_event failed: %m"); events = NULL; @@ -911,3 +915,35 @@ struct sd_event *jobs_get_sd_event() return events ? events->event : NULL; } +/** + * Enter the jobs processing loop. + * @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(); +} +