mirror of
https://github.com/kiwix/java-libkiwix.git
synced 2025-09-10 07:36: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"
|
||||
|
||||
#if __ANDROID__
|
||||
pthread_mutex_t globalLock = PTHREAD_RECURSIVE_MUTEX_INITIALIZER;
|
||||
#else
|
||||
pthread_mutex_t globalLock = PTHREAD_RECURSIVE_MUTEX_INITIALIZER_NP;
|
||||
#endif
|
||||
std::mutex globalLock;
|
||||
|
||||
JNIEXPORT void JNICALL Java_org_kiwix_kiwixlib_JNIICU_setDataDirectory(
|
||||
JNIEnv* env, jclass kclass, jstring dirStr)
|
||||
|
@ -24,7 +24,7 @@
|
||||
|
||||
#include <jni.h>
|
||||
|
||||
#include <pthread.h>
|
||||
#include <mutex>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
#include <iostream>
|
||||
@ -36,7 +36,7 @@
|
||||
#define LOG(...)
|
||||
#endif
|
||||
|
||||
extern pthread_mutex_t globalLock;
|
||||
extern std::mutex globalLock;
|
||||
|
||||
template<typename T>
|
||||
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);
|
||||
}
|
||||
|
||||
class Lock
|
||||
class Lock : public std::unique_lock<std::mutex>
|
||||
{
|
||||
protected:
|
||||
pthread_mutex_t* lock;
|
||||
|
||||
public:
|
||||
Lock() : lock(&globalLock) { pthread_mutex_lock(lock); }
|
||||
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);
|
||||
}
|
||||
}
|
||||
Lock() : std::unique_lock<std::mutex>(globalLock) { }
|
||||
};
|
||||
|
||||
template <class T>
|
||||
|
Loading…
x
Reference in New Issue
Block a user