summaryrefslogtreecommitdiff
path: root/lib/tsocket
diff options
context:
space:
mode:
authorStefan Metzmacher <metze@samba.org>2011-07-28 10:37:51 +0200
committerStefan Metzmacher <metze@samba.org>2011-08-10 08:04:15 +0200
commitb97aab0223746870429255acac5607062781a266 (patch)
tree03360c4755851592bea23970a1298e3505bea3a1 /lib/tsocket
parent4a5e9cf0ed909faef1325efff4581a4c5ee8d736 (diff)
downloadsamba-b97aab0223746870429255acac5607062781a266.tar.gz
samba-b97aab0223746870429255acac5607062781a266.tar.bz2
samba-b97aab0223746870429255acac5607062781a266.zip
tsocket: make use of tevent_queue_add_optimize_empty() to optimize for the empty queue case
metze
Diffstat (limited to 'lib/tsocket')
-rw-r--r--lib/tsocket/tsocket_helpers.c85
1 files changed, 48 insertions, 37 deletions
diff --git a/lib/tsocket/tsocket_helpers.c b/lib/tsocket/tsocket_helpers.c
index db6b6148e9..1b92b9f82c 100644
--- a/lib/tsocket/tsocket_helpers.c
+++ b/lib/tsocket/tsocket_helpers.c
@@ -52,7 +52,7 @@ struct tevent_req *tdgram_sendto_queue_send(TALLOC_CTX *mem_ctx,
{
struct tevent_req *req;
struct tdgram_sendto_queue_state *state;
- bool ok;
+ struct tevent_queue_entry *e;
req = tevent_req_create(mem_ctx, &state,
struct tdgram_sendto_queue_state);
@@ -67,21 +67,24 @@ struct tevent_req *tdgram_sendto_queue_send(TALLOC_CTX *mem_ctx,
state->caller.dst = dst;
state->ret = -1;
- ok = tevent_queue_add(queue,
- ev,
- req,
- tdgram_sendto_queue_trigger,
- NULL);
- if (!ok) {
- tevent_req_oom(req);
- goto post;
+ /*
+ * we use tevent_queue_add_optimize_empty() with allow_direct
+ * in order to optimize for the empty queue case.
+ */
+ e = tevent_queue_add_optimize_empty(
+ queue,
+ ev,
+ req,
+ tdgram_sendto_queue_trigger,
+ NULL);
+ if (tevent_req_nomem(e, req)) {
+ return tevent_req_post(req, ev);
+ }
+ if (!tevent_req_is_in_progress(req)) {
+ return tevent_req_post(req, ev);
}
return req;
-
- post:
- tevent_req_post(req, ev);
- return req;
}
static void tdgram_sendto_queue_trigger(struct tevent_req *req,
@@ -326,7 +329,7 @@ struct tevent_req *tstream_readv_pdu_queue_send(TALLOC_CTX *mem_ctx,
{
struct tevent_req *req;
struct tstream_readv_pdu_queue_state *state;
- bool ok;
+ struct tevent_queue_entry *e;
req = tevent_req_create(mem_ctx, &state,
struct tstream_readv_pdu_queue_state);
@@ -340,20 +343,24 @@ struct tevent_req *tstream_readv_pdu_queue_send(TALLOC_CTX *mem_ctx,
state->caller.next_vector_private = next_vector_private;
state->ret = -1;
- ok = tevent_queue_add(queue,
- ev,
- req,
- tstream_readv_pdu_queue_trigger,
- NULL);
- if (!ok) {
- tevent_req_oom(req);
- goto post;
+ /*
+ * we use tevent_queue_add_optimize_empty() with allow_direct
+ * in order to optimize for the empty queue case.
+ */
+ e = tevent_queue_add_optimize_empty(
+ queue,
+ ev,
+ req,
+ tstream_readv_pdu_queue_trigger,
+ NULL);
+ if (tevent_req_nomem(e, req)) {
+ return tevent_req_post(req, ev);
+ }
+ if (!tevent_req_is_in_progress(req)) {
+ return tevent_req_post(req, ev);
}
return req;
-
- post:
- return tevent_req_post(req, ev);
}
static void tstream_readv_pdu_queue_trigger(struct tevent_req *req,
@@ -433,7 +440,7 @@ struct tevent_req *tstream_writev_queue_send(TALLOC_CTX *mem_ctx,
{
struct tevent_req *req;
struct tstream_writev_queue_state *state;
- bool ok;
+ struct tevent_queue_entry *e;
req = tevent_req_create(mem_ctx, &state,
struct tstream_writev_queue_state);
@@ -447,20 +454,24 @@ struct tevent_req *tstream_writev_queue_send(TALLOC_CTX *mem_ctx,
state->caller.count = count;
state->ret = -1;
- ok = tevent_queue_add(queue,
- ev,
- req,
- tstream_writev_queue_trigger,
- NULL);
- if (!ok) {
- tevent_req_oom(req);
- goto post;
+ /*
+ * we use tevent_queue_add_optimize_empty() with allow_direct
+ * in order to optimize for the empty queue case.
+ */
+ e = tevent_queue_add_optimize_empty(
+ queue,
+ ev,
+ req,
+ tstream_writev_queue_trigger,
+ NULL);
+ if (tevent_req_nomem(e, req)) {
+ return tevent_req_post(req, ev);
+ }
+ if (!tevent_req_is_in_progress(req)) {
+ return tevent_req_post(req, ev);
}
return req;
-
- post:
- return tevent_req_post(req, ev);
}
static void tstream_writev_queue_trigger(struct tevent_req *req,