• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // Copyright (c) 2019 The Chromium Embedded Framework Authors. All rights
2 // reserved. Use of this source code is governed by a BSD-style license that
3 // can be found in the LICENSE file.
4 
5 #include "libcef_dll/shutdown_checker.h"
6 
7 // For compatibility with older client compiler versions only use std::atomic
8 // on the library side.
9 #if defined(BUILDING_CEF_SHARED)
10 #include <atomic>
11 #else
12 #include "include/base/cef_atomic_ref_count.h"
13 #endif
14 
15 #include "include/base/cef_logging.h"
16 
17 namespace shutdown_checker {
18 
19 #if DCHECK_IS_ON()
20 
21 namespace {
22 
23 #if defined(BUILDING_CEF_SHARED)
24 
25 std::atomic_bool g_cef_shutdown{false};
26 
IsCefShutdown()27 bool IsCefShutdown() {
28   return g_cef_shutdown.load();
29 }
30 
SetCefShutdown()31 void SetCefShutdown() {
32   g_cef_shutdown.store(true);
33 }
34 
35 #else  // !defined(BUILDING_CEF_SHARED)
36 
37 base::AtomicRefCount g_cef_shutdown ATOMIC_DECLARATION;
38 
39 bool IsCefShutdown() {
40   return !base::AtomicRefCountIsZero(&g_cef_shutdown);
41 }
42 
43 void SetCefShutdown() {
44   base::AtomicRefCountInc(&g_cef_shutdown);
45 }
46 
47 #endif  // !defined(BUILDING_CEF_SHARED)
48 
49 }  // namespace
50 
AssertNotShutdown()51 void AssertNotShutdown() {
52   DCHECK(!IsCefShutdown())
53       << "Object reference incorrectly held at CefShutdown";
54 }
55 
SetIsShutdown()56 void SetIsShutdown() {
57   DCHECK(!IsCefShutdown());
58   SetCefShutdown();
59 }
60 
61 #else  // !DCHECK_IS_ON()
62 
63 void AssertNotShutdown() {}
64 
65 #endif  // !DCHECK_IS_ON()
66 
67 }  // namespace shutdown_checker
68