From 711c18c2301d1bea35cac1144080a94e6b89be27 Mon Sep 17 00:00:00 2001 From: Jeremy Allison Date: Wed, 21 Dec 2011 20:38:32 -0800 Subject: [PATCH] Change the signature of pthreadpool_finished_job() to return 0 on success, errno on fail and return the jobid in a separate variable. I need this fix for my vfs_aio_pthread.c module. Autobuild-User: Jeremy Allison Autobuild-Date: Thu Dec 22 12:12:33 CET 2011 on sn-devel-104 --- source3/lib/fncall.c | 3 +-- source3/lib/pthreadpool/pthreadpool.c | 9 +++++---- source3/lib/pthreadpool/pthreadpool.h | 5 +++-- source3/lib/pthreadpool/tests.c | 18 ++++++++++-------- 4 files changed, 19 insertions(+), 16 deletions(-) diff --git a/source3/lib/fncall.c b/source3/lib/fncall.c index 6e6b7c9250..79bf8260d9 100644 --- a/source3/lib/fncall.c +++ b/source3/lib/fncall.c @@ -280,8 +280,7 @@ static void fncall_handler(struct tevent_context *ev, struct tevent_fd *fde, int i, num_pending; int job_id; - job_id = pthreadpool_finished_job(ctx->pool); - if (job_id <= 0) { + if (pthreadpool_finished_job(ctx->pool, &job_id) != 0) { return; } diff --git a/source3/lib/pthreadpool/pthreadpool.c b/source3/lib/pthreadpool/pthreadpool.c index c916dc0f8d..fffbd050df 100644 --- a/source3/lib/pthreadpool/pthreadpool.c +++ b/source3/lib/pthreadpool/pthreadpool.c @@ -285,16 +285,16 @@ static void pthreadpool_join_children(struct pthreadpool *pool) * Fetch a finished job number from the signal pipe */ -int pthreadpool_finished_job(struct pthreadpool *pool) +int pthreadpool_finished_job(struct pthreadpool *pool, int *jobid) { - int result; + int ret_jobid; ssize_t nread; nread = -1; errno = EINTR; while ((nread == -1) && (errno == EINTR)) { - nread = read(pool->sig_pipe[0], &result, sizeof(int)); + nread = read(pool->sig_pipe[0], &ret_jobid, sizeof(int)); } if (nread == -1) { return errno; @@ -302,7 +302,8 @@ int pthreadpool_finished_job(struct pthreadpool *pool) if (nread != sizeof(int)) { return EINVAL; } - return result; + *jobid = ret_jobid; + return 0; } /* diff --git a/source3/lib/pthreadpool/pthreadpool.h b/source3/lib/pthreadpool/pthreadpool.h index 79704ea385..0fde3c811b 100644 --- a/source3/lib/pthreadpool/pthreadpool.h +++ b/source3/lib/pthreadpool/pthreadpool.h @@ -90,8 +90,9 @@ int pthreadpool_signal_fd(struct pthreadpool *pool); * pthreadpool_signal_fd() is readable. * * @param[in] pool The pool to query for finished jobs - * @return The job_id of the finished job + * @param[out] pjobid The job_id of the finished job + * @return success: 0, failure: errno */ -int pthreadpool_finished_job(struct pthreadpool *pool); +int pthreadpool_finished_job(struct pthreadpool *pool, int *jobid); #endif diff --git a/source3/lib/pthreadpool/tests.c b/source3/lib/pthreadpool/tests.c index 667ee01784..95d37b6f17 100644 --- a/source3/lib/pthreadpool/tests.c +++ b/source3/lib/pthreadpool/tests.c @@ -68,12 +68,13 @@ static int test_jobs(int num_threads, int num_jobs) } for (i=0; i= num_jobs)) { - fprintf(stderr, "invalid job number %d\n", ret); + int jobid = -1; + ret = pthreadpool_finished_job(p, &jobid); + if ((ret != 0) || (jobid >= num_jobs)) { + fprintf(stderr, "invalid job number %d\n", jobid); return -1; } - finished[ret] += 1; + finished[jobid] += 1; } for (i=0; i= num_jobs * num_threads)) { + ret = pthreadpool_finished_job(pools[j], &jobid); + if ((ret != 0) || (jobid >= num_jobs * num_threads)) { fprintf(stderr, "invalid job number %d\n", - ret); + jobid); return -1; } - finished[ret] += 1; + finished[jobid] += 1; received += 1; } } -- 2.34.1