mirror of
https://github.com/NekoX-Dev/NekoX.git
synced 2024-12-13 19:51:10 +01:00
Fix: init ConnectionsManager when calling getInstance
Signed-off-by: luvletter2333 <luvletter2333@gmail.com>
This commit is contained in:
parent
7f8ca21868
commit
aadfcb7e96
@ -34,7 +34,8 @@
|
||||
#ifdef ANDROID
|
||||
#include <jni.h>
|
||||
JavaVM *javaVm = nullptr;
|
||||
JNIEnv *jniEnv[MAX_ACCOUNT_COUNT];
|
||||
//JNIEnv *jniEnv[MAX_ACCOUNT_COUNT];
|
||||
std::vector<JNIEnv*> jniEnv(MAX_ACCOUNT_COUNT);
|
||||
jclass jclass_ByteBuffer = nullptr;
|
||||
jmethodID jclass_ByteBuffer_allocateDirect = 0;
|
||||
#endif
|
||||
@ -132,58 +133,18 @@ ConnectionsManager::~ConnectionsManager() {
|
||||
pthread_mutex_destroy(&mutex);
|
||||
}
|
||||
|
||||
std::vector<ConnectionsManager*> ConnectionsManager::_instances = std::vector<ConnectionsManager*>(MAX_ACCOUNT_COUNT);
|
||||
|
||||
ConnectionsManager& ConnectionsManager::getInstance(int32_t instanceNum) {
|
||||
switch (instanceNum) {
|
||||
case 0:
|
||||
static ConnectionsManager instance0(0);
|
||||
return instance0;
|
||||
case 1:
|
||||
static ConnectionsManager instance1(1);
|
||||
return instance1;
|
||||
case 2:
|
||||
static ConnectionsManager instance2(2);
|
||||
return instance2;
|
||||
case 3:
|
||||
static ConnectionsManager instance3(3);
|
||||
return instance3;
|
||||
case 4:
|
||||
static ConnectionsManager instance4(4);
|
||||
return instance4;
|
||||
case 5:
|
||||
static ConnectionsManager instance5(5);
|
||||
return instance5;
|
||||
case 6:
|
||||
static ConnectionsManager instance6(6);
|
||||
return instance6;
|
||||
case 7:
|
||||
static ConnectionsManager instance7(7);
|
||||
return instance7;
|
||||
case 8:
|
||||
static ConnectionsManager instance8(8);
|
||||
return instance8;
|
||||
case 9:
|
||||
static ConnectionsManager instance9(9);
|
||||
return instance9;
|
||||
case 10:
|
||||
static ConnectionsManager instance10(10);
|
||||
return instance10;
|
||||
case 11:
|
||||
static ConnectionsManager instance11(11);
|
||||
return instance11;
|
||||
case 12:
|
||||
static ConnectionsManager instance12(12);
|
||||
return instance12;
|
||||
case 13:
|
||||
static ConnectionsManager instance13(13);
|
||||
return instance13;
|
||||
case 14:
|
||||
static ConnectionsManager instance14(14);
|
||||
return instance14;
|
||||
case 15:
|
||||
default:
|
||||
static ConnectionsManager instance15(15);
|
||||
return instance15;
|
||||
static std::mutex _new_mutex;
|
||||
|
||||
if(_instances[instanceNum] == nullptr) {
|
||||
_new_mutex.lock();
|
||||
if(_instances[instanceNum] == nullptr)
|
||||
_instances[instanceNum] = new ConnectionsManager(instanceNum);
|
||||
_new_mutex.unlock();
|
||||
}
|
||||
return *_instances[instanceNum];
|
||||
}
|
||||
|
||||
int ConnectionsManager::callEvents(int64_t now) {
|
||||
|
@ -91,6 +91,7 @@ public:
|
||||
|
||||
private:
|
||||
static void *ThreadProc(void *data);
|
||||
static std::vector<ConnectionsManager*> _instances;
|
||||
|
||||
void initDatacenters();
|
||||
void loadConfig();
|
||||
@ -264,7 +265,8 @@ private:
|
||||
|
||||
#ifdef ANDROID
|
||||
extern JavaVM *javaVm;
|
||||
extern JNIEnv *jniEnv[MAX_ACCOUNT_COUNT];
|
||||
//extern JNIEnv *jniEnv[MAX_ACCOUNT_COUNT];
|
||||
extern std::vector<JNIEnv*> jniEnv;
|
||||
extern jclass jclass_ByteBuffer;
|
||||
extern jmethodID jclass_ByteBuffer_allocateDirect;
|
||||
#endif
|
||||
|
Loading…
Reference in New Issue
Block a user