| 12 | // immediately before setting the value to GOOGLE_ONCE_INTERNAL_DONE. |
| 13 | |
| 14 | void GoogleOnceInternalInit(Atomic32 *control, void (*func)(), |
| 15 | void (*func_with_arg)(void*), void* arg) { |
| 16 | if (DEBUG_MODE) { |
| 17 | int32 old_control = base::subtle::Acquire_Load(control); |
| 18 | if (old_control != GOOGLE_ONCE_INTERNAL_INIT && |
| 19 | old_control != GOOGLE_ONCE_INTERNAL_RUNNING && |
| 20 | old_control != GOOGLE_ONCE_INTERNAL_WAITER && |
| 21 | old_control != GOOGLE_ONCE_INTERNAL_DONE) { |
| 22 | LOG(FATAL) << "Either GoogleOnceType is used in non-static storage " |
| 23 | "(where GoogleOnceDynamic might be appropriate), " |
| 24 | "or there's a memory corruption."; |
| 25 | } |
| 26 | } |
| 27 | static const base::internal::SpinLockWaitTransition trans[] = { |
| 28 | { GOOGLE_ONCE_INTERNAL_INIT, GOOGLE_ONCE_INTERNAL_RUNNING, true }, |
| 29 | { GOOGLE_ONCE_INTERNAL_RUNNING, GOOGLE_ONCE_INTERNAL_WAITER, false }, |
| 30 | { GOOGLE_ONCE_INTERNAL_DONE, GOOGLE_ONCE_INTERNAL_DONE, true } |
| 31 | }; |
| 32 | // Short circuit the simplest case to avoid procedure call overhead. |
| 33 | if (base::subtle::Acquire_CompareAndSwap(control, GOOGLE_ONCE_INTERNAL_INIT, |
| 34 | GOOGLE_ONCE_INTERNAL_RUNNING) == GOOGLE_ONCE_INTERNAL_INIT || |
| 35 | base::internal::SpinLockWait(control, ARRAYSIZE(trans), trans) == |
| 36 | GOOGLE_ONCE_INTERNAL_INIT) { |
| 37 | if (func != nullptr) { |
| 38 | (*func)(); |
| 39 | } else { |
| 40 | (*func_with_arg)(arg); |
| 41 | } |
| 42 | ANNOTATE_HAPPENS_BEFORE(control); |
| 43 | int32 old_control = base::subtle::NoBarrier_Load(control); |
| 44 | base::subtle::Release_Store(control, GOOGLE_ONCE_INTERNAL_DONE); |
| 45 | if (old_control == GOOGLE_ONCE_INTERNAL_WAITER) { |
| 46 | base::internal::SpinLockWake(control, true); |
| 47 | } |
| 48 | } // else *control is already GOOGLE_ONCE_INTERNAL_DONE |
| 49 | } |
no test coverage detected