mirror of
https://github.com/samba-team/samba.git
synced 2025-07-04 00:59:13 +03:00
pthreadpool: Move creating of thread to new function
No functional change, but this simplifies error handling.
BUG: https://bugzilla.samba.org/show_bug.cgi?id=13170
Signed-off-by: Christof Schmitt <cs@samba.org>
Reviewed-by: Volker Lendecke <vl@samba.org>
(cherry picked from commit 949ccc3ea9
)
This commit is contained in:
committed by
Karolin Seeger
parent
82f6111ad5
commit
b51a2712c1
@ -521,14 +521,56 @@ static void *pthreadpool_server(void *arg)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
int pthreadpool_add_job(struct pthreadpool *pool, int job_id,
|
static int pthreadpool_create_thread(struct pthreadpool *pool)
|
||||||
void (*fn)(void *private_data), void *private_data)
|
|
||||||
{
|
{
|
||||||
pthread_attr_t thread_attr;
|
pthread_attr_t thread_attr;
|
||||||
pthread_t thread_id;
|
pthread_t thread_id;
|
||||||
int res;
|
int res;
|
||||||
sigset_t mask, omask;
|
sigset_t mask, omask;
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Create a new worker thread. It should not receive any signals.
|
||||||
|
*/
|
||||||
|
|
||||||
|
sigfillset(&mask);
|
||||||
|
|
||||||
|
res = pthread_attr_init(&thread_attr);
|
||||||
|
if (res != 0) {
|
||||||
|
return res;
|
||||||
|
}
|
||||||
|
|
||||||
|
res = pthread_attr_setdetachstate(
|
||||||
|
&thread_attr, PTHREAD_CREATE_DETACHED);
|
||||||
|
if (res != 0) {
|
||||||
|
pthread_attr_destroy(&thread_attr);
|
||||||
|
return res;
|
||||||
|
}
|
||||||
|
|
||||||
|
res = pthread_sigmask(SIG_BLOCK, &mask, &omask);
|
||||||
|
if (res != 0) {
|
||||||
|
pthread_attr_destroy(&thread_attr);
|
||||||
|
return res;
|
||||||
|
}
|
||||||
|
|
||||||
|
res = pthread_create(&thread_id, &thread_attr, pthreadpool_server,
|
||||||
|
(void *)pool);
|
||||||
|
|
||||||
|
assert(pthread_sigmask(SIG_SETMASK, &omask, NULL) == 0);
|
||||||
|
|
||||||
|
pthread_attr_destroy(&thread_attr);
|
||||||
|
|
||||||
|
if (res == 0) {
|
||||||
|
pool->num_threads += 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
return res;
|
||||||
|
}
|
||||||
|
|
||||||
|
int pthreadpool_add_job(struct pthreadpool *pool, int job_id,
|
||||||
|
void (*fn)(void *private_data), void *private_data)
|
||||||
|
{
|
||||||
|
int res;
|
||||||
|
|
||||||
res = pthread_mutex_lock(&pool->mutex);
|
res = pthread_mutex_lock(&pool->mutex);
|
||||||
if (res != 0) {
|
if (res != 0) {
|
||||||
return res;
|
return res;
|
||||||
@ -570,43 +612,12 @@ int pthreadpool_add_job(struct pthreadpool *pool, int job_id,
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
res = pthreadpool_create_thread(pool);
|
||||||
* Create a new worker thread. It should not receive any signals.
|
|
||||||
*/
|
|
||||||
|
|
||||||
sigfillset(&mask);
|
|
||||||
|
|
||||||
res = pthread_attr_init(&thread_attr);
|
|
||||||
if (res != 0) {
|
if (res != 0) {
|
||||||
pthread_mutex_unlock(&pool->mutex);
|
pthread_mutex_unlock(&pool->mutex);
|
||||||
return res;
|
return res;
|
||||||
}
|
}
|
||||||
|
|
||||||
res = pthread_attr_setdetachstate(
|
|
||||||
&thread_attr, PTHREAD_CREATE_DETACHED);
|
|
||||||
if (res != 0) {
|
|
||||||
pthread_attr_destroy(&thread_attr);
|
|
||||||
pthread_mutex_unlock(&pool->mutex);
|
|
||||||
return res;
|
|
||||||
}
|
|
||||||
|
|
||||||
res = pthread_sigmask(SIG_BLOCK, &mask, &omask);
|
|
||||||
if (res != 0) {
|
|
||||||
pthread_attr_destroy(&thread_attr);
|
|
||||||
pthread_mutex_unlock(&pool->mutex);
|
|
||||||
return res;
|
|
||||||
}
|
|
||||||
|
|
||||||
res = pthread_create(&thread_id, &thread_attr, pthreadpool_server,
|
|
||||||
(void *)pool);
|
|
||||||
if (res == 0) {
|
|
||||||
pool->num_threads += 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
assert(pthread_sigmask(SIG_SETMASK, &omask, NULL) == 0);
|
|
||||||
|
|
||||||
pthread_attr_destroy(&thread_attr);
|
|
||||||
|
|
||||||
pthread_mutex_unlock(&pool->mutex);
|
pthread_mutex_unlock(&pool->mutex);
|
||||||
return res;
|
return res;
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user