From: Volker Lendecke Date: Mon, 5 Jun 2017 04:58:37 +0000 (+0200) Subject: tevent: Factor out context initialization X-Git-Tag: ldb-1.1.31~136 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=97d912d99afb115e17f683a55aef447dc92ced49;p=thirdparty%2Fsamba.git tevent: Factor out context initialization Signed-off-by: Volker Lendecke Reviewed-by: Jeremy Allison --- 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;