From c40faba20ffdef83eca85f90bccbf5b242912665 Mon Sep 17 00:00:00 2001 From: Ari Lazier Date: Thu, 12 Nov 2015 17:16:24 -0800 Subject: [PATCH] make rpc shutdown thread safe --- ReactNative/RealmReact.mm | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/ReactNative/RealmReact.mm b/ReactNative/RealmReact.mm index 574c917e..6fcc3982 100644 --- a/ReactNative/RealmReact.mm +++ b/ReactNative/RealmReact.mm @@ -54,10 +54,10 @@ JSGlobalContextRef RealmReactGetJSGlobalContextForExecutor(id executor, bool cre @interface RealmReact () { GCDWebServer *_webServer; std::unique_ptr _rpcServer; + std::mutex _rpcMutex; } @end -static std::mutex s_rpcMutex; static __weak RealmReact *s_currentRealmModule = nil; #endif @@ -86,7 +86,7 @@ static __weak RealmReact *s_currentRealmModule = nil; #if DEBUG - (void)startRPC { - std::lock_guard lock(s_rpcMutex); + std::lock_guard lock(_rpcMutex); [GCDWebServer setLogLevel:3]; _webServer = [[GCDWebServer alloc] init]; @@ -104,7 +104,7 @@ static __weak RealmReact *s_currentRealmModule = nil; dispatch_sync(dispatch_get_main_queue(), ^{ RealmReact *self = weakSelf; if (self) { - std::lock_guard lock(s_rpcMutex); + std::lock_guard lock(_rpcMutex); if (_rpcServer) { realm_js::json args = realm_js::json::parse([[(GCDWebServerDataRequest *)request text] UTF8String]); std::string responseText = _rpcServer->perform_request(request.path.UTF8String, args).dump(); @@ -133,7 +133,7 @@ static __weak RealmReact *s_currentRealmModule = nil; } - (void)shutdownRPC { - std::lock_guard lock(s_rpcMutex); + std::lock_guard lock(_rpcMutex); [_webServer stop]; [_webServer removeAllHandlers]; _webServer = nil;