summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--source3/lib/fncall.c3
-rw-r--r--source3/lib/pthreadpool/pthreadpool.c9
-rw-r--r--source3/lib/pthreadpool/pthreadpool.h5
-rw-r--r--source3/lib/pthreadpool/tests.c18
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; i++) {
- ret = pthreadpool_finished_job(p);
- if ((ret < 0) || (ret >= 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; i++) {
@@ -275,18 +276,19 @@ static int test_threaded_addjob(int num_pools, int num_threads, int poolsize,
}
for (j=0; j<num_pools; j++) {
+ int jobid = -1;
if ((pfds[j].revents & (POLLIN|POLLHUP)) == 0) {
continue;
}
- ret = pthreadpool_finished_job(pools[j]);
- if ((ret < 0) || (ret >= 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;
}
}