Skip to content

Commit

Permalink
cygfuse: improve cygfuse initialization
Browse files Browse the repository at this point in the history
  • Loading branch information
billziss-gh committed May 17, 2017
1 parent 4ea9c6e commit 18a77d6
Show file tree
Hide file tree
Showing 5 changed files with 25 additions and 6 deletions.
29 changes: 23 additions & 6 deletions opt/cygfuse/cygfuse.c
Original file line number Diff line number Diff line change
Expand Up @@ -22,18 +22,34 @@
#include <unistd.h>
#include <sys/cygwin.h>

static void *cygfuse_init_slow(int force);
static void *cygfuse_init_winfsp();
static void *cygfuse_init_fail();

static pthread_mutex_t cygfuse_mutex = PTHREAD_MUTEX_INITIALIZER;
static void *cygfuse_handle = 0;

static inline void cygfuse_init(int force)
static inline void *cygfuse_init_fast(void)
{
void *handle = cygfuse_handle;
__sync_synchronize(); /* memory barrier */
if (0 == handle)
handle = cygfuse_init_slow(0);
return handle;
}

static void *cygfuse_init_slow(int force)
{
void *handle;
pthread_mutex_lock(&cygfuse_mutex);
if (force || 0 == cygfuse_handle)
cygfuse_handle = cygfuse_init_winfsp();
handle = cygfuse_handle;
if (force || 0 == handle)
{
handle = cygfuse_init_winfsp();
__sync_synchronize(); /* memory barrier */
cygfuse_handle = handle;
}
pthread_mutex_unlock(&cygfuse_mutex);
return handle;
}

/*
Expand All @@ -51,15 +67,15 @@ static inline int cygfuse_daemon(int nochdir, int noclose)
return -1;

/* force reload of WinFsp DLL to workaround fork() problems */
cygfuse_init(1);
cygfuse_init_slow(1);

return 0;
}
#define daemon cygfuse_daemon

#define FSP_FUSE_API static
#define FSP_FUSE_API_NAME(api) (* pfn_ ## api)
#define FSP_FUSE_API_CALL(api) (cygfuse_init(0), pfn_ ## api)
#define FSP_FUSE_API_CALL(api) (cygfuse_init_fast(), pfn_ ## api)
#define FSP_FUSE_SYM(proto, ...) __attribute__ ((visibility("default"))) proto { __VA_ARGS__ }
#include <fuse_common.h>
#include <fuse.h>
Expand All @@ -75,6 +91,7 @@ static inline int cygfuse_daemon(int nochdir, int noclose)
if (0 == (*(void **)&(pfn_ ## n) = dlsym(h, #n)))\
return cygfuse_init_fail();

static void *cygfuse_init_fail();
static void *cygfuse_init_winfsp()
{
void *h;
Expand Down
1 change: 1 addition & 0 deletions opt/cygfuse/dist/install.sh
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,4 @@ x86_64)
*)
tar -C/ -xaf x86/fuse-2.8-*.tar.xz ;;
esac
echo FUSE for Cygwin installed.
1 change: 1 addition & 0 deletions opt/cygfuse/dist/uninstall.sh
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,4 @@ x86_64)
*)
tar -taf x86/fuse-2.8-*.tar.xz | sed -e '/\/$/d' -e 's/.*/\/&/' | xargs rm -f ;;
esac
echo FUSE for Cygwin uninstalled.
Binary file modified opt/cygfuse/dist/x64/fuse-2.8-5.tar.xz
Binary file not shown.
Binary file modified opt/cygfuse/dist/x86/fuse-2.8-5.tar.xz
Binary file not shown.

0 comments on commit 18a77d6

Please sign in to comment.