2015-08-07 11:34:00 +00:00
|
|
|
// Copyright 2014 The Chromium Authors. All rights reserved.
|
|
|
|
// Use of this source code is governed by a BSD-style license that can be
|
|
|
|
// found in the LICENSE.chromium file.
|
|
|
|
|
2019-10-31 07:56:00 +00:00
|
|
|
#ifndef SHELL_COMMON_GIN_HELPER_LOCKER_H_
|
|
|
|
#define SHELL_COMMON_GIN_HELPER_LOCKER_H_
|
2015-08-07 11:34:00 +00:00
|
|
|
|
2016-05-23 01:59:39 +00:00
|
|
|
#include <memory>
|
|
|
|
|
2015-08-07 11:34:00 +00:00
|
|
|
#include "v8/include/v8.h"
|
|
|
|
|
2019-10-31 07:56:00 +00:00
|
|
|
namespace gin_helper {
|
2015-08-07 11:34:00 +00:00
|
|
|
|
|
|
|
// Only lock when lockers are used in current thread.
|
|
|
|
class Locker {
|
|
|
|
public:
|
|
|
|
explicit Locker(v8::Isolate* isolate);
|
|
|
|
~Locker();
|
|
|
|
|
2021-11-03 11:41:45 +00:00
|
|
|
// disable copy
|
|
|
|
Locker(const Locker&) = delete;
|
|
|
|
Locker& operator=(const Locker&) = delete;
|
|
|
|
|
2015-08-07 11:34:00 +00:00
|
|
|
// Returns whether current process is browser process, currently we detect it
|
|
|
|
// by checking whether current has used V8 Lock, but it might be a bad idea.
|
|
|
|
static inline bool IsBrowserProcess() { return v8::Locker::IsActive(); }
|
|
|
|
|
|
|
|
private:
|
|
|
|
void* operator new(size_t size);
|
|
|
|
void operator delete(void*, size_t);
|
|
|
|
|
2016-05-23 01:59:39 +00:00
|
|
|
std::unique_ptr<v8::Locker> locker_;
|
2015-08-07 11:34:00 +00:00
|
|
|
};
|
|
|
|
|
2019-10-31 07:56:00 +00:00
|
|
|
} // namespace gin_helper
|
2015-08-07 11:34:00 +00:00
|
|
|
|
2019-10-31 07:56:00 +00:00
|
|
|
#endif // SHELL_COMMON_GIN_HELPER_LOCKER_H_
|