Skip to content

Commit

Permalink
add simple way of messaging numbers and return code
Browse files Browse the repository at this point in the history
  • Loading branch information
mafintosh committed Jul 25, 2019
1 parent 48d991a commit 5a2c2b5
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 18 deletions.
28 changes: 12 additions & 16 deletions fuse-native.c
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,8 @@ typedef struct {
} fuse_thread_t;

typedef struct {
int hello;
uint32_t ints[32];
int32_t res;
fuse_thread_t *fuse;
fuse_native_semaphore_t sem;
uv_async_t async;
Expand All @@ -39,18 +40,6 @@ typedef struct {

static pthread_key_t thread_locals_key;

// static fuse_thread_locals_t * thread_local_map[1024];
// static int thread_local_map_length = 0;

// static int get_free_thread_id () {
// for (int i = 0; i < thread_local_map_length; i++) {
// if (thread_local_map[i] == NULL) return i;
// }

// return thread_local_map_length++;
// }


static void fin (napi_env env, void *fin_data, void* fin_hint) {
printf("finaliser is run\n");
// exit(0);
Expand Down Expand Up @@ -91,8 +80,6 @@ static fuse_thread_locals_t* get_thread_locals () {

fuse_thread_locals_t* l = (fuse_thread_locals_t *) malloc(sizeof(fuse_thread_locals_t));

l->hello = 42;

// TODO: mutex me??
int err = uv_async_init(uv_default_loop(), &(l->async), (uv_async_cb) fuse_native_dispatch);

Expand Down Expand Up @@ -138,14 +125,23 @@ static int fuse_native_getattr (const char *path, struct stat *stat) {
uv_async_send(&(l->async));
fuse_native_semaphore_wait(&(l->sem));

printf("l->res: %i\n", l->res);
printf("l->ints[0]: %u\n", l->ints[0]);
printf("l->ints[1]: %u\n", l->ints[1]);
printf("l->ints[2]: %u\n", l->ints[2]);

return -1;
}

NAPI_METHOD(fuse_native_signal) {
NAPI_ARGV(5)
NAPI_ARGV(2)
NAPI_ARGV_BUFFER_CAST(fuse_thread_locals_t *, l, 0);
NAPI_ARGV_INT32(res, 1)

l->res = res;
fuse_native_semaphore_signal(&(l->sem));

return NULL;
}

NAPI_METHOD(fuse_native_mount) {
Expand Down
9 changes: 7 additions & 2 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,14 @@ class Fuse {
}

onop (handle) {
console.log('on_op is called', handle)
const ints = new Uint32Array(handle.buffer, handle.byteOffset, 32)

ints[0] = 1
ints[1] = 42
ints[2] = 10

process.nextTick(function () {
binding.fuse_native_signal(handle)
binding.fuse_native_signal(handle, -1)
})
}
}
Expand Down

0 comments on commit 5a2c2b5

Please sign in to comment.