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);
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;