diff src/c/urweb.c @ 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 4df4521fbd3b
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;
 }