diff options
author | Richard Braun <rbraun@sceen.net> | 2012-09-03 16:17:09 +0200 |
---|---|---|
committer | Samuel Thibault <samuel.thibault@ens-lyon.org> | 2012-11-24 18:24:55 +0100 |
commit | 628eb5a1fb4bbb2ddcd386500fe9d7241cf7f474 (patch) | |
tree | 64a5a6579ec3c87422997b00fee17beea0ac9789 | |
parent | b8b7940234ed7b06cb81f49210b165c47d44a1f1 (diff) |
Reduce contention on thread creation in libports
* libports/manage-multithread.c (ports_manage_port_operations_multithread):
Don't drop the lock when determining if a new thread must be created.
-rw-r--r-- | libports/manage-multithread.c | 14 |
1 files changed, 5 insertions, 9 deletions
diff --git a/libports/manage-multithread.c b/libports/manage-multithread.c index c25bfd38..309b3038 100644 --- a/libports/manage-multithread.c +++ b/libports/manage-multithread.c @@ -74,8 +74,8 @@ ports_manage_port_operations_multithread (struct port_bucket *bucket, int global_timeout, void (*hook)()) { - volatile int nreqthreads; - volatile int totalthreads; + volatile unsigned int nreqthreads; + volatile unsigned int totalthreads; spin_lock_t lock = SPIN_LOCK_INITIALIZER; auto int thread_function (int); @@ -84,7 +84,6 @@ ports_manage_port_operations_multithread (struct port_bucket *bucket, internal_demuxer (mach_msg_header_t *inp, mach_msg_header_t *outheadp) { - int spawn = 0; int status; struct port_info *pi; struct rpc_info link; @@ -102,14 +101,11 @@ ports_manage_port_operations_multithread (struct port_bucket *bucket, spin_lock (&lock); assert (nreqthreads); nreqthreads--; - if (nreqthreads == 0) + if (nreqthreads != 0) + spin_unlock (&lock); + else /* No thread would be listening for requests, spawn one. */ - spawn = 1; - spin_unlock (&lock); - - if (spawn) { - spin_lock (&lock); totalthreads++; nreqthreads++; spin_unlock (&lock); |