int asys_pread(struct asys_context *ctx, int fildes, void *buf, size_t nbyte, off_t offset, void *private_data) { struct asys_job *job; struct asys_pread_args *args; int jobid; int ret; ret = asys_new_job(ctx, &jobid, &job); if (ret != 0) { return ret; } job->private_data = private_data; args = &job->args.pread_args; args->fildes = fildes; args->buf = buf; args->nbyte = nbyte; args->offset = offset; ret = pthreadpool_add_job(ctx->pool, jobid, asys_pread_do, job); if (ret != 0) { return ret; } job->busy = 1; return 0; }
static int aio_pthread_write(struct vfs_handle_struct *handle, struct files_struct *fsp, SMB_STRUCT_AIOCB *aiocb) { struct aio_extra *aio_ex = (struct aio_extra *)aiocb->aio_sigevent.sigev_value.sival_ptr; struct aio_private_data *pd = NULL; int ret; if (!init_aio_threadpool(handle)) { return -1; } pd = create_private_data(aio_ex, aiocb); if (pd == NULL) { DEBUG(10, ("aio_pthread_write: Could not create private data.\n")); return -1; } pd->write_command = true; ret = pthreadpool_add_job(pool, pd->jobid, aio_worker, (void *)pd); if (ret) { errno = ret; return -1; } DEBUG(10, ("aio_pthread_write: jobid=%d pwrite requested " "of %llu bytes at offset %llu\n", pd->jobid, (unsigned long long)pd->aiocb->aio_nbytes, (unsigned long long)pd->aiocb->aio_offset)); return 0; }
static int test_jobs(int num_threads, int num_jobs) { char *finished; struct pthreadpool *p; int timeout = 1; int i, ret; finished = (char *)calloc(1, num_jobs); if (finished == NULL) { fprintf(stderr, "calloc failed\n"); return -1; } ret = pthreadpool_init(num_threads, &p); if (ret != 0) { fprintf(stderr, "pthreadpool_init failed: %s\n", strerror(ret)); return -1; } for (i=0; i<num_jobs; i++) { ret = pthreadpool_add_job(p, i, test_sleep, &timeout); if (ret != 0) { fprintf(stderr, "pthreadpool_add_job failed: %s\n", strerror(ret)); return -1; } } for (i=0; i<num_jobs; i++) { 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[jobid] += 1; } for (i=0; i<num_jobs; i++) { if (finished[i] != 1) { fprintf(stderr, "finished[%d] = %d\n", i, finished[i]); return -1; } } ret = pthreadpool_destroy(p); if (ret != 0) { fprintf(stderr, "pthreadpool_destroy failed: %s\n", strerror(ret)); return -1; } free(finished); return 0; }
static void *test_threaded_worker(void *p) { struct threaded_state *state = (struct threaded_state *)p; int i; for (i=0; i<state->num_jobs; i++) { int ret = pthreadpool_add_job(state->p, state->start_job + i, test_sleep, &state->timeout); if (ret != 0) { fprintf(stderr, "pthreadpool_add_job failed: %s\n", strerror(ret)); return NULL; } } return NULL; }
static int open_async(const files_struct *fsp, int flags, mode_t mode) { struct aio_open_private_data *opd = NULL; int ret; if (!init_aio_threadpool(fsp->conn->sconn->ev_ctx, &open_pool, aio_open_handle_completion)) { return -1; } opd = create_private_open_data(fsp, flags, mode); if (opd == NULL) { DEBUG(10, ("open_async: Could not create private data.\n")); return -1; } ret = pthreadpool_add_job(open_pool, opd->jobid, aio_open_worker, (void *)opd); if (ret) { errno = ret; return -1; } DEBUG(5,("open_async: mid %llu jobid %d created for file %s/%s\n", (unsigned long long)opd->mid, opd->jobid, opd->dname, opd->fname)); /* Cause the calling code to reschedule us. */ errno = EINTR; /* Maps to NT_STATUS_RETRY. */ return -1; }
static int test_busydestroy(void) { struct pthreadpool *p; int timeout = 50; struct pollfd pfd; int ret; ret = pthreadpool_init(1, &p); if (ret != 0) { fprintf(stderr, "pthreadpool_init failed: %s\n", strerror(ret)); return -1; } ret = pthreadpool_add_job(p, 1, test_sleep, &timeout); if (ret != 0) { fprintf(stderr, "pthreadpool_add_job failed: %s\n", strerror(ret)); return -1; } ret = pthreadpool_destroy(p); if (ret != EBUSY) { fprintf(stderr, "Could destroy a busy pool\n"); return -1; } pfd.fd = pthreadpool_signal_fd(p); pfd.events = POLLIN|POLLERR; poll(&pfd, 1, -1); ret = pthreadpool_destroy(p); if (ret != 0) { fprintf(stderr, "pthreadpool_destroy failed: %s\n", strerror(ret)); return -1; } return 0; }
int asys_fsync(struct asys_context *ctx, int fildes, void *private_data) { struct asys_job *job; struct asys_fsync_args *args; int jobid; int ret; ret = asys_new_job(ctx, &jobid, &job); if (ret != 0) { return ret; } job->private_data = private_data; args = &job->args.fsync_args; args->fildes = fildes; ret = pthreadpool_add_job(ctx->pool, jobid, asys_fsync_do, job); if (ret != 0) { return ret; } job->busy = 1; return 0; }