Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(243)

Side by Side Diff: src/base/once.h

Issue 2381273002: Turn libbase into a component (Closed)
Patch Set: updates Created 4 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « src/base/logging.h ('k') | src/base/platform/condition-variable.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2012 the V8 project authors. All rights reserved. 1 // Copyright 2012 the V8 project authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 // emulates google3/base/once.h 5 // emulates google3/base/once.h
6 // 6 //
7 // This header is intended to be included only by v8's internal code. Users 7 // This header is intended to be included only by v8's internal code. Users
8 // should not use this directly. 8 // should not use this directly.
9 // 9 //
10 // This is basically a portable version of pthread_once(). 10 // This is basically a portable version of pthread_once().
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
48 // but it is technically not guaranteed. Unfortunately, Win32 provides no way 48 // but it is technically not guaranteed. Unfortunately, Win32 provides no way
49 // whatsoever to statically-initialize its synchronization primitives, so our 49 // whatsoever to statically-initialize its synchronization primitives, so our
50 // only choice is to assume that dynamic initialization is single-threaded. 50 // only choice is to assume that dynamic initialization is single-threaded.
51 51
52 #ifndef V8_BASE_ONCE_H_ 52 #ifndef V8_BASE_ONCE_H_
53 #define V8_BASE_ONCE_H_ 53 #define V8_BASE_ONCE_H_
54 54
55 #include <stddef.h> 55 #include <stddef.h>
56 56
57 #include "src/base/atomicops.h" 57 #include "src/base/atomicops.h"
58 #include "src/base/base-export.h"
58 59
59 namespace v8 { 60 namespace v8 {
60 namespace base { 61 namespace base {
61 62
62 typedef AtomicWord OnceType; 63 typedef AtomicWord OnceType;
63 64
64 #define V8_ONCE_INIT 0 65 #define V8_ONCE_INIT 0
65 66
66 #define V8_DECLARE_ONCE(NAME) ::v8::base::OnceType NAME 67 #define V8_DECLARE_ONCE(NAME) ::v8::base::OnceType NAME
67 68
68 enum { 69 enum {
69 ONCE_STATE_UNINITIALIZED = 0, 70 ONCE_STATE_UNINITIALIZED = 0,
70 ONCE_STATE_EXECUTING_FUNCTION = 1, 71 ONCE_STATE_EXECUTING_FUNCTION = 1,
71 ONCE_STATE_DONE = 2 72 ONCE_STATE_DONE = 2
72 }; 73 };
73 74
74 typedef void (*NoArgFunction)(); 75 typedef void (*NoArgFunction)();
75 typedef void (*PointerArgFunction)(void* arg); 76 typedef void (*PointerArgFunction)(void* arg);
76 77
77 template <typename T> 78 template <typename T>
78 struct OneArgFunction { 79 struct OneArgFunction {
79 typedef void (*type)(T); 80 typedef void (*type)(T);
80 }; 81 };
81 82
82 void CallOnceImpl(OnceType* once, PointerArgFunction init_func, void* arg); 83 V8_BASE_EXPORT void CallOnceImpl(OnceType* once, PointerArgFunction init_func,
84 void* arg);
83 85
84 inline void CallOnce(OnceType* once, NoArgFunction init_func) { 86 inline void CallOnce(OnceType* once, NoArgFunction init_func) {
85 if (Acquire_Load(once) != ONCE_STATE_DONE) { 87 if (Acquire_Load(once) != ONCE_STATE_DONE) {
86 CallOnceImpl(once, reinterpret_cast<PointerArgFunction>(init_func), NULL); 88 CallOnceImpl(once, reinterpret_cast<PointerArgFunction>(init_func), NULL);
87 } 89 }
88 } 90 }
89 91
90 92
91 template <typename Arg> 93 template <typename Arg>
92 inline void CallOnce(OnceType* once, 94 inline void CallOnce(OnceType* once,
93 typename OneArgFunction<Arg*>::type init_func, Arg* arg) { 95 typename OneArgFunction<Arg*>::type init_func, Arg* arg) {
94 if (Acquire_Load(once) != ONCE_STATE_DONE) { 96 if (Acquire_Load(once) != ONCE_STATE_DONE) {
95 CallOnceImpl(once, reinterpret_cast<PointerArgFunction>(init_func), 97 CallOnceImpl(once, reinterpret_cast<PointerArgFunction>(init_func),
96 static_cast<void*>(arg)); 98 static_cast<void*>(arg));
97 } 99 }
98 } 100 }
99 101
100 } // namespace base 102 } // namespace base
101 } // namespace v8 103 } // namespace v8
102 104
103 #endif // V8_BASE_ONCE_H_ 105 #endif // V8_BASE_ONCE_H_
OLDNEW
« no previous file with comments | « src/base/logging.h ('k') | src/base/platform/condition-variable.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698