Lines Matching +full:zero +full:- +full:initialised
2 * Copyright 2010-2012 PathScale, Inc. All rights reserved.
29 * guard.cc: Functions for thread-safe static initialisation.
31 * Static values in C++ can be initialised lazily their first use. This file
37 * Statics that require initialisation are protected by a 64-bit value. Any
38 * platform that can do 32-bit atomic test and set operations can use this
39 * value as a low-overhead lock. Because statics (in most sane code) are
40 * accessed far more times than they are initialised, this lock implementation
42 * initialised.
57 // x86 and ARM are the most common little-endian CPUs, so let's have a
66 * The Itanium C++ ABI defines guard words that are 64-bit (32-bit on AArch32)
71 * On many 32-bit platforms, 64-bit atomics are unavailable (or slow) and so we
72 * treat the two halves of the 64-bit word as independent values and establish
74 * lock word is in the locked state. This means that we can do double-checked
75 * locking by loading the guard word and, if it is not initialised, trying to
107 * indicate the initialised state is `1<<InitBit`.
119 * The value indicating that the initialised bit is set (and all other
120 * bits are zero).
122 static constexpr GuardWord initialised = static_cast<GuardWord>(1) member
132 * Release the lock and set the initialised state. In the single-word
137 val.store(isInitialised ? initialised : 0, memory_order::release); in unlock()
139 GuardWord init_state = initialised; in unlock()
145 * Try to acquire the lock. This has a tri-state return, indicating
148 * already initialised.
154 // the lock is not held and the variable is not initialised (so the in try_lock()
161 // initialised, return that initialisation is done and skip further in try_lock()
163 if (old == initialised) in try_lock()
172 * Check whether the guard indicates that the variable is initialised.
176 return (val.load(memory_order::acquire) & initialised) == in is_initialised()
177 initialised; in is_initialised()
182 * Class encapsulating using two 32-bit atomic values to represent a 64-bit
195 * The value of `init_word` when the guarded variable is initialised.
197 static constexpr uint32_t initialised = static_cast<uint32_t>(1) member in __anone6a749c70111::DoubleWordGuard
201 * The word used for the initialised flag. This is always the first
214 * Try to acquire the lock. This has a tri-state return, indicating
217 * already initialised.
227 // lock and initialised bits together. Instead, we have an in try_lock()
228 // ordering rule that the initialised bit is only ever updated in try_lock()
244 * Set the initialised state and release the lock. In this
250 init_word.store(isInitialised ? initialised : 0, in unlock()
257 * Return whether the guarded variable is initialised.
261 return (init_word.load(memory_order::acquire) & initialised) == in is_initialised()
262 initialised; in is_initialised()
268 "Single-word 32-bit guard must be 32 bits");
270 "Single-word 64-bit guard must be 64 bits");
272 "Double-word guard must be 64 bits");
276 * The Arm PCS defines a variant of the Itanium ABI with 32-bit lock words.
282 * On little-endian 64-bit platforms the guard word is a single 64-bit
283 * atomic with the lock in the high bit and the initialised flag in the low
289 * On bit-endian 64-bit platforms, the guard word is a single 64-bit atomic
290 * with the lock in the low bit and the initialised bit in the highest
298 * 32-bit platforms use the same layout as 64-bit.
303 * 32-bit platforms use the same layout as 64-bit.
313 * initialised, and 1 if it has not. If the object is already constructed then
318 // Check if this is already initialised. If so, we don't have to do in __cxa_guard_acquire()
320 if (guard_object->is_initialised()) in __cxa_guard_acquire()
331 switch (guard_object->try_lock()) in __cxa_guard_acquire()
334 // initialised the lock while we were waiting, return immediately in __cxa_guard_acquire()
351 * Releases the lock without marking the object as initialised. This function
356 guard_object->unlock(false); in __cxa_guard_abort()
360 * Releases the guard and marks the object as initialised. This function is
365 guard_object->unlock(true); in __cxa_guard_release()