-
-/**
- * Adds the events waiter/dispatcher to the list of events waiters/dispatchers
- * to monitor.
- * @param key A key to register the events waiter/dispatcher (see
- * 'jobs_del_events')
- * @param timeout Timeout in second of the function or 0 if none
- * @param events The callback, the first argument is 0 for normal
- * flow or the signal number when normal flow failed
- * @param closure The closure to give to the callback as secondd argument
- * @return 0 in case of success or -1 in case of error
- */
-int jobs_add_events(void *key, int timeout, void (*events)(int signum, void*), void *closure)
-{
- struct job *job;
-
- pthread_mutex_lock(&mutex);
-
- /* look at an already existsing events for same key */
- job = events_of_key(key);
- if (job) {
- pthread_mutex_unlock(&mutex);
- ERROR("events of key %p already exist", key);
- errno = EEXIST;
- return -1;
- }
-
- /* creates the job */
- job = job_create(key, timeout, (job_cb_t)events, closure, NULL, NULL);
- if (!job) {
- pthread_mutex_unlock(&mutex);
- ERROR("Can't create events, out of memory");
- errno = ENOMEM;
- return -1;
- }
-
- /* adds the loop */
- job->next = first_events;
- first_events = job;
-
- /* signal the loop */
- if (waiting)
- pthread_cond_signal(&cond);
- pthread_mutex_unlock(&mutex);
- return 0;
-}
-
-/**
- * Removes the events of 'key'
- * @param key The key of the events to remove
- * @return 0 in case of success or -1 in case of error
- */
-int jobs_del_events(void *key)
-{
- struct job *job;
-
- pthread_mutex_lock(&mutex);
- job = events_of_key(key);
- if (job)
- if (job->blocked)
- job->dropped = 1;
- else
- events_release(job);
- pthread_mutex_unlock(&mutex);
- if (!job) {
- ERROR("events of key %p not found", key);
- errno = ENOENT;
- }
- return -!job;
-}
-
-/**
- * Adds the current thread to the pool of threads
- * processing the jobs. Returns normally when the threads are
- * terminated or immediately with an error if the thread is
- * already in the pool.
- * @return 0 in case of success or -1 in case of error
- */
-int jobs_add_me()
-{
- struct thread me;
-
- /* check whether already running */
- if (current) {
- ERROR("thread already running");
- errno = EINVAL;
- return -1;
- }
-
- /* allowed... */
- pthread_mutex_lock(&mutex);
- allowed++;
- thread_run(&me);
- allowed--;
- pthread_mutex_unlock(&mutex);
- return 0;
-}
-
-