aboutsummaryrefslogtreecommitdiff
path: root/lib/fuse_loop_mt.c
diff options
context:
space:
mode:
Diffstat (limited to 'lib/fuse_loop_mt.c')
-rwxr-xr-xlib/fuse_loop_mt.c30
1 files changed, 9 insertions, 21 deletions
diff --git a/lib/fuse_loop_mt.c b/lib/fuse_loop_mt.c
index 82e3001..b146d73 100755
--- a/lib/fuse_loop_mt.c
+++ b/lib/fuse_loop_mt.c
@@ -28,7 +28,7 @@ struct fuse_worker {
struct fuse_worker *next;
pthread_t thread_id;
size_t bufsize;
- char *buf;
+ struct fuse_buf fbuf;
struct fuse_mt *mt;
};
@@ -70,15 +70,10 @@ static void *fuse_do_work(void *data)
while (!fuse_session_exited(mt->se)) {
int isforget = 0;
- struct fuse_chan *ch = mt->prevch;
- struct fuse_buf fbuf = {
- .mem = w->buf,
- .size = w->bufsize,
- };
int res;
pthread_setcancelstate(PTHREAD_CANCEL_ENABLE, NULL);
- res = fuse_session_receive_buf(mt->se, &fbuf, &ch);
+ res = fuse_session_receive_buf(mt->se, &w->fbuf, mt->prevch);
pthread_setcancelstate(PTHREAD_CANCEL_DISABLE, NULL);
if (res == -EINTR)
continue;
@@ -100,8 +95,8 @@ static void *fuse_do_work(void *data)
* This disgusting hack is needed so that zillions of threads
* are not created on a burst of FORGET messages
*/
- if (!(fbuf.flags & FUSE_BUF_IS_FD)) {
- struct fuse_in_header *in = fbuf.mem;
+ if (!(w->fbuf.flags & FUSE_BUF_IS_FD)) {
+ struct fuse_in_header *in = w->fbuf.mem;
if (in->opcode == FUSE_FORGET ||
in->opcode == FUSE_BATCH_FORGET)
@@ -114,7 +109,7 @@ static void *fuse_do_work(void *data)
fuse_loop_start_thread(mt);
pthread_mutex_unlock(&mt->lock);
- fuse_session_process_buf(mt->se, &fbuf, ch);
+ fuse_session_process_buf(mt->se, &w->fbuf, mt->prevch);
pthread_mutex_lock(&mt->lock);
if (!isforget)
@@ -130,7 +125,7 @@ static void *fuse_do_work(void *data)
pthread_mutex_unlock(&mt->lock);
pthread_detach(w->thread_id);
- free(w->buf);
+ free(w->fbuf.mem);
free(w);
return NULL;
}
@@ -184,18 +179,11 @@ static int fuse_loop_start_thread(struct fuse_mt *mt)
return -1;
}
memset(w, 0, sizeof(struct fuse_worker));
- w->bufsize = fuse_chan_bufsize(mt->prevch);
- w->buf = malloc(w->bufsize);
+ w->fbuf.mem = NULL;
w->mt = mt;
- if (!w->buf) {
- fprintf(stderr, "fuse: failed to allocate read buffer\n");
- free(w);
- return -1;
- }
res = fuse_start_thread(&w->thread_id, fuse_do_work, w);
if (res == -1) {
- free(w->buf);
free(w);
return -1;
}
@@ -212,7 +200,7 @@ static void fuse_join_worker(struct fuse_mt *mt, struct fuse_worker *w)
pthread_mutex_lock(&mt->lock);
list_del_worker(w);
pthread_mutex_unlock(&mt->lock);
- free(w->buf);
+ free(w->fbuf.mem);
free(w);
}
@@ -224,7 +212,7 @@ int fuse_session_loop_mt(struct fuse_session *se)
memset(&mt, 0, sizeof(struct fuse_mt));
mt.se = se;
- mt.prevch = fuse_session_next_chan(se, NULL);
+ mt.prevch = fuse_session_chan(se);
mt.error = 0;
mt.numworker = 0;
mt.numavail = 0;