mirror of
https://github.com/fuse-friends/fuse-native
synced 2024-10-27 18:34:01 +00:00
move semaphore abstractions to header file
This commit is contained in:
parent
1804062e26
commit
a6192b1ad2
40
abstractions.h
Normal file
40
abstractions.h
Normal file
@ -0,0 +1,40 @@
|
|||||||
|
#ifdef __APPLE__
|
||||||
|
|
||||||
|
// OS X
|
||||||
|
#include <semaphore.h>
|
||||||
|
|
||||||
|
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);
|
||||||
|
}
|
||||||
|
|
||||||
|
#else
|
||||||
|
|
||||||
|
// Linux and whatnot
|
||||||
|
#include <semaphore.h>
|
||||||
|
|
||||||
|
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);
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif
|
@ -5,7 +5,6 @@
|
|||||||
#include <fuse.h>
|
#include <fuse.h>
|
||||||
#include <fuse_opt.h>
|
#include <fuse_opt.h>
|
||||||
#include <fuse_lowlevel.h>
|
#include <fuse_lowlevel.h>
|
||||||
#include <semaphore.h>
|
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include <errno.h>
|
#include <errno.h>
|
||||||
@ -18,6 +17,8 @@
|
|||||||
#include <dispatch/dispatch.h>
|
#include <dispatch/dispatch.h>
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#include "abstractions.h"
|
||||||
|
|
||||||
using namespace v8;
|
using namespace v8;
|
||||||
|
|
||||||
enum bindings_ops_t {
|
enum bindings_ops_t {
|
||||||
@ -74,11 +75,7 @@ struct bindings_t {
|
|||||||
char mnt[1024];
|
char mnt[1024];
|
||||||
char mntopts[1024];
|
char mntopts[1024];
|
||||||
pthread_t thread;
|
pthread_t thread;
|
||||||
#ifdef __APPLE__
|
bindings_sem_t semaphore;
|
||||||
dispatch_semaphore_t semaphore;
|
|
||||||
#else
|
|
||||||
sem_t semaphore;
|
|
||||||
#endif
|
|
||||||
uv_async_t async;
|
uv_async_t async;
|
||||||
|
|
||||||
// methods
|
// methods
|
||||||
@ -138,33 +135,6 @@ static bindings_t *bindings_mounted[1024];
|
|||||||
static int bindings_mounted_count = 0;
|
static int bindings_mounted_count = 0;
|
||||||
static bindings_t *bindings_current = NULL;
|
static bindings_t *bindings_current = NULL;
|
||||||
|
|
||||||
#ifdef __APPLE__
|
|
||||||
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);
|
|
||||||
}
|
|
||||||
#else
|
|
||||||
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);
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
|
|
||||||
static bindings_t *bindings_find_mounted (char *path) {
|
static bindings_t *bindings_find_mounted (char *path) {
|
||||||
for (int i = 0; i < bindings_mounted_count; i++) {
|
for (int i = 0; i < bindings_mounted_count; i++) {
|
||||||
bindings_t *b = bindings_mounted[i];
|
bindings_t *b = bindings_mounted[i];
|
||||||
|
Loading…
Reference in New Issue
Block a user