locker.h 926 B

123456789101112131415161718192021222324252627282930313233343536
  1. // Copyright 2014 The Chromium Authors. All rights reserved.
  2. // Use of this source code is governed by a BSD-style license that can be
  3. // found in the LICENSE.chromium file.
  4. #ifndef ATOM_COMMON_API_LOCKER_H_
  5. #define ATOM_COMMON_API_LOCKER_H_
  6. #include <memory>
  7. #include "base/macros.h"
  8. #include "v8/include/v8.h"
  9. namespace mate {
  10. // Only lock when lockers are used in current thread.
  11. class Locker {
  12. public:
  13. explicit Locker(v8::Isolate* isolate);
  14. ~Locker();
  15. // Returns whether current process is browser process, currently we detect it
  16. // by checking whether current has used V8 Lock, but it might be a bad idea.
  17. static inline bool IsBrowserProcess() { return v8::Locker::IsActive(); }
  18. private:
  19. void* operator new(size_t size);
  20. void operator delete(void*, size_t);
  21. std::unique_ptr<v8::Locker> locker_;
  22. DISALLOW_COPY_AND_ASSIGN(Locker);
  23. };
  24. } // namespace mate
  25. #endif // ATOM_COMMON_API_LOCKER_H_