diff options
author | Lennart Poettering <lennart@poettering.net> | 2013-11-11 19:34:13 +0100 |
---|---|---|
committer | Lennart Poettering <lennart@poettering.net> | 2013-11-12 00:12:43 +0100 |
commit | afc6adb5ec7e73bc13156c43f52fb015cd80cc68 (patch) | |
tree | 999c8810a856d98826900c81c6bfb42fe4dc0ee7 /src/libsystemd-bus/sd-event.c | |
parent | d5e4ec5b1ee1e3f04a2cb0871490490eb47ef34a (diff) |
bus: introduce concept of a "default" event loop per-thread and make use of it everywhere
Try to emphasize a bit that there should be a mapping between event
loops and threads, hence introduce a logic that there's one "default"
event loop for each thread, that can be queried via
"sd_event_default()".
Diffstat (limited to 'src/libsystemd-bus/sd-event.c')
-rw-r--r-- | src/libsystemd-bus/sd-event.c | 44 |
1 files changed, 43 insertions, 1 deletions
diff --git a/src/libsystemd-bus/sd-event.c b/src/libsystemd-bus/sd-event.c index 97e6db289b..8025d24bb7 100644 --- a/src/libsystemd-bus/sd-event.c +++ b/src/libsystemd-bus/sd-event.c @@ -23,12 +23,13 @@ #include <sys/timerfd.h> #include <sys/wait.h> +#include "sd-id128.h" #include "macro.h" #include "prioq.h" #include "hashmap.h" #include "util.h" #include "time-util.h" -#include "sd-id128.h" +#include "missing.h" #include "sd-event.h" @@ -138,6 +139,9 @@ struct sd_event { bool quit_requested:1; bool need_process_child:1; + + pid_t tid; + sd_event **default_event_ptr; }; static int pending_prioq_compare(const void *a, const void *b) { @@ -304,6 +308,9 @@ static int quit_prioq_compare(const void *a, const void *b) { static void event_free(sd_event *e) { assert(e); + if (e->default_event_ptr) + *(e->default_event_ptr) = NULL; + if (e->epoll_fd >= 0) close_nointr_nofail(e->epoll_fd); @@ -1869,3 +1876,38 @@ _public_ int sd_event_get_now_monotonic(sd_event *e, uint64_t *usec) { *usec = e->timestamp.monotonic; return 0; } + +_public_ int sd_event_default(sd_event **ret) { + + static __thread sd_event *default_event = NULL; + sd_event *e; + int r; + + if (!ret) + return !!default_event; + + if (default_event) { + *ret = sd_event_ref(default_event); + return 0; + } + + r = sd_event_new(&e); + if (r < 0) + return r; + + e->default_event_ptr = &default_event; + e->tid = gettid(); + default_event = e; + + *ret = e; + return 1; +} + +_public_ int sd_event_get_tid(sd_event *e, pid_t *tid) { + assert_return(e, -EINVAL); + assert_return(tid, -EINVAL); + assert_return(e->tid != 0, -ENXIO); + + *tid = e->tid; + return 0; +} |