fix iOS debugger

This commit is contained in:
blagoev 2017-11-13 09:26:13 +02:00
parent e2c6a5f906
commit 521fd12937
2 changed files with 36 additions and 14 deletions

View File

@ -28,7 +28,6 @@
#include "object_accessor.hpp"
#include "shared_realm.hpp"
#include "results.hpp"
#include <android/looper.h>
using namespace realm;
using namespace realm::rpc;
@ -83,15 +82,30 @@ RPCServer*& get_rpc_server(JSGlobalContextRef ctx) {
}
}
RPCWorker::RPCWorker() {
//m_thread = std::thread([this]() {
//m_looper = ALooper_prepare(ALOOPER_PREPARE_ALLOW_NON_CALLBACKS);
#ifdef REALM_PLATFORM_APPLE
void runLoopFunc(CFRunLoopRef loop, RPCWorker* rpcWorker) {
auto m_stop = false;
CFRunLoopPerformBlock(loop, kCFRunLoopDefaultMode,
^{
rpcWorker->try_run_task();
if (rpcWorker->should_stop()) {
CFRunLoopStop(CFRunLoopGetCurrent());
} else {
runLoopFunc(loop, rpcWorker);
}
});
CFRunLoopWakeUp(loop);
}
#endif
// TODO: Create ALooper/CFRunLoop to support async calls.
//while (!m_stop) {
//try_run_task();
//}
//});
RPCWorker::RPCWorker() {
#ifdef REALM_PLATFORM_APPLE
m_thread = std::thread([this]() {
m_loop = CFRunLoopGetCurrent();
runLoopFunc(m_loop, this);
CFRunLoopRun();
});
#endif
}
RPCWorker::~RPCWorker() {
@ -139,11 +153,17 @@ bool RPCWorker::try_run_task() {
return m_stop;
}
bool RPCWorker::should_stop() {
return m_stop;
}
void RPCWorker::stop() {
if (!m_stop) {
m_stop = true;
//m_thread.join();
//m_looper = nullptr;
#if REALM_PLATFORM_APPLE
m_thread.join();
m_loop = nullptr;
#endif
}
}

View File

@ -26,7 +26,6 @@
#include "json.hpp"
#include "jsc_types.hpp"
#include "jsc_protected.hpp"
#include <android/looper.h>
namespace realm {
@ -49,11 +48,14 @@ class RPCWorker {
bool try_run_task();
void stop();
json try_pop_task_result();
bool should_stop();
private:
bool m_stop = false;
//ALooper* m_looper;
//std::thread m_thread;
#if REALM_PLATFORM_APPLE
std::thread m_thread;
CFRunLoopRef m_loop;
#endif
ConcurrentDeque<std::packaged_task<json()>> m_tasks;
ConcurrentDeque<std::future<json>> m_futures;
};