22
22
#include " include/zipconf.h"
23
23
#include < csignal>
24
24
#include < sstream>
25
+ #include < mutex>
25
26
#include < dlfcn.h>
26
27
#include < console/Console.h>
27
28
#include " NetworkDomainCallbackHandlers.h"
@@ -188,6 +189,26 @@ void Runtime::Init(jstring filesPath, jstring nativeLibDir, bool verboseLoggingE
188
189
s_isolate2RuntimesCache.insert (make_pair (m_isolate, this ));
189
190
}
190
191
192
+ std::string Runtime::ReadFileText (const std::string& filePath) {
193
+ #ifdef APPLICATION_IN_DEBUG
194
+ std::lock_guard<std::mutex> lock (m_fileWriteMutex);
195
+ #endif
196
+ return File::ReadText (filePath);
197
+ }
198
+
199
+
200
+ void Runtime::Lock () {
201
+ #ifdef APPLICATION_IN_DEBUG
202
+ m_fileWriteMutex.lock ();
203
+ #endif
204
+ }
205
+
206
+ void Runtime::Unlock () {
207
+ #ifdef APPLICATION_IN_DEBUG
208
+ m_fileWriteMutex.unlock ();
209
+ #endif
210
+ }
211
+
191
212
void Runtime::RunModule (JNIEnv* _env, jobject obj, jstring scriptFile) {
192
213
JEnv env (_env);
193
214
@@ -209,7 +230,8 @@ jobject Runtime::RunScript(JNIEnv* _env, jobject obj, jstring scriptFile) {
209
230
auto context = isolate->GetCurrentContext ();
210
231
211
232
auto filename = ArgConverter::jstringToString (scriptFile);
212
- auto src = File::ReadText (filename);
233
+ auto src = ReadFileText (filename);
234
+
213
235
auto source = ArgConverter::ConvertToV8String (isolate, src);
214
236
215
237
TryCatch tc (isolate);
@@ -476,7 +498,7 @@ Isolate* Runtime::PrepareV8Runtime(const string& filesPath, const string& native
476
498
477
499
// check for custom script to include in the snapshot
478
500
if (Constants::V8_HEAP_SNAPSHOT_SCRIPT.size () > 0 && File::Exists (Constants::V8_HEAP_SNAPSHOT_SCRIPT)) {
479
- customScript = File::ReadText (Constants::V8_HEAP_SNAPSHOT_SCRIPT);
501
+ customScript = ReadFileText (Constants::V8_HEAP_SNAPSHOT_SCRIPT);
480
502
}
481
503
482
504
DEBUG_WRITE_FORCE (" Creating heap snapshot" );
0 commit comments