mirror of
https://github.com/kiwix/java-libkiwix.git
synced 2025-09-10 15:50:26 -04:00
Use c++11 std::thread instead of pthread.
This commit is contained in:
parent
50314fdae8
commit
da247042c0
@ -28,11 +28,7 @@
|
|||||||
|
|
||||||
#include "utils.h"
|
#include "utils.h"
|
||||||
|
|
||||||
#if __ANDROID__
|
std::mutex globalLock;
|
||||||
pthread_mutex_t globalLock = PTHREAD_RECURSIVE_MUTEX_INITIALIZER;
|
|
||||||
#else
|
|
||||||
pthread_mutex_t globalLock = PTHREAD_RECURSIVE_MUTEX_INITIALIZER_NP;
|
|
||||||
#endif
|
|
||||||
|
|
||||||
JNIEXPORT void JNICALL Java_org_kiwix_kiwixlib_JNIICU_setDataDirectory(
|
JNIEXPORT void JNICALL Java_org_kiwix_kiwixlib_JNIICU_setDataDirectory(
|
||||||
JNIEnv* env, jclass kclass, jstring dirStr)
|
JNIEnv* env, jclass kclass, jstring dirStr)
|
||||||
|
@ -24,7 +24,7 @@
|
|||||||
|
|
||||||
#include <jni.h>
|
#include <jni.h>
|
||||||
|
|
||||||
#include <pthread.h>
|
#include <mutex>
|
||||||
#include <string>
|
#include <string>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
@ -36,7 +36,7 @@
|
|||||||
#define LOG(...)
|
#define LOG(...)
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
extern pthread_mutex_t globalLock;
|
extern std::mutex globalLock;
|
||||||
|
|
||||||
template<typename T>
|
template<typename T>
|
||||||
void setPtr(JNIEnv* env, jobject thisObj, T* ptr)
|
void setPtr(JNIEnv* env, jobject thisObj, T* ptr)
|
||||||
@ -88,22 +88,10 @@ inline jobjectArray createArray(JNIEnv* env, size_t length, const std::string& t
|
|||||||
return env->NewObjectArray(length, c, NULL);
|
return env->NewObjectArray(length, c, NULL);
|
||||||
}
|
}
|
||||||
|
|
||||||
class Lock
|
class Lock : public std::unique_lock<std::mutex>
|
||||||
{
|
{
|
||||||
protected:
|
|
||||||
pthread_mutex_t* lock;
|
|
||||||
|
|
||||||
public:
|
public:
|
||||||
Lock() : lock(&globalLock) { pthread_mutex_lock(lock); }
|
Lock() : std::unique_lock<std::mutex>(globalLock) { }
|
||||||
Lock(const Lock&) = delete;
|
|
||||||
Lock& operator=(const Lock&) = delete;
|
|
||||||
Lock(Lock&& other) : lock(&globalLock) { other.lock = nullptr; }
|
|
||||||
virtual ~Lock()
|
|
||||||
{
|
|
||||||
if (lock) {
|
|
||||||
pthread_mutex_unlock(lock);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
};
|
};
|
||||||
|
|
||||||
template <class T>
|
template <class T>
|
||||||
|
Loading…
x
Reference in New Issue
Block a user