diff options
author | malc <malc@c046a42c-6fe2-441c-8c8c-71466251a162> | 2009-02-21 05:48:17 +0000 |
---|---|---|
committer | malc <malc@c046a42c-6fe2-441c-8c8c-71466251a162> | 2009-02-21 05:48:17 +0000 |
commit | a8227a5a200f1bb52ecd0f1a96b24d2e2dbf39f5 (patch) | |
tree | f36c1da9f07276a5ae8923f829d1ead4799f5b11 /posix-aio-compat.c | |
parent | 5d47e3728bbd589701f74bb494c9c9825ba23c88 (diff) |
Cosmetics
Avoid repeated creation/initalization/destruction of attr and calls to
getpid
git-svn-id: svn://svn.savannah.nongnu.org/qemu/trunk@6633 c046a42c-6fe2-441c-8c8c-71466251a162
Diffstat (limited to 'posix-aio-compat.c')
-rw-r--r-- | posix-aio-compat.c | 24 |
1 files changed, 13 insertions, 11 deletions
diff --git a/posix-aio-compat.c b/posix-aio-compat.c index 27b210cae..195691744 100644 --- a/posix-aio-compat.c +++ b/posix-aio-compat.c @@ -25,6 +25,7 @@ static pthread_mutex_t lock = PTHREAD_MUTEX_INITIALIZER; static pthread_cond_t cond = PTHREAD_COND_INITIALIZER; static pthread_t thread_id; +static pthread_attr_t attr; static int max_threads = 64; static int cur_threads = 0; static int idle_threads = 0; @@ -76,8 +77,11 @@ static void thread_create(pthread_t *thread, pthread_attr_t *attr, static void *aio_thread(void *unused) { + pid_t pid; sigset_t set; + pid = getpid(); + /* block all signals */ if (sigfillset(&set)) die("sigfillset"); if (sigprocmask(SIG_BLOCK, &set, NULL)) die("sigprocmask"); @@ -142,7 +146,7 @@ static void *aio_thread(void *unused) idle_threads++; mutex_unlock(&lock); - if (kill(getpid(), aiocb->ev_signo)) die("kill failed"); + if (kill(pid, aiocb->ev_signo)) die("kill failed"); } idle_threads--; @@ -154,23 +158,21 @@ static void *aio_thread(void *unused) static void spawn_thread(void) { - int ret; - pthread_attr_t attr; - cur_threads++; idle_threads++; - - ret = pthread_attr_init(&attr); - if (ret) die2 (ret, "pthread_attr_init"); - ret = pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_DETACHED); - if (ret) die2 (ret, "pthread_attr_setdetachstate"); thread_create(&thread_id, &attr, aio_thread, NULL); - ret = pthread_attr_destroy(&attr); - if (ret) die2 (ret, "pthread_attr_destroy"); } int qemu_paio_init(struct qemu_paioinit *aioinit) { + int ret; + + ret = pthread_attr_init(&attr); + if (ret) die2(ret, "pthread_attr_init"); + + ret = pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_DETACHED); + if (ret) die2(ret, "pthread_attr_setdetachstate"); + TAILQ_INIT(&request_list); return 0; |