Commit a8227a5a200f1bb52ecd0f1a96b24d2e2dbf39f5
1 parent
5d47e372
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
Showing
1 changed file
with
13 additions
and
11 deletions
posix-aio-compat.c
| @@ -25,6 +25,7 @@ | @@ -25,6 +25,7 @@ | ||
| 25 | static pthread_mutex_t lock = PTHREAD_MUTEX_INITIALIZER; | 25 | static pthread_mutex_t lock = PTHREAD_MUTEX_INITIALIZER; |
| 26 | static pthread_cond_t cond = PTHREAD_COND_INITIALIZER; | 26 | static pthread_cond_t cond = PTHREAD_COND_INITIALIZER; |
| 27 | static pthread_t thread_id; | 27 | static pthread_t thread_id; |
| 28 | +static pthread_attr_t attr; | ||
| 28 | static int max_threads = 64; | 29 | static int max_threads = 64; |
| 29 | static int cur_threads = 0; | 30 | static int cur_threads = 0; |
| 30 | static int idle_threads = 0; | 31 | static int idle_threads = 0; |
| @@ -76,8 +77,11 @@ static void thread_create(pthread_t *thread, pthread_attr_t *attr, | @@ -76,8 +77,11 @@ static void thread_create(pthread_t *thread, pthread_attr_t *attr, | ||
| 76 | 77 | ||
| 77 | static void *aio_thread(void *unused) | 78 | static void *aio_thread(void *unused) |
| 78 | { | 79 | { |
| 80 | + pid_t pid; | ||
| 79 | sigset_t set; | 81 | sigset_t set; |
| 80 | 82 | ||
| 83 | + pid = getpid(); | ||
| 84 | + | ||
| 81 | /* block all signals */ | 85 | /* block all signals */ |
| 82 | if (sigfillset(&set)) die("sigfillset"); | 86 | if (sigfillset(&set)) die("sigfillset"); |
| 83 | if (sigprocmask(SIG_BLOCK, &set, NULL)) die("sigprocmask"); | 87 | if (sigprocmask(SIG_BLOCK, &set, NULL)) die("sigprocmask"); |
| @@ -142,7 +146,7 @@ static void *aio_thread(void *unused) | @@ -142,7 +146,7 @@ static void *aio_thread(void *unused) | ||
| 142 | idle_threads++; | 146 | idle_threads++; |
| 143 | mutex_unlock(&lock); | 147 | mutex_unlock(&lock); |
| 144 | 148 | ||
| 145 | - if (kill(getpid(), aiocb->ev_signo)) die("kill failed"); | 149 | + if (kill(pid, aiocb->ev_signo)) die("kill failed"); |
| 146 | } | 150 | } |
| 147 | 151 | ||
| 148 | idle_threads--; | 152 | idle_threads--; |
| @@ -154,23 +158,21 @@ static void *aio_thread(void *unused) | @@ -154,23 +158,21 @@ static void *aio_thread(void *unused) | ||
| 154 | 158 | ||
| 155 | static void spawn_thread(void) | 159 | static void spawn_thread(void) |
| 156 | { | 160 | { |
| 157 | - int ret; | ||
| 158 | - pthread_attr_t attr; | ||
| 159 | - | ||
| 160 | cur_threads++; | 161 | cur_threads++; |
| 161 | idle_threads++; | 162 | idle_threads++; |
| 162 | - | ||
| 163 | - ret = pthread_attr_init(&attr); | ||
| 164 | - if (ret) die2 (ret, "pthread_attr_init"); | ||
| 165 | - ret = pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_DETACHED); | ||
| 166 | - if (ret) die2 (ret, "pthread_attr_setdetachstate"); | ||
| 167 | thread_create(&thread_id, &attr, aio_thread, NULL); | 163 | thread_create(&thread_id, &attr, aio_thread, NULL); |
| 168 | - ret = pthread_attr_destroy(&attr); | ||
| 169 | - if (ret) die2 (ret, "pthread_attr_destroy"); | ||
| 170 | } | 164 | } |
| 171 | 165 | ||
| 172 | int qemu_paio_init(struct qemu_paioinit *aioinit) | 166 | int qemu_paio_init(struct qemu_paioinit *aioinit) |
| 173 | { | 167 | { |
| 168 | + int ret; | ||
| 169 | + | ||
| 170 | + ret = pthread_attr_init(&attr); | ||
| 171 | + if (ret) die2(ret, "pthread_attr_init"); | ||
| 172 | + | ||
| 173 | + ret = pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_DETACHED); | ||
| 174 | + if (ret) die2(ret, "pthread_attr_setdetachstate"); | ||
| 175 | + | ||
| 174 | TAILQ_INIT(&request_list); | 176 | TAILQ_INIT(&request_list); |
| 175 | 177 | ||
| 176 | return 0; | 178 | return 0; |