summaryrefslogtreecommitdiffstats
path: root/source3/lib/pthreadpool
diff options
context:
space:
mode:
Diffstat (limited to 'source3/lib/pthreadpool')
-rw-r--r--source3/lib/pthreadpool/pthreadpool.c19
-rw-r--r--source3/lib/pthreadpool/pthreadpool.h13
-rw-r--r--source3/lib/pthreadpool/pthreadpool_sync.c26
-rw-r--r--source3/lib/pthreadpool/tests.c8
4 files changed, 39 insertions, 27 deletions
diff --git a/source3/lib/pthreadpool/pthreadpool.c b/source3/lib/pthreadpool/pthreadpool.c
index d51e808360..4436ab3289 100644
--- a/source3/lib/pthreadpool/pthreadpool.c
+++ b/source3/lib/pthreadpool/pthreadpool.c
@@ -288,25 +288,26 @@ 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 *jobid)
+int pthreadpool_finished_jobs(struct pthreadpool *pool, int *jobids,
+ unsigned num_jobids)
{
- int ret_jobid;
- ssize_t nread;
+ ssize_t to_read, nread;
nread = -1;
errno = EINTR;
+ to_read = sizeof(int) * num_jobids;
+
while ((nread == -1) && (errno == EINTR)) {
- nread = read(pool->sig_pipe[0], &ret_jobid, sizeof(int));
+ nread = read(pool->sig_pipe[0], jobids, to_read);
}
if (nread == -1) {
- return errno;
+ return -errno;
}
- if (nread != sizeof(int)) {
- return EINVAL;
+ if ((nread % sizeof(int)) != 0) {
+ return -EINVAL;
}
- *jobid = ret_jobid;
- return 0;
+ return nread / sizeof(int);
}
/*
diff --git a/source3/lib/pthreadpool/pthreadpool.h b/source3/lib/pthreadpool/pthreadpool.h
index fac2d25424..adb825a528 100644
--- a/source3/lib/pthreadpool/pthreadpool.h
+++ b/source3/lib/pthreadpool/pthreadpool.h
@@ -61,7 +61,7 @@ int pthreadpool_destroy(struct pthreadpool *pool);
*
* This adds a job to a pthreadpool. The job can be identified by
* job_id. This integer will be returned from
- * pthreadpool_finished_job() then the job is completed.
+ * pthreadpool_finished_jobs() then the job is completed.
*
* @param[in] pool The pool to run the job on
* @param[in] job_id A custom identifier
@@ -84,15 +84,18 @@ int pthreadpool_add_job(struct pthreadpool *pool, int job_id,
int pthreadpool_signal_fd(struct pthreadpool *pool);
/**
- * @brief Get the job_id of a finished job
+ * @brief Get the job_ids of finished jobs
*
* This blocks until a job has finished unless the fd returned by
* pthreadpool_signal_fd() is readable.
*
* @param[in] pool The pool to query for finished jobs
- * @param[out] pjobid The job_id of the finished job
- * @return success: 0, failure: errno
+ * @param[out] jobids The job_ids of the finished job
+ * @param[int] num_jobids The job_ids array size
+ * @return success: >=0, number of finished jobs
+ * failure: -errno
*/
-int pthreadpool_finished_job(struct pthreadpool *pool, int *jobid);
+int pthreadpool_finished_jobs(struct pthreadpool *pool, int *jobids,
+ unsigned num_jobids);
#endif
diff --git a/source3/lib/pthreadpool/pthreadpool_sync.c b/source3/lib/pthreadpool/pthreadpool_sync.c
index 0c2d12fef3..5f06cae2f8 100644
--- a/source3/lib/pthreadpool/pthreadpool_sync.c
+++ b/source3/lib/pthreadpool/pthreadpool_sync.c
@@ -133,27 +133,35 @@ int pthreadpool_add_job(struct pthreadpool *pool, int job_id,
}
-int pthreadpool_finished_job(struct pthreadpool *pool, int *jobid)
+int pthreadpool_finished_jobs(struct pthreadpool *pool, int *jobids,
+ unsigned num_jobids)
{
- int ret_jobid;
- ssize_t nread;
+ ssize_t to_read, nread;
+ int ret;
nread = -1;
errno = EINTR;
+ to_read = sizeof(int) * num_jobids;
+
while ((nread == -1) && (errno == EINTR)) {
- nread = read(pool->sig_pipe[0], &ret_jobid, sizeof(int));
+ nread = read(pool->sig_pipe[0], jobids, to_read);
}
if (nread == -1) {
- return errno;
+ return -errno;
}
- if (nread != sizeof(int)) {
- return EINVAL;
+ if ((nread % sizeof(int)) != 0) {
+ return -EINVAL;
}
- *jobid = ret_jobid;
pool->pipe_busy = 0;
- return pthreadpool_write_to_pipe(pool);
+
+ ret = pthreadpool_write_to_pipe(pool);
+ if (ret != 0) {
+ return -ret;
+ }
+
+ return nread / sizeof(int);
}
int pthreadpool_destroy(struct pthreadpool *pool)
diff --git a/source3/lib/pthreadpool/tests.c b/source3/lib/pthreadpool/tests.c
index 170cedf07f..847471297f 100644
--- a/source3/lib/pthreadpool/tests.c
+++ b/source3/lib/pthreadpool/tests.c
@@ -71,8 +71,8 @@ static int test_jobs(int num_threads, int num_jobs)
for (i=0; i<num_jobs; i++) {
int jobid = -1;
- ret = pthreadpool_finished_job(p, &jobid);
- if ((ret != 0) || (jobid >= num_jobs)) {
+ ret = pthreadpool_finished_jobs(p, &jobid, 1);
+ if ((ret != 1) || (jobid >= num_jobs)) {
fprintf(stderr, "invalid job number %d\n", jobid);
return -1;
}
@@ -284,8 +284,8 @@ static int test_threaded_addjob(int num_pools, int num_threads, int poolsize,
continue;
}
- ret = pthreadpool_finished_job(pools[j], &jobid);
- if ((ret != 0) || (jobid >= num_jobs * num_threads)) {
+ ret = pthreadpool_finished_jobs(pools[j], &jobid, 1);
+ if ((ret != 1) || (jobid >= num_jobs * num_threads)) {
fprintf(stderr, "invalid job number %d\n",
jobid);
return -1;