Skip to content

Commit 5270bb9

Browse files
committed
Use mutex to lock instead of v8::Locker
1 parent 3991c31 commit 5270bb9

File tree

5 files changed

+17
-7
lines changed

5 files changed

+17
-7
lines changed

test-app/app/src/main/java/com/tns/RuntimeHelper.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -192,7 +192,7 @@ public static Runtime initRuntime(Application app) {
192192

193193
// if app is in debuggable mode run livesync service
194194
// runtime needs to be initialized before the NativeScriptSyncService is enabled because it uses runtime.runScript(...)
195-
// initLiveSync(runtime, logger, app);
195+
initLiveSync(runtime, logger, app);
196196
}
197197

198198
runtime.runScript(new File(appDir, "internal/ts_helpers.js"));

test-app/build-tools/static-binding-generator/src/main/java/org/nativescript/staticbindinggenerator/Generator.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -655,9 +655,9 @@ private void writeMethodBody(Method m, boolean isConstructor, boolean isApplicat
655655
}
656656

657657
// call liveSync initialization
658-
if (m.getName().equals("onCreate") && isActivityClass) {
659-
w.writeln("\t\tcom.tns.RuntimeHelper.initLiveSync(this.getApplication());");
660-
}
658+
// if (m.getName().equals("onCreate") && isActivityClass) {
659+
// w.writeln("\t\tcom.tns.RuntimeHelper.initLiveSync(this.getApplication());");
660+
// }
661661
}
662662

663663
private void writeType(Type t, Writer w) {

test-app/runtime/src/main/cpp/ModuleInternal.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
#include "include/v8.h"
1818
#include "CallbackHandlers.h"
1919
#include "ManualInstrumentation.h"
20+
#include "Runtime.h"
2021
#include <sstream>
2122
#include <libgen.h>
2223
#include <dlfcn.h>
@@ -428,7 +429,9 @@ Local<Object> ModuleInternal::LoadData(Isolate* isolate, const string& path) {
428429

429430
Local<String> ModuleInternal::WrapModuleContent(const string& path) {
430431
TNSPERF();
432+
Runtime::GetRuntime(m_isolate)->Lock();
431433
string content = File::ReadText(path);
434+
Runtime::GetRuntime(m_isolate)->Unlock();
432435

433436
auto separatorIndex = path.find_last_of("/");
434437

test-app/runtime/src/main/cpp/Runtime.cpp

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
#include "include/zipconf.h"
2323
#include <csignal>
2424
#include <sstream>
25+
#include <mutex>
2526
#include <dlfcn.h>
2627
#include <console/Console.h>
2728
#include "NetworkDomainCallbackHandlers.h"
@@ -189,11 +190,15 @@ void Runtime::Init(jstring filesPath, jstring nativeLibDir, bool verboseLoggingE
189190
}
190191

191192
void Runtime::Lock() {
192-
m_locker.reset(new v8::Locker(m_isolate));
193+
#ifdef APPLICATION_IN_DEBUG
194+
m_fileWriteLock.reset(new std::lock_guard<std::mutex>(m_fileWriteMutex));
195+
#endif
193196
}
194197

195198
void Runtime::Unlock() {
196-
m_locker.reset(nullptr);
199+
#ifdef APPLICATION_IN_DEBUG
200+
m_fileWriteLock.reset(nullptr);
201+
#endif
197202
}
198203

199204
void Runtime::RunModule(JNIEnv* _env, jobject obj, jstring scriptFile) {

test-app/runtime/src/main/cpp/Runtime.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
#include "Profiler.h"
1111
#include "ModuleInternal.h"
1212
#include "File.h"
13+
#include <mutex>
1314

1415
jobject ConvertJsValueToJavaObject(tns::JEnv& env, const v8::Local<v8::Value>& value, int classReturnType);
1516

@@ -60,7 +61,8 @@ class Runtime {
6061
void Unlock();
6162

6263
static v8::Platform* platform;
63-
std::auto_ptr<v8::Locker> m_locker;
64+
std::auto_ptr<std::lock_guard<std::mutex>> m_fileWriteLock;
65+
std::mutex m_fileWriteMutex;
6466

6567
private:
6668
Runtime(JNIEnv* env, jobject runtime, int id);

0 commit comments

Comments
 (0)