diff options
author | Volker Lendecke <vl@samba.org> | 2017-06-05 06:58:37 +0200 |
---|---|---|
committer | Jeremy Allison <jra@samba.org> | 2017-06-08 20:38:19 +0200 |
commit | 97d912d99afb115e17f683a55aef447dc92ced49 (patch) | |
tree | ef7a5eb82a4d2b22cc2955ad7f7c724498052b24 | |
parent | b03475048a49db78422d1bfc11f2c69d56fbf87f (diff) | |
download | samba-97d912d99afb115e17f683a55aef447dc92ced49.tar.gz |
tevent: Factor out context initialization
Signed-off-by: Volker Lendecke <vl@samba.org>
Reviewed-by: Jeremy Allison <jra@samba.org>
-rw-r--r-- | lib/tevent/tevent.c | 59 |
1 files changed, 34 insertions, 25 deletions
diff --git a/lib/tevent/tevent.c b/lib/tevent/tevent.c index 65b101f28e5..68b9db605f3 100644 --- a/lib/tevent/tevent.c +++ b/lib/tevent/tevent.c @@ -392,46 +392,26 @@ int tevent_common_context_destructor(struct tevent_context *ev) return 0; } -/* - create a event_context structure for a specific implemementation. - This must be the first events call, and all subsequent calls pass - this event_context as the first element. Event handlers also - receive this as their first argument. - - This function is for allowing third-party-applications to hook in gluecode - to their own event loop code, so that they can make async usage of our client libs - - NOTE: use tevent_context_init() inside of samba! -*/ -struct tevent_context *tevent_context_init_ops(TALLOC_CTX *mem_ctx, - const struct tevent_ops *ops, - void *additional_data) +static int tevent_common_context_constructor(struct tevent_context *ev) { - struct tevent_context *ev; int ret; - ev = talloc_zero(mem_ctx, struct tevent_context); - if (!ev) return NULL; - #ifdef HAVE_PTHREAD ret = pthread_once(&tevent_atfork_initialized, tevent_prep_atfork); if (ret != 0) { - talloc_free(ev); - return NULL; + return ret; } ret = pthread_mutex_init(&ev->scheduled_mutex, NULL); if (ret != 0) { - talloc_free(ev); - return NULL; + return ret; } ret = pthread_mutex_lock(&tevent_contexts_mutex); if (ret != 0) { pthread_mutex_destroy(&ev->scheduled_mutex); - talloc_free(ev); - return NULL; + return ret; } DLIST_ADD(tevent_contexts, ev); @@ -440,11 +420,40 @@ struct tevent_context *tevent_context_init_ops(TALLOC_CTX *mem_ctx, if (ret != 0) { abort(); } - #endif talloc_set_destructor(ev, tevent_common_context_destructor); + return 0; +} + +/* + create a event_context structure for a specific implemementation. + This must be the first events call, and all subsequent calls pass + this event_context as the first element. Event handlers also + receive this as their first argument. + + This function is for allowing third-party-applications to hook in gluecode + to their own event loop code, so that they can make async usage of our client libs + + NOTE: use tevent_context_init() inside of samba! +*/ +struct tevent_context *tevent_context_init_ops(TALLOC_CTX *mem_ctx, + const struct tevent_ops *ops, + void *additional_data) +{ + struct tevent_context *ev; + int ret; + + ev = talloc_zero(mem_ctx, struct tevent_context); + if (!ev) return NULL; + + ret = tevent_common_context_constructor(ev); + if (ret != 0) { + talloc_free(ev); + return NULL; + } + ev->ops = ops; ev->additional_data = additional_data; |