summaryrefslogtreecommitdiff
path: root/lib/pthreadpool
diff options
context:
space:
mode:
authorStefan Metzmacher <metze@samba.org>2018-06-22 01:01:42 +0200
committerStefan Metzmacher <metze@samba.org>2018-07-12 14:25:18 +0200
commite4dfd3da94c097fa9cd3fea4ad6dfc4af8ca2a45 (patch)
treeeded532cfb130698abb1152d884fd59b1dc81f36 /lib/pthreadpool
parent505d298e81570bb118a9b82e5166a8f11139750b (diff)
downloadsamba-e4dfd3da94c097fa9cd3fea4ad6dfc4af8ca2a45.tar.gz
pthreadpool: add pthreadpool_tevent_max_threads() and pthreadpool_tevent_queued_jobs()
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>
Diffstat (limited to 'lib/pthreadpool')
-rw-r--r--lib/pthreadpool/pthreadpool_tevent.c18
-rw-r--r--lib/pthreadpool/pthreadpool_tevent.h3
2 files changed, 21 insertions, 0 deletions
diff --git a/lib/pthreadpool/pthreadpool_tevent.c b/lib/pthreadpool/pthreadpool_tevent.c
index b2292ef214c..db6d4b2f2e8 100644
--- a/lib/pthreadpool/pthreadpool_tevent.c
+++ b/lib/pthreadpool/pthreadpool_tevent.c
@@ -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;
diff --git a/lib/pthreadpool/pthreadpool_tevent.h b/lib/pthreadpool/pthreadpool_tevent.h
index de74a347e25..10d3a71c40a 100644
--- a/lib/pthreadpool/pthreadpool_tevent.h
+++ b/lib/pthreadpool/pthreadpool_tevent.h
@@ -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,