pthreadpool: add pthreadpool_tevent_max_threads() and pthreadpool_tevent_queued_jobs()
authorStefan Metzmacher <metze@samba.org>
Thu, 21 Jun 2018 23:01:42 +0000 (01:01 +0200)
committerStefan Metzmacher <metze@samba.org>
Thu, 12 Jul 2018 12:25:18 +0000 (14:25 +0200)
These can be used to implement some kind of flow control in the caller.
E.g. unless pthreadpool_tevent_queued_jobs() is lower than
pthreadpool_tevent_max_threads() is good to prepare new jobs.

Signed-off-by: Stefan Metzmacher <metze@samba.org>
Reviewed-by: Ralph Boehme <slow@samba.org>
lib/pthreadpool/pthreadpool_tevent.c
lib/pthreadpool/pthreadpool_tevent.h

index b2292ef214c940e204e4ab091c8727f2840c6ae8..db6d4b2f2e8301c6146f929add7ea85929786437 100644 (file)
@@ -102,6 +102,24 @@ int pthreadpool_tevent_init(TALLOC_CTX *mem_ctx, unsigned max_threads,
        return 0;
 }
 
+size_t pthreadpool_tevent_max_threads(struct pthreadpool_tevent *pool)
+{
+       if (pool->pool == NULL) {
+               return 0;
+       }
+
+       return pthreadpool_max_threads(pool->pool);
+}
+
+size_t pthreadpool_tevent_queued_jobs(struct pthreadpool_tevent *pool)
+{
+       if (pool->pool == NULL) {
+               return 0;
+       }
+
+       return pthreadpool_queued_jobs(pool->pool);
+}
+
 static int pthreadpool_tevent_destructor(struct pthreadpool_tevent *pool)
 {
        struct pthreadpool_tevent_job_state *state, *next;
index de74a347e25c2d84823464b9f073b71a37bc2d6e..10d3a71c40a7cb358e5c40f0242c41a697b229ec 100644 (file)
@@ -27,6 +27,9 @@ struct pthreadpool_tevent;
 int pthreadpool_tevent_init(TALLOC_CTX *mem_ctx, unsigned max_threads,
                            struct pthreadpool_tevent **presult);
 
+size_t pthreadpool_tevent_max_threads(struct pthreadpool_tevent *pool);
+size_t pthreadpool_tevent_queued_jobs(struct pthreadpool_tevent *pool);
+
 struct tevent_req *pthreadpool_tevent_job_send(
        TALLOC_CTX *mem_ctx, struct tevent_context *ev,
        struct pthreadpool_tevent *pool,