Free all possibly held mutexes in error handlers

Now that we have 3 mutexes lying around, it's important that we check
and free these if necessary if error() is called in any thread that can
hold them.  To do this, we now have flexthread.c, which defines a
flexthread_mutex struct.  This is a wrapper around a pthread_mutex_t and
a pthread_t.  The idea is that in the error handler, the thread can
check whether it holds the mutex and can free it if and only if it does.
This is important because pthread fast mutexes can be freed by *any*
thread, not just the thread which holds them.

Note: it is only ever safe for a thread to check if it holds the mutex
itself.  It is *never* safe to check if another thread holds a mutex
without first locking that mutex, which makes the whole operation rather
pointless.
This commit is contained in:
Alex Young
2012-07-11 09:43:16 +01:00
parent 17fe6d3023
commit f3f017a87d
17 changed files with 351 additions and 70 deletions

View File

@@ -38,7 +38,7 @@ struct server {
uint64_t size;
/** Claims around any I/O to this file */
pthread_mutex_t l_io;
struct flexthread_mutex * l_io;
/** to interrupt accept loop and clients, write() to close_signal[1] */
struct self_pipe * close_signal;
@@ -49,7 +49,9 @@ struct server {
* has been replaced
*/
struct self_pipe * acl_updated_signal;
pthread_mutex_t l_acl;
/* Claimed around any updates to the ACL. */
struct flexthread_mutex * l_acl;
struct mirror_status* mirror;
struct mirror_super * mirror_super;
@@ -90,6 +92,11 @@ void server_replace_acl( struct server *serve, struct acl * acl);
void server_control_arrived( struct server *serve );
int server_is_in_control( struct server *serve );
int server_default_deny( struct server * serve );
int server_io_locked( struct server * serve );
int server_acl_locked( struct server * serve );
void server_lock_acl( struct server *serve );
void server_unlock_acl( struct server *serve );
int do_serve( struct server * );