2015-08-06 17:24:38 +00:00
|
|
|
#include <nan.h>
|
|
|
|
|
2015-08-07 01:58:01 +00:00
|
|
|
#define FUSE_USE_VERSION 29
|
|
|
|
|
2015-08-06 16:33:20 +00:00
|
|
|
#ifdef __APPLE__
|
|
|
|
|
|
|
|
// OS X
|
2015-08-06 19:33:27 +00:00
|
|
|
#include <sys/mount.h>
|
|
|
|
|
2015-08-06 16:33:20 +00:00
|
|
|
#include <semaphore.h>
|
2015-08-06 17:24:38 +00:00
|
|
|
#include <dispatch/dispatch.h>
|
2015-08-06 16:33:20 +00:00
|
|
|
|
2015-08-06 19:39:12 +00:00
|
|
|
#include <fuse_lowlevel.h>
|
|
|
|
|
|
|
|
#define FUSE_OFF_T off_t
|
|
|
|
|
2015-08-06 16:33:20 +00:00
|
|
|
typedef dispatch_semaphore_t bindings_sem_t;
|
|
|
|
|
|
|
|
NAN_INLINE static int semaphore_init (dispatch_semaphore_t *sem) {
|
|
|
|
*sem = dispatch_semaphore_create(0);
|
|
|
|
return *sem == NULL ? -1 : 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
NAN_INLINE static void semaphore_wait (dispatch_semaphore_t *sem) {
|
|
|
|
dispatch_semaphore_wait(*sem, DISPATCH_TIME_FOREVER);
|
|
|
|
}
|
|
|
|
|
|
|
|
NAN_INLINE static void semaphore_signal (dispatch_semaphore_t *sem) {
|
|
|
|
dispatch_semaphore_signal(*sem);
|
|
|
|
}
|
|
|
|
|
2015-08-06 17:24:38 +00:00
|
|
|
extern pthread_mutex_t mutex;
|
|
|
|
|
|
|
|
NAN_INLINE static void mutex_lock (pthread_mutex_t *mutex) {
|
|
|
|
pthread_mutex_lock(mutex);
|
|
|
|
}
|
|
|
|
|
|
|
|
NAN_INLINE static void mutex_unlock (pthread_mutex_t *mutex) {
|
|
|
|
pthread_mutex_unlock(mutex);
|
|
|
|
}
|
|
|
|
|
2015-08-07 01:51:38 +00:00
|
|
|
typedef pthread_t abstr_thread_t;
|
2015-08-06 19:33:27 +00:00
|
|
|
typedef void* thread_fn_rtn_t;
|
2015-08-06 17:24:38 +00:00
|
|
|
|
2015-08-06 19:33:27 +00:00
|
|
|
#elif defined(_WIN32)
|
|
|
|
|
|
|
|
#include <windows.h>
|
|
|
|
#include <io.h>
|
|
|
|
#include <winsock2.h>
|
|
|
|
|
|
|
|
typedef HANDLE bindings_sem_t;
|
|
|
|
|
|
|
|
NAN_INLINE static int semaphore_init (HANDLE *sem) {
|
|
|
|
*sem = CreateSemaphore(NULL, 0, 10, NULL);
|
|
|
|
return *sem == NULL ? -1 : 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
NAN_INLINE static void semaphore_wait (HANDLE *sem) {
|
|
|
|
WaitForSingleObject(*sem, INFINITE);
|
|
|
|
}
|
|
|
|
|
|
|
|
NAN_INLINE static void semaphore_signal (HANDLE *sem) {
|
|
|
|
ReleaseSemaphore(*sem, 1, NULL);
|
|
|
|
}
|
|
|
|
|
|
|
|
extern HANDLE mutex;
|
|
|
|
|
|
|
|
NAN_INLINE static void mutex_lock (HANDLE *mutex) {
|
|
|
|
WaitForSingleObject(*mutex, INFINITE);
|
|
|
|
}
|
|
|
|
|
|
|
|
NAN_INLINE static void mutex_unlock (HANDLE *mutex) {
|
|
|
|
ReleaseMutex(*mutex);
|
|
|
|
}
|
|
|
|
|
2015-08-07 01:51:38 +00:00
|
|
|
typedef HANDLE abstr_thread_t;
|
2015-08-06 19:33:27 +00:00
|
|
|
typedef DWORD thread_fn_rtn_t;
|
|
|
|
|
|
|
|
#define fuse_session_remove_chan(x)
|
|
|
|
#define stat _stati64
|
2015-08-06 17:24:38 +00:00
|
|
|
|
2015-08-06 16:33:20 +00:00
|
|
|
#else
|
|
|
|
|
|
|
|
// Linux and whatnot
|
2015-08-06 19:33:27 +00:00
|
|
|
#include <sys/mount.h>
|
|
|
|
|
2015-08-06 16:33:20 +00:00
|
|
|
#include <semaphore.h>
|
2015-08-06 19:39:12 +00:00
|
|
|
#include <fuse_lowlevel.h>
|
|
|
|
|
|
|
|
#define FUSE_OFF_T off_t
|
2015-08-06 16:33:20 +00:00
|
|
|
|
|
|
|
typedef sem_t bindings_sem_t;
|
|
|
|
|
|
|
|
NAN_INLINE static int semaphore_init (sem_t *sem) {
|
|
|
|
return sem_init(sem, 0, 0);
|
|
|
|
}
|
|
|
|
|
|
|
|
NAN_INLINE static void semaphore_wait (sem_t *sem) {
|
|
|
|
sem_wait(sem);
|
|
|
|
}
|
|
|
|
|
|
|
|
NAN_INLINE static void semaphore_signal (sem_t *sem) {
|
|
|
|
sem_post(sem);
|
|
|
|
}
|
|
|
|
|
2015-08-06 17:24:38 +00:00
|
|
|
extern pthread_mutex_t mutex;
|
|
|
|
|
|
|
|
NAN_INLINE static void mutex_lock (pthread_mutex_t *mutex) {
|
|
|
|
pthread_mutex_lock(mutex);
|
|
|
|
}
|
|
|
|
|
|
|
|
NAN_INLINE static void mutex_unlock (pthread_mutex_t *mutex) {
|
|
|
|
pthread_mutex_unlock(mutex);
|
|
|
|
}
|
|
|
|
|
2015-08-07 01:51:38 +00:00
|
|
|
typedef pthread_t abstr_thread_t;
|
2015-08-06 19:33:27 +00:00
|
|
|
typedef void* thread_fn_rtn_t;
|
|
|
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
typedef thread_fn_rtn_t(*thread_fn)(void*);
|
2015-08-06 17:24:38 +00:00
|
|
|
|
2015-08-07 01:51:38 +00:00
|
|
|
void thread_create (abstr_thread_t*, thread_fn, void*);
|
|
|
|
void thread_join (abstr_thread_t);
|
2015-08-06 17:24:38 +00:00
|
|
|
|
2016-10-17 11:50:38 +00:00
|
|
|
int fusermount (char*);
|