fixed potential deadlocks for MERGE UPDATE and FILTER
authorChristian Thaeter <ct@pipapo.org>
Fri, 9 Nov 2007 07:30:35 +0000 (08:30 +0100)
committerChristian Thaeter <ct@pipapo.org>
Fri, 9 Nov 2007 07:30:35 +0000 (08:30 +0100)
src/rxpd.h
src/rxpd_base.c
src/rxpd_connection_cmd.c

index 07b7bd2..851fd1d 100644 (file)
@@ -110,6 +110,12 @@ struct rxpd_base
 
   pth_t main;
 
+  /* we have few operations which operate on two or more lists (UPDATE, MERGE, FILTER),
+     just using this big lock to serialize these.
+     Other strategies like timed_lock/rollback might be implemented later
+  */
+  pth_mutex_t nest_lock;
+
   // TODO
   //FILE* -l log      log hits to logfile
 
index d4545aa..cedcdb7 100644 (file)
@@ -38,6 +38,7 @@ rxpd_init (void)
   global_base.user = NULL;
   global_base.policy = NULL;
   global_base.main = pth_self ();
+  pth_mutex_init (&global_base.nest_lock);
 
   psplay_init_root (&global_base.files, rxpd_file_cmp, (psplay_delete_t)rxpd_file_delete);
   llist_init (&global_base.sockets);
index f250202..b6aae8b 100644 (file)
@@ -517,6 +517,7 @@ rxpd_connection_cmd_UPDATE (struct rxpd_connection* self)
 
   struct rxpd_base* base = self->socket->base;
 
+  pth_mutex_acquire (&base->nest_lock, 0, NULL);
   pth_rwlock_acquire (&self->file->lock, PTH_RWLOCK_RW, FALSE, NULL);
 
   char* line;
@@ -595,6 +596,7 @@ rxpd_connection_cmd_UPDATE (struct rxpd_connection* self)
     }
 
   pth_rwlock_release (&self->file->lock);
+  pth_mutex_release (&base->nest_lock);
 
   rxpd_buffer_printf (&self->out, "#OK:\n");
 }
@@ -607,6 +609,7 @@ rxpd_connection_cmd_MERGE (struct rxpd_connection* self)
 
   struct rxpd_base* base = self->socket->base;
 
+  pth_mutex_acquire (&base->nest_lock, 0, NULL);
   pth_rwlock_acquire (&self->file->lock, PTH_RWLOCK_RW, FALSE, NULL);
 
   char* line;
@@ -668,6 +671,7 @@ rxpd_connection_cmd_MERGE (struct rxpd_connection* self)
     }
 
   pth_rwlock_release (&self->file->lock);
+  pth_mutex_release (&base->nest_lock);
 
   rxpd_buffer_printf (&self->out, "#OK:\n");
 }
@@ -685,6 +689,7 @@ rxpd_connection_cmd_FILTER (struct rxpd_connection* self)
 
   struct rxpd_base* base = self->socket->base;
 
+  pth_mutex_acquire (&base->nest_lock, 0, NULL);
   pth_rwlock_acquire (&self->file->lock, PTH_RWLOCK_RW, FALSE, NULL);
 
   char* line;
@@ -750,6 +755,7 @@ rxpd_connection_cmd_FILTER (struct rxpd_connection* self)
     }
 
   pth_rwlock_release (&self->file->lock);
+  pth_mutex_release (&base->nest_lock);
 
   rxpd_buffer_printf (&self->out, "#OK:\n");
 }