little locking rework
authorChristian Thaeter <ct@pipapo.org>
Fri, 9 Nov 2007 07:31:35 +0000 (08:31 +0100)
committerChristian Thaeter <ct@pipapo.org>
Fri, 9 Nov 2007 07:31:35 +0000 (08:31 +0100)
src/rxpd_connection_cmd.c
src/rxpd_file.c

index b6aae8b..8c206bf 100644 (file)
@@ -211,21 +211,17 @@ rxpd_connection_do_REPLACE (struct rxpd_connection* self)
 {
   struct rxpd_rule* rule;
 
-  pth_rwlock_acquire (&self->file->lock, PTH_RWLOCK_RW, FALSE, NULL);
-
   LLIST_FOREACH (&self->file->rules, n)
     {
       rule = (struct rxpd_rule*)n;
       if (strcmp (rule->string, self->tmp_str) == 0)
         goto found;
     }
-  pth_rwlock_release (&self->file->lock);
   return 0;
 
  found:
   llist_insertlist_next (&rule->node, &self->tmp_list);
   rxpd_rule_delete (rule);
-  pth_rwlock_release (&self->file->lock);
 
   free (self->tmp_str);
   self->tmp_str = NULL;
@@ -260,8 +256,6 @@ rxpd_connection_cmd_REPLACE (struct rxpd_connection* self)
         break;  /* exit at empty line, error or whatever */
     }
 
-  pth_rwlock_release (&self->file->lock);
-
   if (rxpd_buffer_state (&self->in) == RXPD_ERROR)
     rxpd_buffer_printf (&self->out, "#ERROR:\n");
 
@@ -269,6 +263,8 @@ rxpd_connection_cmd_REPLACE (struct rxpd_connection* self)
     rxpd_buffer_printf (&self->out, "#OK:\n");
   else
     rxpd_buffer_printf (&self->out, "#ERROR: no rule matching '%s'\n", self->tmp_str);
+
+  pth_rwlock_release (&self->file->lock);
 }
 
 void
index fb10fd4..a66a9b3 100644 (file)
@@ -58,8 +58,12 @@ rxpd_file_delete (struct rxpd_file* self)
 {
   if (self)
     {
-      rxpd_file_rules_delete (self);
+      /* psplay remove does not preempt, no locking needed */
+      /* pth_rwlock_acquire (&self->lock, PTH_RWLOCK_RW, FALSE, NULL); */
       psplay_remove (&self->base->files, &self->node);
+      /* pth_rwlock_release (&self->lock); */
+
+      rxpd_file_rules_delete (self);
 
       while (1) 
         {