summaryrefslogtreecommitdiff
path: root/lib/tevent/tevent_queue.c
diff options
context:
space:
mode:
authorStefan Metzmacher <metze@samba.org>2011-07-28 10:45:22 +0200
committerStefan Metzmacher <metze@samba.org>2011-08-09 21:37:41 +0200
commit1533f1722de96f814c5e9de9aebc2892eb4bf882 (patch)
tree9fe1e37f919a0767bd77b1779f22022d722b46f3 /lib/tevent/tevent_queue.c
parent6b7d58cb4ee3ed7796a8dc67c214a1b8439fbaeb (diff)
downloadsamba-1533f1722de96f814c5e9de9aebc2892eb4bf882.tar.gz
samba-1533f1722de96f814c5e9de9aebc2892eb4bf882.tar.bz2
samba-1533f1722de96f814c5e9de9aebc2892eb4bf882.zip
tevent: add tevent_queue_add_entry() and tevent_queue_add_optimize_empty()
This adds more flexible handling for the add operation: - It allows the caller to remove a tevent_req from the queue by calling talloc_free() on the returned tevent_queue_entry. - It allows the caller to optimize for the empty queue case, where it the caller wants to avoid the delay caused by the immediate event. metze
Diffstat (limited to 'lib/tevent/tevent_queue.c')
-rw-r--r--lib/tevent/tevent_queue.c57
1 files changed, 55 insertions, 2 deletions
diff --git a/lib/tevent/tevent_queue.c b/lib/tevent/tevent_queue.c
index 7737b3e814..4750675802 100644
--- a/lib/tevent/tevent_queue.c
+++ b/lib/tevent/tevent_queue.c
@@ -149,7 +149,8 @@ static struct tevent_queue_entry *tevent_queue_add_internal(
struct tevent_context *ev,
struct tevent_req *req,
tevent_queue_trigger_fn_t trigger,
- void *private_data)
+ void *private_data,
+ bool allow_direct)
{
struct tevent_queue_entry *e;
@@ -171,6 +172,24 @@ static struct tevent_queue_entry *tevent_queue_add_internal(
e->triggered = true;
}
+ if (queue->length > 0) {
+ /*
+ * if there are already entries in the
+ * queue do not optimize.
+ */
+ allow_direct = false;
+ }
+
+ if (req->async.fn != NULL) {
+ /*
+ * If the callers wants to optimize for the
+ * empty queue case, call the trigger only
+ * if there is no callback defined for the
+ * request yet.
+ */
+ allow_direct = false;
+ }
+
DLIST_ADD_END(queue->list, e, struct tevent_queue_entry *);
queue->length++;
talloc_set_destructor(e, tevent_queue_entry_destructor);
@@ -183,6 +202,18 @@ static struct tevent_queue_entry *tevent_queue_add_internal(
return e;
}
+ /*
+ * If allowed we directly call the trigger
+ * avoiding possible delays caused by
+ * an immediate event.
+ */
+ if (allow_direct) {
+ queue->list->triggered = true;
+ queue->list->trigger(queue->list->req,
+ queue->list->private_data);
+ return e;
+ }
+
tevent_schedule_immediate(queue->immediate,
queue->list->ev,
tevent_queue_immediate_trigger,
@@ -200,7 +231,7 @@ bool tevent_queue_add(struct tevent_queue *queue,
struct tevent_queue_entry *e;
e = tevent_queue_add_internal(queue, ev, req,
- trigger, private_data);
+ trigger, private_data, false);
if (e == NULL) {
return false;
}
@@ -208,6 +239,28 @@ bool tevent_queue_add(struct tevent_queue *queue,
return true;
}
+struct tevent_queue_entry *tevent_queue_add_entry(
+ struct tevent_queue *queue,
+ struct tevent_context *ev,
+ struct tevent_req *req,
+ tevent_queue_trigger_fn_t trigger,
+ void *private_data)
+{
+ return tevent_queue_add_internal(queue, ev, req,
+ trigger, private_data, false);
+}
+
+struct tevent_queue_entry *tevent_queue_add_optimize_empty(
+ struct tevent_queue *queue,
+ struct tevent_context *ev,
+ struct tevent_req *req,
+ tevent_queue_trigger_fn_t trigger,
+ void *private_data)
+{
+ return tevent_queue_add_internal(queue, ev, req,
+ trigger, private_data, true);
+}
+
void tevent_queue_start(struct tevent_queue *queue)
{
if (queue->running) {