2 * Copyright (C) 2016, 2017 "IoT.bzh"
3 * Author José Bollo <jose.bollo@iot.bzh>
5 * Licensed under the Apache License, Version 2.0 (the "License");
6 * you may not use this file except in compliance with the License.
7 * You may obtain a copy of the License at
9 * http://www.apache.org/licenses/LICENSE-2.0
11 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an "AS IS" BASIS,
13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 * See the License for the specific language governing permissions and
15 * limitations under the License.
25 #include <sys/syscall.h>
30 #include <systemd/sd-event.h>
33 #include "sig-monitor.h"
45 void (*callback)(int signum, void* arg);
49 static struct job *first, *last;
50 static pthread_mutex_t mutex = PTHREAD_MUTEX_INITIALIZER;
52 static int add_job(const void *group, int timeout, void (*callback)(int signum, void *closure), void *closure)
65 j->callback = callback;
68 pthread_mutex_lock(&mutex);
74 pthread_mutex_unlock(&mutex);
78 static void *thrrun(void *arg)
82 pthread_mutex_lock(&mutex);
86 pthread_mutex_unlock(&mutex);
88 j->callback(0, j->closure);
97 void (*callback)(int signum, void* arg),
101 int rc = add_job(group, timeout, callback, arg);
103 rc = pthread_create(&tid, NULL, thrrun, NULL);
114 void (*callback)(int signum, void *closure, struct jobloop *jobloop),
120 int jobs_leave(struct jobloop *jobloop)
128 void (*callback)(int, void*),
134 struct sd_event *jobs_get_sd_event()
137 int rc = sd_event_default(&r);
138 return rc < 0 ? NULL : r;
141 void jobs_terminate()
145 int jobs_start(int allowed_count, int start_count, int waiter_count, void (*start)(int signum))