| OLD | NEW |
| 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 #include "src/once.h" | 5 #include "src/base/once.h" |
| 6 | 6 |
| 7 #ifdef _WIN32 | 7 #ifdef _WIN32 |
| 8 #include <windows.h> | 8 #include <windows.h> |
| 9 #else | 9 #else |
| 10 #include <sched.h> | 10 #include <sched.h> |
| 11 #endif | 11 #endif |
| 12 | 12 |
| 13 #include "src/atomicops.h" | 13 #include "src/base/atomicops.h" |
| 14 | 14 |
| 15 namespace v8 { | 15 namespace v8 { |
| 16 namespace internal { | 16 namespace base { |
| 17 | 17 |
| 18 void CallOnceImpl(OnceType* once, PointerArgFunction init_func, void* arg) { | 18 void CallOnceImpl(OnceType* once, PointerArgFunction init_func, void* arg) { |
| 19 AtomicWord state = Acquire_Load(once); | 19 AtomicWord state = Acquire_Load(once); |
| 20 // Fast path. The provided function was already executed. | 20 // Fast path. The provided function was already executed. |
| 21 if (state == ONCE_STATE_DONE) { | 21 if (state == ONCE_STATE_DONE) { |
| 22 return; | 22 return; |
| 23 } | 23 } |
| 24 | 24 |
| 25 // The function execution did not complete yet. The once object can be in one | 25 // The function execution did not complete yet. The once object can be in one |
| 26 // of the two following states: | 26 // of the two following states: |
| (...skipping 16 matching lines...) Expand all Loading... |
| 43 #ifdef _WIN32 | 43 #ifdef _WIN32 |
| 44 ::Sleep(0); | 44 ::Sleep(0); |
| 45 #else | 45 #else |
| 46 sched_yield(); | 46 sched_yield(); |
| 47 #endif | 47 #endif |
| 48 state = Acquire_Load(once); | 48 state = Acquire_Load(once); |
| 49 } | 49 } |
| 50 } | 50 } |
| 51 } | 51 } |
| 52 | 52 |
| 53 } } // namespace v8::internal | 53 } } // namespace v8::base |
| OLD | NEW |