From bacdc44b0b3754c50eb62648a3864c1d645c034d Mon Sep 17 00:00:00 2001 From: Dave West Date: Fri, 30 Nov 2007 16:59:08 +0000 Subject: [PATCH] Add a function try_critical_section() Just like begin_critical_section but this one returns non zero if the section is already busy. --- citadel/sysdep.c | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/citadel/sysdep.c b/citadel/sysdep.c index ae45dceec..520e02d2b 100644 --- a/citadel/sysdep.c +++ b/citadel/sysdep.c @@ -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. */ -- 2.39.2