Protect access to the external_snapshot_blob global with a lock.

The external_snapshot_blob is a global and might be accessed from multiple
threads.  Protect it with a lock.

BUG=457656
LOG=N
R=vogelheim@chromium.org

Review URL: https://codereview.chromium.org/918213002

Cr-Commit-Position: refs/heads/master@{#26638}
This commit is contained in:
Ross McIlroy 2015-02-13 10:35:37 +00:00
parent e9fd6b0836
commit 1da1e34788

View File

@ -6,6 +6,7 @@
#include "src/snapshot.h"
#include "src/base/platform/mutex.h"
#include "src/serialize.h"
#include "src/snapshot-source-sink.h"
#include "src/v8.h" // for V8::Initialize
@ -19,9 +20,12 @@
namespace v8 {
namespace internal {
static base::LazyMutex external_startup_data_mutex = LAZY_MUTEX_INITIALIZER;
static v8::StartupData external_startup_blob = {NULL, 0};
void SetSnapshotFromFile(StartupData* snapshot_blob) {
base::LockGuard<base::Mutex> lock_guard(
external_startup_data_mutex.Pointer());
DCHECK(snapshot_blob);
DCHECK(snapshot_blob->data);
DCHECK(snapshot_blob->raw_size > 0);
@ -31,5 +35,9 @@ void SetSnapshotFromFile(StartupData* snapshot_blob) {
}
const v8::StartupData Snapshot::SnapshotBlob() { return external_startup_blob; }
const v8::StartupData Snapshot::SnapshotBlob() {
base::LockGuard<base::Mutex> lock_guard(
external_startup_data_mutex.Pointer());
return external_startup_blob;
}
} } // namespace v8::internal