Skip to content

Commit 06638d4

Browse files
committed
Remove thread lock.
This make the JNI wrapping *somehow* NOT threadsafe. Few things are threadsafe "by nature": - A lot of native method in libzim are threadsafe. - Wrapping internal are threadsafe (shared_ptr). What is not threadsafe is accessing the SAME java object from different thread. But accessing the same wrapped cpp object using two different java wrapper in two different thread is ok (assuming that the called cpp method is threadsafe itself).
1 parent b2b7dad commit 06638d4

File tree

9 files changed

+0
-25
lines changed

9 files changed

+0
-25
lines changed

lib/src/main/cpp/CMakeLists.txt

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@ add_library(
1010
zim_wrapper
1111

1212
SHARED
13-
common.cpp
1413
libzim/archive.cpp
1514
libzim/entry.cpp
1615
libzim/entry_iterator.cpp

lib/src/main/cpp/common.cpp

Lines changed: 0 additions & 4 deletions
This file was deleted.

lib/src/main/cpp/libkiwix/kiwixicu.cpp

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,12 +27,9 @@
2727
#include "utils.h"
2828
#include "zim/tools.h"
2929

30-
std::mutex globalLock;
31-
3230
JNIEXPORT void JNICALL Java_org_kiwix_kiwixlib_JNIICU_setDataDirectory(
3331
JNIEnv* env, jclass kclass, jstring dirStr)
3432
{
35-
Lock l;
3633
try {
3734
zim::setICUDataDirectory(TO_C(dirStr));
3835
} catch (...) {

lib/src/main/cpp/libkiwix/kiwixserver.cpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,6 @@
3535
METHOD(void, setNativeServer, jobject jLibrary)
3636
{
3737
LOG("Attempting to create server");
38-
Lock l;
3938
try {
4039
auto library = getPtr<kiwix::Library>(env, jLibrary);
4140
SET_PTR(std::make_shared<NATIVE_TYPE>(library.get()));

lib/src/main/cpp/libzim/archive.cpp

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,6 @@ METHOD(void, setNativeArchive, jstring filename)
4141
std::string cPath = TO_C(filename);
4242

4343
LOG("Attempting to create reader with: %s", cPath.c_str());
44-
Lock l;
4544
try {
4645
auto archive = std::make_shared<zim::Archive>(cPath);
4746
SET_PTR(archive);
@@ -78,7 +77,6 @@ JNIEXPORT void JNICALL Java_org_kiwix_libzim_Archive_setNativeArchiveByFD(
7877
int fd = jni2fd(fdObj, env);
7978

8079
LOG("Attempting to create reader with fd: %d", fd);
81-
Lock l;
8280
try {
8381
auto archive = std::make_shared<zim::Archive>(fd);
8482
SET_PTR(archive);
@@ -99,7 +97,6 @@ JNIEXPORT void JNICALL Java_org_kiwix_libzim_Archive_setNativeArchiveEmbedded(
9997
int fd = jni2fd(fdObj, env);
10098

10199
LOG("Attempting to create reader with fd: %d", fd);
102-
Lock l;
103100
try {
104101
auto archive = std::make_shared<zim::Archive>(fd, offset, size);
105102
SET_PTR(archive);

lib/src/main/cpp/libzim/query.cpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,6 @@
3636
METHOD(void, setNativeQuery, jstring query)
3737
{
3838
auto cQuery = TO_C(query);
39-
Lock l;
4039
try {
4140
auto query = std::make_shared<NATIVE_TYPE>(cQuery);
4241
SET_PTR(query);

lib/src/main/cpp/libzim/searcher.cpp

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,8 +35,6 @@
3535

3636
METHOD(void, setNativeSearcher, jobject archive)
3737
{
38-
39-
Lock l;
4038
auto cArchive = getPtr<zim::Archive>(env, archive);
4139
try {
4240
auto searcher = std::make_shared<zim::Searcher>(*cArchive);

lib/src/main/cpp/libzim/suggestion_searcher.cpp

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,8 +35,6 @@
3535

3636
METHOD(void, setNativeSearcher, jobject archive)
3737
{
38-
39-
Lock l;
4038
auto cArchive = getPtr<zim::Archive>(env, archive);
4139
try {
4240
auto searcher = std::make_shared<zim::SuggestionSearcher>(*cArchive);

lib/src/main/cpp/utils.h

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,6 @@
3737
#define LOG(...)
3838
#endif
3939

40-
extern std::mutex globalLock;
4140
using std::shared_ptr;
4241

4342
// Here is the wrapping structure.
@@ -131,13 +130,6 @@ inline jobject buildWrapper(JNIEnv* env, const char* class_name, T&& obj, const
131130
#define BUILD_WRAPPER(CLASSNAME, OBJ) buildWrapper(env, CLASSNAME, std::move(OBJ))
132131

133132

134-
// A mixin class which will lock the globalLock when a instance is created
135-
// This avoid the cration of two instance inheriting from Lock in the same time.
136-
class Lock : public std::unique_lock<std::mutex>
137-
{
138-
public:
139-
Lock() : std::unique_lock<std::mutex>(globalLock) { }
140-
};
141133

142134
// ---------------------------------------------------------------------------
143135
// Convert things to JAVA

0 commit comments

Comments
 (0)