mirror of
https://github.com/kiwix/java-libkiwix.git
synced 2025-09-12 16:48:45 -04:00
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).
This commit is contained in:
parent
b2b7dad84f
commit
06638d46b8
@ -10,7 +10,6 @@ add_library(
|
||||
zim_wrapper
|
||||
|
||||
SHARED
|
||||
common.cpp
|
||||
libzim/archive.cpp
|
||||
libzim/entry.cpp
|
||||
libzim/entry_iterator.cpp
|
||||
|
@ -1,4 +0,0 @@
|
||||
|
||||
#include <thread>
|
||||
|
||||
std::mutex globalLock;
|
@ -27,12 +27,9 @@
|
||||
#include "utils.h"
|
||||
#include "zim/tools.h"
|
||||
|
||||
std::mutex globalLock;
|
||||
|
||||
JNIEXPORT void JNICALL Java_org_kiwix_kiwixlib_JNIICU_setDataDirectory(
|
||||
JNIEnv* env, jclass kclass, jstring dirStr)
|
||||
{
|
||||
Lock l;
|
||||
try {
|
||||
zim::setICUDataDirectory(TO_C(dirStr));
|
||||
} catch (...) {
|
||||
|
@ -35,7 +35,6 @@
|
||||
METHOD(void, setNativeServer, jobject jLibrary)
|
||||
{
|
||||
LOG("Attempting to create server");
|
||||
Lock l;
|
||||
try {
|
||||
auto library = getPtr<kiwix::Library>(env, jLibrary);
|
||||
SET_PTR(std::make_shared<NATIVE_TYPE>(library.get()));
|
||||
|
@ -41,7 +41,6 @@ METHOD(void, setNativeArchive, jstring filename)
|
||||
std::string cPath = TO_C(filename);
|
||||
|
||||
LOG("Attempting to create reader with: %s", cPath.c_str());
|
||||
Lock l;
|
||||
try {
|
||||
auto archive = std::make_shared<zim::Archive>(cPath);
|
||||
SET_PTR(archive);
|
||||
@ -78,7 +77,6 @@ JNIEXPORT void JNICALL Java_org_kiwix_libzim_Archive_setNativeArchiveByFD(
|
||||
int fd = jni2fd(fdObj, env);
|
||||
|
||||
LOG("Attempting to create reader with fd: %d", fd);
|
||||
Lock l;
|
||||
try {
|
||||
auto archive = std::make_shared<zim::Archive>(fd);
|
||||
SET_PTR(archive);
|
||||
@ -99,7 +97,6 @@ JNIEXPORT void JNICALL Java_org_kiwix_libzim_Archive_setNativeArchiveEmbedded(
|
||||
int fd = jni2fd(fdObj, env);
|
||||
|
||||
LOG("Attempting to create reader with fd: %d", fd);
|
||||
Lock l;
|
||||
try {
|
||||
auto archive = std::make_shared<zim::Archive>(fd, offset, size);
|
||||
SET_PTR(archive);
|
||||
|
@ -36,7 +36,6 @@
|
||||
METHOD(void, setNativeQuery, jstring query)
|
||||
{
|
||||
auto cQuery = TO_C(query);
|
||||
Lock l;
|
||||
try {
|
||||
auto query = std::make_shared<NATIVE_TYPE>(cQuery);
|
||||
SET_PTR(query);
|
||||
|
@ -35,8 +35,6 @@
|
||||
|
||||
METHOD(void, setNativeSearcher, jobject archive)
|
||||
{
|
||||
|
||||
Lock l;
|
||||
auto cArchive = getPtr<zim::Archive>(env, archive);
|
||||
try {
|
||||
auto searcher = std::make_shared<zim::Searcher>(*cArchive);
|
||||
|
@ -35,8 +35,6 @@
|
||||
|
||||
METHOD(void, setNativeSearcher, jobject archive)
|
||||
{
|
||||
|
||||
Lock l;
|
||||
auto cArchive = getPtr<zim::Archive>(env, archive);
|
||||
try {
|
||||
auto searcher = std::make_shared<zim::SuggestionSearcher>(*cArchive);
|
||||
|
@ -37,7 +37,6 @@
|
||||
#define LOG(...)
|
||||
#endif
|
||||
|
||||
extern std::mutex globalLock;
|
||||
using std::shared_ptr;
|
||||
|
||||
// Here is the wrapping structure.
|
||||
@ -131,13 +130,6 @@ inline jobject buildWrapper(JNIEnv* env, const char* class_name, T&& obj, const
|
||||
#define BUILD_WRAPPER(CLASSNAME, OBJ) buildWrapper(env, CLASSNAME, std::move(OBJ))
|
||||
|
||||
|
||||
// A mixin class which will lock the globalLock when a instance is created
|
||||
// This avoid the cration of two instance inheriting from Lock in the same time.
|
||||
class Lock : public std::unique_lock<std::mutex>
|
||||
{
|
||||
public:
|
||||
Lock() : std::unique_lock<std::mutex>(globalLock) { }
|
||||
};
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
// Convert things to JAVA
|
||||
|
Loading…
x
Reference in New Issue
Block a user