Run Tizen Webapps in single process mode
[platform/framework/web/crosswalk-tizen.git] / atom / common / api / locker.h
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
5 #ifndef ATOM_COMMON_API_LOCKER_H_
6 #define ATOM_COMMON_API_LOCKER_H_
7
8 #include <memory>
9
10 #include "base/macros.h"
11 #include "tizen/common/env_variables.h"
12 #include "v8/include/v8.h"
13
14 namespace mate {
15
16 // Only lock when lockers are used in current thread.
17 class Locker {
18  public:
19   explicit Locker(v8::Isolate* isolate);
20   ~Locker();
21
22   // Returns whether current process is browser process, currently we detect it
23   // by checking whether current has used V8 Lock, but it might be a bad idea.
24   static inline bool IsBrowserProcess() { if (::tizen::is_single_process) return true; return v8::Locker::IsActive(); }
25
26  private:
27   void* operator new(size_t size);
28   void operator delete(void*, size_t);
29
30   std::unique_ptr<v8::Locker> locker_;
31
32   DISALLOW_COPY_AND_ASSIGN(Locker);
33 };
34
35 }  // namespace mate
36
37 #endif  // ATOM_COMMON_API_LOCKER_H_