1
0
mirror of https://github.com/samba-team/samba.git synced 2025-01-22 22:04:08 +03:00

s3:messages: improve tevent_create_immediate recycling

We should create the immediate event at the beginning
were we have a chance to return an error, rather than
ignoring a failure later.

As a side effect this also reuses the immediate event
after the refcount went to 0 and up again.

Pair-Programmed-With: Stefan Metzmacher <metze@samba.org>

Signed-off-by: Ralph Boehme <slow@samba.org>
Signed-off-by: Stefan Metzmacher <metze@samba.org>
Reviewed-by: Volker Lendecke <vl@samba.org>

Autobuild-User(master): Stefan Metzmacher <metze@samba.org>
Autobuild-Date(master): Tue Apr 24 14:30:20 CEST 2018 on sn-devel-144
This commit is contained in:
Ralph Boehme 2018-03-27 16:04:58 +02:00 committed by Stefan Metzmacher
parent dfb712a03c
commit 8e5cc9732b

View File

@ -213,6 +213,13 @@ static bool messaging_register_event_context(struct messaging_context *ctx,
}
if (free_reg == NULL) {
struct tevent_immediate *im = NULL;
im = tevent_create_immediate(ctx);
if (im == NULL) {
return false;
}
tmp = talloc_realloc(ctx, ctx->event_contexts,
struct messaging_registered_ev,
num_event_contexts+1);
@ -222,9 +229,14 @@ static bool messaging_register_event_context(struct messaging_context *ctx,
ctx->event_contexts = tmp;
free_reg = &ctx->event_contexts[num_event_contexts];
free_reg->im = talloc_move(ctx->event_contexts, &im);
}
*free_reg = (struct messaging_registered_ev) { .ev = ev, .refcount = 1 };
/*
* free_reg->im might be cached
*/
free_reg->ev = ev;
free_reg->refcount = 1;
return true;
}
@ -247,6 +259,16 @@ static bool messaging_deregister_event_context(struct messaging_context *ctx,
reg->refcount -= 1;
if (reg->refcount == 0) {
/*
* The primary event context
* is never unregistered using
* messaging_deregister_event_context()
* it's only registered using
* messaging_register_event_context().
*/
SMB_ASSERT(ev != ctx->event_ctx);
SMB_ASSERT(reg->ev != ctx->event_ctx);
/*
* Not strictly necessary, just
* paranoia
@ -256,7 +278,14 @@ static bool messaging_deregister_event_context(struct messaging_context *ctx,
/*
* Do not talloc_free(reg->im),
* recycle immediates events.
*
* We just invalidate it using
* the primary event context,
* which is never unregistered.
*/
tevent_schedule_immediate(reg->im,
ctx->event_ctx,
NULL, NULL);
}
return true;
}
@ -329,15 +358,6 @@ static bool messaging_alert_event_contexts(struct messaging_context *ctx)
continue;
}
if (reg->im == NULL) {
reg->im = tevent_create_immediate(
ctx->event_contexts);
}
if (reg->im == NULL) {
DBG_WARNING("Could not create immediate\n");
continue;
}
/*
* We depend on schedule_immediate to work
* multiple times. Might be a bit inefficient,