Change the signature of pthreadpool_finished_job() to return 0
authorJeremy Allison <jra@samba.org>
Thu, 22 Dec 2011 04:38:32 +0000 (20:38 -0800)
committerJeremy Allison <jra@samba.org>
Thu, 22 Dec 2011 11:12:33 +0000 (12:12 +0100)
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 <jra@samba.org>
Autobuild-Date: Thu Dec 22 12:12:33 CET 2011 on sn-devel-104

source3/lib/fncall.c
source3/lib/pthreadpool/pthreadpool.c
source3/lib/pthreadpool/pthreadpool.h
source3/lib/pthreadpool/tests.c

index 6e6b7c92504f7c1553b73a6a67891f4a65cc471b..79bf8260d9393ca315fe6363de4d81973bfac3ca 100644 (file)
@@ -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;
        }
 
index c916dc0f8d5ca1dc0f112c310a1f8d676386e5fd..fffbd050dffdf5f398c49d7343acc24c7bda9bd7 100644 (file)
@@ -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;
 }
 
 /*
index 79704ea385366f108158566f1a58557888ae6fcf..0fde3c811bd190cd560d9ddb6a5bc2b85e078c7c 100644 (file)
@@ -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
index 667ee01784e74feb29e304ef66d90e8cbef5113d..95d37b6f1703c44c780e84d4f390c216824b9fc6 100644 (file)
@@ -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;
                }
        }