mirror of
https://github.com/samba-team/samba.git
synced 2025-01-11 05:18:09 +03:00
lib: add job data to to callback
The pthreadpool_tevent wrapper will need this Signed-off-by: Volker Lendecke <vl@samba.org> Reviewed-by: Stefan Metzmacher <metze@samba.org> Reviewed-by: Jeremy Allison <jra@samba.org>
This commit is contained in:
parent
5593467eb1
commit
d7e51286e7
@ -59,8 +59,11 @@ struct pthreadpool {
|
||||
/*
|
||||
* Indicate job completion
|
||||
*/
|
||||
int (*signal_fn)(int jobid, void *private_data);
|
||||
void *signal_private_data;
|
||||
int (*signal_fn)(int jobid,
|
||||
void (*job_fn)(void *private_data),
|
||||
void *job_fn_private_data,
|
||||
void *private_data);
|
||||
void *signal_fn_private_data;
|
||||
|
||||
/*
|
||||
* indicator to worker threads that they should shut down
|
||||
@ -100,8 +103,11 @@ static void pthreadpool_prep_atfork(void);
|
||||
*/
|
||||
|
||||
int pthreadpool_init(unsigned max_threads, struct pthreadpool **presult,
|
||||
int (*signal_fn)(int jobid, void *private_data),
|
||||
void *signal_private_data)
|
||||
int (*signal_fn)(int jobid,
|
||||
void (*job_fn)(void *private_data),
|
||||
void *job_fn_private_data,
|
||||
void *private_data),
|
||||
void *signal_fn_private_data)
|
||||
{
|
||||
struct pthreadpool *pool;
|
||||
int ret;
|
||||
@ -111,7 +117,7 @@ int pthreadpool_init(unsigned max_threads, struct pthreadpool **presult,
|
||||
return ENOMEM;
|
||||
}
|
||||
pool->signal_fn = signal_fn;
|
||||
pool->signal_private_data = signal_private_data;
|
||||
pool->signal_fn_private_data = signal_fn_private_data;
|
||||
|
||||
pool->jobs_array_len = 4;
|
||||
pool->jobs = calloc(
|
||||
@ -484,7 +490,8 @@ static void *pthreadpool_server(void *arg)
|
||||
assert(res == 0);
|
||||
|
||||
ret = pool->signal_fn(job.id,
|
||||
pool->signal_private_data);
|
||||
job.fn, job.private_data,
|
||||
pool->signal_fn_private_data);
|
||||
if (ret != 0) {
|
||||
pthreadpool_server_exit(pool);
|
||||
pthread_mutex_unlock(&pool->mutex);
|
||||
|
@ -44,8 +44,11 @@ struct pthreadpool;
|
||||
* care to not overload the system.
|
||||
*/
|
||||
int pthreadpool_init(unsigned max_threads, struct pthreadpool **presult,
|
||||
int (*signal_fn)(int jobid, void *private_data),
|
||||
void *signal_private_data);
|
||||
int (*signal_fn)(int jobid,
|
||||
void (*job_fn)(void *private_data),
|
||||
void *job_fn_private_data,
|
||||
void *private_data),
|
||||
void *signal_fn_private_data);
|
||||
|
||||
/**
|
||||
* @brief Destroy a pthreadpool
|
||||
|
@ -28,7 +28,10 @@ struct pthreadpool_pipe {
|
||||
int pipe_fds[2];
|
||||
};
|
||||
|
||||
static int pthreadpool_pipe_signal(int jobid, void *private_data);
|
||||
static int pthreadpool_pipe_signal(int jobid,
|
||||
void (*job_fn)(void *private_data),
|
||||
void *job_private_data,
|
||||
void *private_data);
|
||||
|
||||
int pthreadpool_pipe_init(unsigned max_threads,
|
||||
struct pthreadpool_pipe **presult)
|
||||
@ -62,7 +65,10 @@ int pthreadpool_pipe_init(unsigned max_threads,
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int pthreadpool_pipe_signal(int jobid, void *private_data)
|
||||
static int pthreadpool_pipe_signal(int jobid,
|
||||
void (*job_fn)(void *private_data),
|
||||
void *job_private_data,
|
||||
void *private_data)
|
||||
{
|
||||
struct pthreadpool_pipe *pool = private_data;
|
||||
ssize_t written;
|
||||
|
@ -26,14 +26,18 @@ struct pthreadpool {
|
||||
* Indicate job completion
|
||||
*/
|
||||
int (*signal_fn)(int jobid,
|
||||
void (*job_fn)(void *private_data),
|
||||
void *job_fn_private_data,
|
||||
void *private_data);
|
||||
void *signal_private_data;
|
||||
void *signal_fn_private_data;
|
||||
};
|
||||
|
||||
int pthreadpool_init(unsigned max_threads, struct pthreadpool **presult,
|
||||
int (*signal_fn)(int jobid,
|
||||
void (*job_fn)(void *private_data),
|
||||
void *job_fn_private_data,
|
||||
void *private_data),
|
||||
void *signal_private_data)
|
||||
void *signal_fn_private_data)
|
||||
{
|
||||
struct pthreadpool *pool;
|
||||
|
||||
@ -42,7 +46,7 @@ int pthreadpool_init(unsigned max_threads, struct pthreadpool **presult,
|
||||
return ENOMEM;
|
||||
}
|
||||
pool->signal_fn = signal_fn;
|
||||
pool->signal_private_data = signal_private_data;
|
||||
pool->signal_fn_private_data = signal_fn_private_data;
|
||||
|
||||
*presult = pool;
|
||||
return 0;
|
||||
@ -53,7 +57,8 @@ int pthreadpool_add_job(struct pthreadpool *pool, int job_id,
|
||||
{
|
||||
fn(private_data);
|
||||
|
||||
return pool->signal_fn(job_id, pool->signal_private_data);
|
||||
return pool->signal_fn(job_id, fn, private_data,
|
||||
pool->signal_fn_private_data);
|
||||
}
|
||||
|
||||
int pthreadpool_destroy(struct pthreadpool *pool)
|
||||
|
Loading…
Reference in New Issue
Block a user