From: Miklos Szeredi Date: Thu, 26 Apr 2007 20:29:12 +0000 (+0000) Subject: In multithreaded loop, use a semaphore instead of SIGHUP... X-Git-Tag: fuse_2_7_0_rc1~8 X-Git-Url: http://git.maquefel.me/?a=commitdiff_plain;h=ccf0be03c3f6ec094b18c53c0606dafadb1e5423;p=qemu-gpiodev%2Flibfuse.git In multithreaded loop, use a semaphore instead of SIGHUP... --- diff --git a/ChangeLog b/ChangeLog index b5f83b6..4f27cec 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,9 @@ +2007-04-26 Miklos Szeredi + + * In multithreaded loop, use a semaphore instead of SIGHUP to wake + up the main thread on umount. This is more elegant, and works + even if signals are blocked. + 2007-04-25 Miklos Szeredi * Improve mounting support in libfuse: diff --git a/lib/fuse_loop_mt.c b/lib/fuse_loop_mt.c index 6af20ae..c626ba6 100644 --- a/lib/fuse_loop_mt.c +++ b/lib/fuse_loop_mt.c @@ -14,6 +14,7 @@ #include #include #include +#include #include #include @@ -33,6 +34,7 @@ struct fuse_mt { struct fuse_session *se; struct fuse_chan *prevch; struct fuse_worker main; + sem_t finish; int exit; int error; }; @@ -106,7 +108,7 @@ static void *fuse_do_work(void *data) pthread_mutex_unlock(&mt->lock); } - pthread_kill(mt->main.thread_id, SIGHUP); + sem_post(&mt->finish); pause(); return NULL; @@ -176,14 +178,16 @@ int fuse_session_loop_mt(struct fuse_session *se) mt.numavail = 0; mt.main.thread_id = pthread_self(); mt.main.prev = mt.main.next = &mt.main; + sem_init(&mt.finish, 0, 0); fuse_mutex_init(&mt.lock); pthread_mutex_lock(&mt.lock); err = fuse_start_thread(&mt); pthread_mutex_unlock(&mt.lock); if (!err) { + /* sem_wait() is interruptible */ while (!fuse_session_exited(se)) - pause(); + sem_wait(&mt.finish); for (w = mt.main.next; w != &mt.main; w = w->next) pthread_cancel(w->thread_id); @@ -197,6 +201,7 @@ int fuse_session_loop_mt(struct fuse_session *se) } pthread_mutex_destroy(&mt.lock); + sem_destroy(&mt.finish); fuse_session_reset(se); return err; }