diff options
author | Miklos Szeredi <miklos@szeredi.hu> | 2005-11-21 11:37:01 +0000 |
---|---|---|
committer | Miklos Szeredi <miklos@szeredi.hu> | 2005-11-21 11:37:01 +0000 |
commit | 8393e3d2285533a77d38cfe6713bbe2223802594 (patch) | |
tree | 06273dde0cc638f2645d1ab68f3f0d9c6405ce12 /lib/fuse_loop_mt.c | |
parent | 05c97845cdd649b31ba140f3b2c4784b94489673 (diff) |
fix
Diffstat (limited to 'lib/fuse_loop_mt.c')
-rw-r--r-- | lib/fuse_loop_mt.c | 11 |
1 files changed, 9 insertions, 2 deletions
diff --git a/lib/fuse_loop_mt.c b/lib/fuse_loop_mt.c index df254a9..95399d7 100644 --- a/lib/fuse_loop_mt.c +++ b/lib/fuse_loop_mt.c @@ -27,6 +27,7 @@ struct fuse_worker { struct fuse_chan *ch; struct fuse_chan *prevch; pthread_t threads[FUSE_MAX_WORKERS]; + int exit; int error; }; @@ -70,7 +71,7 @@ static void *do_work(void *data) pthread_cleanup_push(free, buf); pthread_setcancelstate(PTHREAD_CANCEL_ENABLE, NULL); - pthread_setcanceltype(PTHREAD_CANCEL_ASYNCHRONOUS, NULL); + pthread_setcanceltype(PTHREAD_CANCEL_DEFERRED, NULL); while (!fuse_session_exited(w->se)) { int res = fuse_chan_receive(w->prevch, buf, bufsize); @@ -83,6 +84,10 @@ static void *do_work(void *data) } pthread_mutex_lock(&w->lock); + if (w->exit) { + pthread_mutex_unlock(&w->lock); + break; + } w->numavail--; if (w->numavail == 0 && w->numworker < FUSE_MAX_WORKERS) { if (w->numworker < FUSE_MAX_WORKERS) { @@ -117,7 +122,6 @@ static int start_thread(struct fuse_worker *w, pthread_t *thread_id) return -1; } - pthread_detach(*thread_id); return 0; } @@ -153,7 +157,10 @@ int fuse_session_loop_mt(struct fuse_session *se) pthread_mutex_lock(&w->lock); for (i = 1; i < w->numworker; i++) pthread_cancel(w->threads[i]); + w->exit = 1; pthread_mutex_unlock(&w->lock); + for (i = 1; i < w->numworker; i++) + pthread_join(w->threads[i], NULL); pthread_mutex_destroy(&w->lock); err = w->error; fuse_chan_destroy(w->ch); |