Add a function try_critical_section()
authorDave West <davew@uncensored.citadel.org>
Fri, 30 Nov 2007 16:59:08 +0000 (16:59 +0000)
committerDave West <davew@uncensored.citadel.org>
Fri, 30 Nov 2007 16:59:08 +0000 (16:59 +0000)
Just like begin_critical_section but this one returns non zero if the
section is already busy.

citadel/sysdep.c

index ae45dceecd45e0f2fbb425d2fc66a3a163f17fcc..520e02d2b39ec43241a2d958d50e871d37d512f2 100644 (file)
@@ -262,6 +262,29 @@ void init_sysdep(void) {
 }
 
 
+
+/*
+ * Obtain a semaphore lock to begin a critical section.
+ * but only if no one else has one
+ */
+int try_critical_section(int which_one)
+{
+       /* For all types of critical sections except those listed here,
+        * ensure nobody ever tries to do a critical section within a
+        * transaction; this could lead to deadlock.
+        */
+       if (    (which_one != S_FLOORCACHE)
+#ifdef DEBUG_MEMORY_LEAKS
+               && (which_one != S_DEBUGMEMLEAKS)
+#endif
+               && (which_one != S_RPLIST)
+       ) {
+               cdb_check_handles();
+       }
+       return (pthread_mutex_trylock(&Critters[which_one]));
+}
+
+
 /*
  * Obtain a semaphore lock to begin a critical section.
  */