Revert "pthreadpool: add pthreadpool_tevent_job_cancel()"
[samba.git] / lib / pthreadpool / pthreadpool_tevent.c
index e7e17d3..6999730 100644 (file)
@@ -18,6 +18,7 @@
  */
 
 #include "replace.h"
+#include "system/filesys.h"
 #include "pthreadpool_tevent.h"
 #include "pthreadpool.h"
 #include "lib/util/tevent_unix.h"
@@ -81,24 +82,6 @@ static int pthreadpool_tevent_destructor(struct pthreadpool_tevent *pool);
 
 static void pthreadpool_tevent_job_orphan(struct pthreadpool_tevent_job *job);
 
-static struct pthreadpool_tevent_job *orphaned_jobs;
-
-void pthreadpool_tevent_cleanup_orphaned_jobs(void)
-{
-       struct pthreadpool_tevent_job *job = NULL;
-       struct pthreadpool_tevent_job *njob = NULL;
-
-       for (job = orphaned_jobs; job != NULL; job = njob) {
-               njob = job->next;
-
-               /*
-                * The job destructor keeps the job alive
-                * (and in the list) or removes it from the list.
-                */
-               TALLOC_FREE(job);
-       }
-}
-
 static int pthreadpool_tevent_job_signal(int jobid,
                                         void (*job_fn)(void *private_data),
                                         void *job_private_data,
@@ -110,8 +93,6 @@ int pthreadpool_tevent_init(TALLOC_CTX *mem_ctx, unsigned max_threads,
        struct pthreadpool_tevent *pool;
        int ret;
 
-       pthreadpool_tevent_cleanup_orphaned_jobs();
-
        pool = talloc_zero(mem_ctx, struct pthreadpool_tevent);
        if (pool == NULL) {
                return ENOMEM;
@@ -184,8 +165,6 @@ static int pthreadpool_tevent_destructor(struct pthreadpool_tevent *pool)
        }
        pool->pool = NULL;
 
-       pthreadpool_tevent_cleanup_orphaned_jobs();
-
        return 0;
 }
 
@@ -294,7 +273,6 @@ static void pthreadpool_tevent_job_fn(void *private_data);
 static void pthreadpool_tevent_job_done(struct tevent_context *ctx,
                                        struct tevent_immediate *im,
                                        void *private_data);
-static bool pthreadpool_tevent_job_cancel(struct tevent_req *req);
 
 static int pthreadpool_tevent_job_destructor(struct pthreadpool_tevent_job *job)
 {
@@ -339,18 +317,10 @@ static int pthreadpool_tevent_job_destructor(struct pthreadpool_tevent_job *job)
                /*
                 * state->im still there means, we need to wait for the
                 * immediate event to be triggered or just leak the memory.
-                *
-                * Move it to the orphaned list, if it's not already there.
                 */
                return -1;
        }
 
-       /*
-        * Finally remove from the orphaned_jobs list
-        * and let talloc destroy us.
-        */
-       DLIST_REMOVE(orphaned_jobs, job);
-
        return 0;
 }
 
@@ -392,15 +362,6 @@ static void pthreadpool_tevent_job_orphan(struct pthreadpool_tevent_job *job)
         */
        DLIST_REMOVE(job->pool->jobs, job);
 
-       /*
-        * Add it to the list of orphaned jobs,
-        * which may be cleaned up later.
-        *
-        * The destructor removes it from the list
-        * when possible or it denies the free
-        * and keep it in the list.
-        */
-       DLIST_ADD_END(orphaned_jobs, job);
        TALLOC_FREE(job);
 }
 
@@ -439,8 +400,6 @@ struct tevent_req *pthreadpool_tevent_job_send(
        struct pthreadpool_tevent_job *job = NULL;
        int ret;
 
-       pthreadpool_tevent_cleanup_orphaned_jobs();
-
        req = tevent_req_create(mem_ctx, &state,
                                struct pthreadpool_tevent_job_state);
        if (req == NULL) {
@@ -488,7 +447,6 @@ struct tevent_req *pthreadpool_tevent_job_send(
                return tevent_req_post(req, ev);
        }
 
-       tevent_req_set_cancel_fn(req, pthreadpool_tevent_job_cancel);
        return req;
 }
 
@@ -570,44 +528,6 @@ static void pthreadpool_tevent_job_done(struct tevent_context *ctx,
        tevent_req_done(state->req);
 }
 
-static bool pthreadpool_tevent_job_cancel(struct tevent_req *req)
-{
-       struct pthreadpool_tevent_job_state *state =
-               tevent_req_data(req,
-               struct pthreadpool_tevent_job_state);
-       struct pthreadpool_tevent_job *job = state->job;
-       size_t num;
-
-       if (job == NULL) {
-               return false;
-       }
-
-       num = pthreadpool_cancel_job(job->pool->pool, 0,
-                                    pthreadpool_tevent_job_fn,
-                                    job);
-       if (num == 0) {
-               /*
-                * It was too late to cancel the request.
-                */
-               return false;
-       }
-
-       /*
-        * It was not too late to cancel the request.
-        *
-        * We can remove job->im, as it will never be used.
-        */
-       TALLOC_FREE(job->im);
-
-       /*
-        * pthreadpool_tevent_job_cleanup()
-        * will destroy the job.
-        */
-       tevent_req_defer_callback(req, state->ev);
-       tevent_req_error(req, ECANCELED);
-       return true;
-}
-
 int pthreadpool_tevent_job_recv(struct tevent_req *req)
 {
        return tevent_req_simple_recv_unix(req);