Skip to content
This repository has been archived by the owner on Oct 30, 2018. It is now read-only.

Commit

Permalink
Use dedicated thread for running the event loop to avoid deadlocks
Browse files Browse the repository at this point in the history
  • Loading branch information
kaloyan-raev committed Mar 1, 2018
1 parent c4fe402 commit f7bc42d
Show file tree
Hide file tree
Showing 6 changed files with 127 additions and 88 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ For building Android applications it is recommended to use the [android-libstorj

```Gradle
dependencies {
compile 'io.storj:libstorj-java:0.7.2'
compile 'io.storj:libstorj-java:0.7.3'
}
```

Expand All @@ -24,6 +24,6 @@ dependencies {
<dependency>
<groupId>io.storj</groupId>
<artifactId>libstorj-java</artifactId>
<version>0.7.2</version>
<version>0.7.3</version>
</dependency>
```
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ apply plugin: 'maven'
apply plugin: 'maven-publish'

group = 'io.storj'
version = '0.7.2'
version = '0.7.3'

description = """Java bindings for libstorj"""

Expand Down
42 changes: 13 additions & 29 deletions src/main/cpp/storj-java.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -226,7 +226,7 @@ Java_io_storj_libstorj_Storj__1runEventLoop(
jlong storjEnv)
{
storj_env_t *storj_env = (storj_env_t *) storjEnv;
uv_run(storj_env->loop, UV_RUN_DEFAULT);
while (uv_run(storj_env->loop, UV_RUN_ONCE));
}

static void get_buckets_callback(uv_work_t *work_req, int status)
Expand Down Expand Up @@ -296,8 +296,6 @@ Java_io_storj_libstorj_Storj__1getBuckets(
storj_bridge_get_buckets(storj_env,
env->NewGlobalRef(callbackObject),
get_buckets_callback);

uv_run(storj_env->loop, UV_RUN_DEFAULT);
}

static void get_bucket_callback(uv_work_t *work_req, int status)
Expand Down Expand Up @@ -359,8 +357,6 @@ Java_io_storj_libstorj_Storj__1getBucket(
env->NewGlobalRef(callbackObject),
get_bucket_callback);

uv_run(storj_env->loop, UV_RUN_DEFAULT);

env->ReleaseStringUTFChars(bucketId, bucket_id);
}

Expand Down Expand Up @@ -392,6 +388,7 @@ static void get_bucket_id_callback(uv_work_t *work_req, int status)
}

json_object_put(req->response);
free((char *)req->bucket_name);
free(req);
free(work_req);
}
Expand All @@ -409,12 +406,10 @@ Java_io_storj_libstorj_Storj__1getBucketId(
const char *bucket_name = env->GetStringUTFChars(bucketName, NULL);

storj_bridge_get_bucket_id(storj_env,
bucket_name,
strdup(bucket_name),
env->NewGlobalRef(callbackObject),
get_bucket_id_callback);

uv_run(storj_env->loop, UV_RUN_DEFAULT);

env->ReleaseStringUTFChars(bucketName, bucket_name);
}

Expand Down Expand Up @@ -457,6 +452,7 @@ static void create_bucket_callback(uv_work_t *work_req, int status)
}

json_object_put(req->response);
free((char *)req->bucket_name);
free((char *)req->encrypted_bucket_name);
free(req->bucket);
free(req);
Expand All @@ -476,12 +472,10 @@ Java_io_storj_libstorj_Storj__1createBucket(
const char *bucket_name = env->GetStringUTFChars(bucketName, NULL);

storj_bridge_create_bucket(storj_env,
bucket_name,
strdup(bucket_name),
env->NewGlobalRef(callbackObject),
create_bucket_callback);

uv_run(storj_env->loop, UV_RUN_DEFAULT);

env->ReleaseStringUTFChars(bucketName, bucket_name);
}

Expand Down Expand Up @@ -567,6 +561,7 @@ static void list_files_callback(uv_work_t *work_req, int status)
}
}

free((char *) req->bucket_id);
storj_free_list_files_request(req);
free(work_req);
}
Expand All @@ -584,12 +579,10 @@ Java_io_storj_libstorj_Storj__1listFiles(
const char *bucket_id = env->GetStringUTFChars(bucketId, NULL);

storj_bridge_list_files(storj_env,
bucket_id,
strdup(bucket_id),
env->NewGlobalRef(callbackObject),
list_files_callback);

uv_run(storj_env->loop, UV_RUN_DEFAULT);

env->ReleaseStringUTFChars(bucketId, bucket_id);
}

Expand Down Expand Up @@ -646,6 +639,7 @@ static void get_file_callback(uv_work_t *work_req, int status)
}
}

free((char *)req->bucket_id);
storj_free_get_file_info_request(req);
free(work_req);
}
Expand All @@ -665,13 +659,11 @@ Java_io_storj_libstorj_Storj__1getFile(
const char *file_id = env->GetStringUTFChars(fileId, NULL);

storj_bridge_get_file_info(storj_env,
bucket_id,
strdup(bucket_id),
file_id,
env->NewGlobalRef(callbackObject),
get_file_callback);

uv_run(storj_env->loop, UV_RUN_DEFAULT);

env->ReleaseStringUTFChars(bucketId, bucket_id);
env->ReleaseStringUTFChars(fileId, file_id);
}
Expand Down Expand Up @@ -704,6 +696,8 @@ static void get_file_id_callback(uv_work_t *work_req, int status)
}

json_object_put(req->response);
free((char *)req->bucket_id);
free((char *)req->file_name);
free(req);
free(work_req);
}
Expand All @@ -723,13 +717,11 @@ Java_io_storj_libstorj_Storj__1getFileId(
const char *file_name = env->GetStringUTFChars(fileName, NULL);

storj_bridge_get_file_id(storj_env,
bucket_id,
file_name,
strdup(bucket_id),
strdup(file_name),
env->NewGlobalRef(callbackObject),
get_file_id_callback);

uv_run(storj_env->loop, UV_RUN_DEFAULT);

env->ReleaseStringUTFChars(bucketId, bucket_id);
env->ReleaseStringUTFChars(fileName, file_name);
}
Expand Down Expand Up @@ -1071,8 +1063,6 @@ Java_io_storj_libstorj_Storj__1deleteBucket(
env->NewGlobalRef(callbackObject),
delete_bucket_callback);

uv_run(storj_env->loop, UV_RUN_DEFAULT);

env->ReleaseStringUTFChars(bucketId, bucket_id);
}

Expand Down Expand Up @@ -1124,8 +1114,6 @@ Java_io_storj_libstorj_Storj__1deleteFile(
env->NewGlobalRef(callbackObject),
delete_file_callback);

uv_run(storj_env->loop, UV_RUN_DEFAULT);

env->ReleaseStringUTFChars(bucketId, bucket_id);
env->ReleaseStringUTFChars(fileId, file_id);
}
Expand Down Expand Up @@ -1179,8 +1167,6 @@ Java_io_storj_libstorj_Storj__1register(
storj_env->bridge_options->pass,
env->NewGlobalRef(callbackObject),
register_callback);

uv_run(storj_env->loop, UV_RUN_DEFAULT);
}

static void get_info_callback(uv_work_t *work_req, int status)
Expand Down Expand Up @@ -1240,8 +1226,6 @@ Java_io_storj_libstorj_Storj__1getInfo(
storj_bridge_get_info(storj_env,
env->NewGlobalRef(callbackObject),
get_info_callback);

uv_run(storj_env->loop, UV_RUN_DEFAULT);
}

extern "C"
Expand Down
Loading

0 comments on commit f7bc42d

Please sign in to comment.