aboutsummaryrefslogtreecommitdiff
path: root/lib/fuse_loop_mt.c
diff options
context:
space:
mode:
authorGravatar therealneworld@gmail.com <therealneworld@gmail.com>2011-06-02 14:27:02 +0200
committerGravatar Miklos Szeredi <mszeredi@suse.cz>2011-06-02 14:27:02 +0200
commit94c2b63955271d039c62e7c966aa82c9565d28ec (patch)
treea47133690e8d1a5aca9351dd8803e2e5fc4c5dc3 /lib/fuse_loop_mt.c
parent4a9f6ab4805d805ac3b437c89d11ae365a0370f3 (diff)
add "remember" option
This works similar to "noforget" except that eventually the node will be allowed to expire from the cache.
Diffstat (limited to 'lib/fuse_loop_mt.c')
-rw-r--r--lib/fuse_loop_mt.c51
1 files changed, 32 insertions, 19 deletions
diff --git a/lib/fuse_loop_mt.c b/lib/fuse_loop_mt.c
index ab5fd11..b5ad1c7 100644
--- a/lib/fuse_loop_mt.c
+++ b/lib/fuse_loop_mt.c
@@ -9,6 +9,7 @@
#include "fuse_lowlevel.h"
#include "fuse_misc.h"
#include "fuse_kernel.h"
+#include "fuse_i.h"
#include <stdio.h>
#include <stdlib.h>
@@ -60,7 +61,7 @@ static void list_del_worker(struct fuse_worker *w)
next->prev = prev;
}
-static int fuse_start_thread(struct fuse_mt *mt);
+static int fuse_loop_start_thread(struct fuse_mt *mt);
static void *fuse_do_work(void *data)
{
@@ -110,7 +111,7 @@ static void *fuse_do_work(void *data)
if (!isforget)
mt->numavail--;
if (mt->numavail == 0)
- fuse_start_thread(mt);
+ fuse_loop_start_thread(mt);
pthread_mutex_unlock(&mt->lock);
fuse_session_process_buf(mt->se, &fbuf, ch);
@@ -141,27 +142,13 @@ static void *fuse_do_work(void *data)
return NULL;
}
-static int fuse_start_thread(struct fuse_mt *mt)
+int fuse_start_thread(pthread_t *thread_id, void *(*func)(void *), void *arg)
{
sigset_t oldset;
sigset_t newset;
int res;
pthread_attr_t attr;
char *stack_size;
- struct fuse_worker *w = malloc(sizeof(struct fuse_worker));
- if (!w) {
- fprintf(stderr, "fuse: failed to allocate worker structure\n");
- return -1;
- }
- memset(w, 0, sizeof(struct fuse_worker));
- w->bufsize = fuse_chan_bufsize(mt->prevch);
- w->buf = malloc(w->bufsize);
- w->mt = mt;
- if (!w->buf) {
- fprintf(stderr, "fuse: failed to allocate read buffer\n");
- free(w);
- return -1;
- }
/* Override default stack size */
pthread_attr_init(&attr);
@@ -176,12 +163,38 @@ static int fuse_start_thread(struct fuse_mt *mt)
sigaddset(&newset, SIGHUP);
sigaddset(&newset, SIGQUIT);
pthread_sigmask(SIG_BLOCK, &newset, &oldset);
- res = pthread_create(&w->thread_id, &attr, fuse_do_work, w);
+ res = pthread_create(thread_id, &attr, func, arg);
pthread_sigmask(SIG_SETMASK, &oldset, NULL);
pthread_attr_destroy(&attr);
if (res != 0) {
fprintf(stderr, "fuse: error creating thread: %s\n",
strerror(res));
+ return -1;
+ }
+
+ return 0;
+}
+
+static int fuse_loop_start_thread(struct fuse_mt *mt)
+{
+ int res;
+ struct fuse_worker *w = malloc(sizeof(struct fuse_worker));
+ if (!w) {
+ fprintf(stderr, "fuse: failed to allocate worker structure\n");
+ return -1;
+ }
+ memset(w, 0, sizeof(struct fuse_worker));
+ w->bufsize = fuse_chan_bufsize(mt->prevch);
+ w->buf = malloc(w->bufsize);
+ 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;
@@ -221,7 +234,7 @@ int fuse_session_loop_mt(struct fuse_session *se)
fuse_mutex_init(&mt.lock);
pthread_mutex_lock(&mt.lock);
- err = fuse_start_thread(&mt);
+ err = fuse_loop_start_thread(&mt);
pthread_mutex_unlock(&mt.lock);
if (!err) {
/* sem_wait() is interruptible */