aboutsummaryrefslogtreecommitdiffstats
path: root/lib/fuse_mt.c
diff options
context:
space:
mode:
authorMiklos Szeredi <miklos@szeredi.hu>2004-06-24 21:00:00 +0000
committerMiklos Szeredi <miklos@szeredi.hu>2004-06-24 21:00:00 +0000
commit1ea9c96e542d89c0244c172ef34a199f19d912fa (patch)
tree0d8a1c8a6958d9c0b889d215b8550e510e89abf8 /lib/fuse_mt.c
parentcb26451550ee7a9e321cc2fc1cc337579797ec30 (diff)
downloadlibfuse-1ea9c96e542d89c0244c172ef34a199f19d912fa.tar.gz
close after delete support
Diffstat (limited to 'lib/fuse_mt.c')
-rw-r--r--lib/fuse_mt.c33
1 files changed, 24 insertions, 9 deletions
diff --git a/lib/fuse_mt.c b/lib/fuse_mt.c
index aa9dc7e..afc70d4 100644
--- a/lib/fuse_mt.c
+++ b/lib/fuse_mt.c
@@ -20,17 +20,21 @@
struct fuse_worker {
struct fuse *f;
+ pthread_t threads[FUSE_MAX_WORKERS];
void *data;
fuse_processor_t proc;
};
-static void start_thread(struct fuse_worker *w);
+static void start_thread(struct fuse_worker *w, pthread_t *thread_id);
static void *do_work(void *data)
{
struct fuse_worker *w = (struct fuse_worker *) data;
struct fuse *f = w->f;
+ pthread_setcancelstate(PTHREAD_CANCEL_ENABLE, NULL);
+ pthread_setcanceltype(PTHREAD_CANCEL_ASYNCHRONOUS, NULL);
+
while (1) {
struct fuse_cmd *cmd;
@@ -43,10 +47,14 @@ static void *do_work(void *data)
if (f->numavail == 0 && f->numworker < FUSE_MAX_WORKERS) {
pthread_mutex_lock(&f->lock);
- f->numavail ++;
- f->numworker ++;
- pthread_mutex_unlock(&f->lock);
- start_thread(w);
+ if (f->numworker < FUSE_MAX_WORKERS) {
+ pthread_t *thread_id = &w->threads[f->numworker];
+ f->numavail ++;
+ f->numworker ++;
+ pthread_mutex_unlock(&f->lock);
+ start_thread(w, thread_id);
+ } else
+ pthread_mutex_unlock(&f->lock);
}
w->proc(w->f, cmd, w->data);
@@ -55,9 +63,8 @@ static void *do_work(void *data)
return NULL;
}
-static void start_thread(struct fuse_worker *w)
+static void start_thread(struct fuse_worker *w, pthread_t *thread_id)
{
- pthread_t thrid;
sigset_t oldset;
sigset_t newset;
int res;
@@ -65,13 +72,14 @@ static void start_thread(struct fuse_worker *w)
/* Disallow signal reception in worker threads */
sigfillset(&newset);
pthread_sigmask(SIG_SETMASK, &newset, &oldset);
- res = pthread_create(&thrid, NULL, do_work, w);
+ res = pthread_create(thread_id, NULL, do_work, w);
pthread_sigmask(SIG_SETMASK, &oldset, NULL);
if (res != 0) {
fprintf(stderr, "Error creating thread: %s\n", strerror(res));
exit(1);
}
- pthread_detach(thrid);
+
+ pthread_detach(*thread_id);
}
static struct fuse_context *mt_getcontext(struct fuse *f)
@@ -96,8 +104,10 @@ void __fuse_loop_mt(struct fuse *f, fuse_processor_t proc, void *data)
{
struct fuse_worker *w;
int res;
+ int i;
w = malloc(sizeof(struct fuse_worker));
+ memset(w, 0, sizeof(struct fuse_worker));
w->f = f;
w->data = data;
w->proc = proc;
@@ -110,6 +120,11 @@ void __fuse_loop_mt(struct fuse *f, fuse_processor_t proc, void *data)
}
f->getcontext = mt_getcontext;
do_work(w);
+
+ pthread_mutex_lock(&f->lock);
+ for (i = 1; i < f->numworker; i++)
+ pthread_cancel(w->threads[i]);
+ pthread_mutex_unlock(&f->lock);
}
void fuse_loop_mt(struct fuse *f)