aboutsummaryrefslogtreecommitdiffstats
path: root/lib/fuse_mt.c
diff options
context:
space:
mode:
authorMiklos Szeredi <miklos@szeredi.hu>2001-11-16 13:31:14 +0000
committerMiklos Szeredi <miklos@szeredi.hu>2001-11-16 13:31:14 +0000
commit680a69a8be8b7dd9bf1beae4e48e927d0fb1cd7f (patch)
treee3c27e1c3144210621cd30a7f7c3d762ce6b5249 /lib/fuse_mt.c
parentfff56ab1242e3ad7cddf15e7e981da55d06c4da5 (diff)
downloadlibfuse-680a69a8be8b7dd9bf1beae4e48e927d0fb1cd7f.tar.gz
threading fixes
Diffstat (limited to 'lib/fuse_mt.c')
-rw-r--r--lib/fuse_mt.c25
1 files changed, 16 insertions, 9 deletions
diff --git a/lib/fuse_mt.c b/lib/fuse_mt.c
index ac616fe..6afc3bc 100644
--- a/lib/fuse_mt.c
+++ b/lib/fuse_mt.c
@@ -13,25 +13,27 @@
#include <string.h>
#include <errno.h>
#include <pthread.h>
+#include <semaphore.h>
#include <signal.h>
#include <sys/time.h>
-
struct thread_common {
struct fuse *f;
struct fuse_cmd *cmd;
pthread_mutex_t lock;
pthread_cond_t cond;
+ sem_t started;
int avail;
};
-/* Called with c->lock held */
static void *do_work(void *data)
{
struct thread_common *c = (struct thread_common *) data;
- struct fuse *f = c->f;
+ pthread_mutex_lock(&c->lock);
+ sem_post(&c->started);
c->avail ++;
+
while(1) {
int res;
struct timespec timeout;
@@ -52,13 +54,13 @@ static void *do_work(void *data)
c->cmd = NULL;
c->avail --;
pthread_mutex_unlock(&c->lock);
- __fuse_process_cmd(f, cmd);
+ __fuse_process_cmd(c->f, cmd);
pthread_mutex_lock(&c->lock);
c->avail ++;
}
c->avail --;
- pthread_mutex_unlock(&c->lock);
+ pthread_mutex_unlock(&c->lock);
return NULL;
}
@@ -70,19 +72,23 @@ static void start_thread(struct thread_common *c)
sigset_t newset;
int res;
+ pthread_mutex_unlock(&c->lock);
+
pthread_attr_init(&attr);
pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_DETACHED);
/* Disallow signal reception in worker threads */
sigfillset(&newset);
- sigprocmask(SIG_SETMASK, &newset, &oldset);
+ pthread_sigmask(SIG_SETMASK, &newset, &oldset);
res = pthread_create(&thrid, &attr, do_work, c);
- sigprocmask(SIG_SETMASK, &oldset, NULL);
- pthread_mutex_lock(&c->lock);
+ pthread_sigmask(SIG_SETMASK, &oldset, NULL);
if(res != 0) {
fprintf(stderr, "Error creating thread: %s\n", strerror(res));
exit(1);
}
+
+ sem_wait(&c->started);
+ pthread_mutex_lock(&c->lock);
}
void fuse_loop_mt(struct fuse *f)
@@ -94,6 +100,7 @@ void fuse_loop_mt(struct fuse *f)
c->cmd = NULL;
pthread_cond_init(&c->cond, NULL);
pthread_mutex_init(&c->lock, NULL);
+ sem_init(&c->started, 0, 0);
c->avail = 0;
while(1) {
@@ -102,9 +109,9 @@ void fuse_loop_mt(struct fuse *f)
exit(1);
pthread_mutex_lock(&c->lock);
- c->cmd = cmd;
while(c->avail == 0)
start_thread(c);
+ c->cmd = cmd;
pthread_cond_signal(&c->cond);
pthread_mutex_unlock(&c->lock);
}