changeset 1708:e263dab7b579

Optimize code from last changeset a bit
author Adam Chlipala <adam@chlipala.net>
date Sun, 08 Apr 2012 16:29:28 -0400
parents c05e2e4bdde7
children 4600cc5e335c
files src/c/urweb.c
diffstat 1 files changed, 5 insertions(+), 4 deletions(-) [+]
line wrap: on
line diff
--- a/src/c/urweb.c	Sun Apr 08 16:24:16 2012 -0400
+++ b/src/c/urweb.c	Sun Apr 08 16:29:28 2012 -0400
@@ -229,17 +229,18 @@
 
 static client *find_client(unsigned id) {
   client *c;
-
-  if (!pruning_thread_initialized || !pthread_equal(pruning_thread, pthread_self())) pthread_mutex_lock(&clients_mutex);
+  int i_am_pruner = pruning_thread_initialized && pthread_equal(pruning_thread, pthread_self());
+
+  if (!i_am_pruner) pthread_mutex_lock(&clients_mutex);
 
   if (id >= n_clients) {
-    if (!pruning_thread_initialized || !pthread_equal(pruning_thread, pthread_self())) pthread_mutex_unlock(&clients_mutex);
+    if (!i_am_pruner) pthread_mutex_unlock(&clients_mutex);
     return NULL;
   }
 
   c = clients[id];
 
-  if (!pruning_thread_initialized || !pthread_equal(pruning_thread, pthread_self())) pthread_mutex_unlock(&clients_mutex);
+  if (!i_am_pruner) pthread_mutex_unlock(&clients_mutex);
   return c;
 }