more
authorStefan Metzmacher <metze@samba.org>
Thu, 28 Jul 2016 18:02:24 +0000 (20:02 +0200)
committerStefan Metzmacher <metze@samba.org>
Thu, 17 May 2018 07:51:51 +0000 (09:51 +0200)
lib/tevent/tevent_metze.c

index 9bf1a8912ee6fa8fd35c78e282d054eba76c6353..975b7c7a63edbf9bdd63443dfac0116311095ae7 100644 (file)
@@ -166,8 +166,43 @@ struct tevent_threadpool_job *_tevent_threadpool_job_create(TALLOC_CTX *mem_ctx,
 
 struct tevent_threadpool_job_state {
        struct tevent_threadpool_job *job;
+       struct tevent_queue_entry *qe;
 };
 
+static void tevent_threadpool_job_cleanup(struct tevent_req *req,
+                                         enum tevent_req_state req_state);
+static bool tevent_threadpool_job_cancel(struct tevent_req *req);
+static void tevent_threadpool_job_trigger(struct tevent_req *req,
+                                         void *private_data);
+
+struct tevent_req *tevent_threadpool_job_send(TALLOC_CTX *mem_ctx,
+                                             struct tevent_context *ev,
+                                             struct tevent_threadpool *pool,
+                                             struct tevent_threadpool_job *job)
+{
+       struct tevent_req *req;
+       struct tevent_threadpool_job_state *state;
+
+       req = tevent_req_create(mem_ctx, &state,
+                               struct tevent_threadpool_job_state);
+       if (req == NULL) {
+               return NULL;
+       }
+       state->job = job;
+
+       tevent_req_set_cleanup_fn(req, tevent_threadpool_job_cleanup);
+       tevent_req_set_cancel_fn(req, tevent_threadpool_job_cancel);
+
+       state->qe = tevent_queue_add_optimize_empty(pool->job_queue, ev, req,
+                                                   tevent_threadpool_job_trigger,
+                                                   state);
+       if (tevent_req_nomem(state->qe, req)) {
+               return tevent_req_post(req, ev);
+       }
+
+       return req;
+}
+
 static void tevent_threadpool_job_cleanup(struct tevent_req *req,
                                          enum tevent_req_state req_state)
 {
@@ -176,6 +211,8 @@ static void tevent_threadpool_job_cleanup(struct tevent_req *req,
                struct tevent_threadpool_job_state);
        struct tevent_threadpool_job *job = state->job;
 
+       TALLOC_FREE(state->qe);
+
        if (job == NULL) {
                return;
        }
@@ -192,24 +229,22 @@ static void tevent_threadpool_job_cleanup(struct tevent_req *req,
        job->busy.req = NULL;
 }
 
-struct tevent_req *tevent_threadpool_job_send(TALLOC_CTX *mem_ctx,
-                                             struct tevent_context *ev,
-                                             struct tevent_threadpool *pool,
-                                             struct tevent_threadpool_job *job)
+
+static bool tevent_threadpool_job_cancel(struct tevent_req *req)
 {
-       struct tevent_req *req;
-       struct tevent_threadpool_job_state *state;
+       struct tevent_threadpool_job_state *state =
+               tevent_req_data(req,
+               struct tevent_threadpool_job_state);
 
-       req = tevent_req_create(mem_ctx, &state,
-                               struct tevent_threadpool_job_state);
-       if (req == NULL) {
-               return NULL;
-       }
-       state->job = job;
+       TALLOC_FREE(state->qe);
 
-       tevent_req_set_cleanup_fn(req, tevent_threadpool_job_cleanup);
+       //TODO:
+       return false;
+}
 
-       return req;
+static void tevent_threadpool_job_trigger(struct tevent_req *req,
+                                         void *private_data)
+{
 }
 
 int tevent_threadpool_job_recv(struct tevent_req *req, int *perrno)