Export of internal Abseil changes
-- b8e6b64b604449bb51ed0ba8e9439097f3aa8773 by Abseil Team <absl-team@google.com>: fix typo 'implentation' -> 'implementation' PiperOrigin-RevId: 311623471 -- 2b9262a311f3329c8006835a79498edd90568acd by Matt Kulukundis <kfm@google.com>: Internal cleanup PiperOrigin-RevId: 311549039 -- 7507ed3c28113e28f993aa634bd44a9a0d4c4a2c by Derek Mauro <dmauro@google.com>: Delete LinkerInitialized Now that all SpinLocks have the same scheduling mode for their entire lives, the scheduling mode does not need to be re-tested in the loop in LockSlow. PiperOrigin-RevId: 311521474 -- abf5fae67e21b38cda4083aaafd7012e2c6fbb7d by Andy Getzendanner <durandal@google.com>: Fix public target name of the random library Import of https://github.com/abseil/abseil-cpp/pull/684 PiperOrigin-RevId: 311429555 GitOrigin-RevId: b8e6b64b604449bb51ed0ba8e9439097f3aa8773 Change-Id: Ic48f671846bda059cc46f4a0b967cc3b1a733ba0
This commit is contained in:
parent
f2bc9d11e8
commit
d118d4bb11
6 changed files with 14 additions and 95 deletions
|
|
@ -209,31 +209,22 @@ class SynchronizationStorage {
|
|||
// Instances allocated on the heap or on the stack should use the default
|
||||
// constructor.
|
||||
SynchronizationStorage()
|
||||
: is_dynamic_(true), once_() {}
|
||||
|
||||
// Instances allocated in static storage (not on the heap, not on the
|
||||
// stack) should use this constructor.
|
||||
explicit SynchronizationStorage(base_internal::LinkerInitialized) {}
|
||||
: destruct_(true), once_() {}
|
||||
|
||||
constexpr explicit SynchronizationStorage(absl::ConstInitType)
|
||||
: is_dynamic_(false), once_(), space_{{0}} {}
|
||||
: destruct_(false), once_(), space_{{0}} {}
|
||||
|
||||
SynchronizationStorage(SynchronizationStorage&) = delete;
|
||||
SynchronizationStorage& operator=(SynchronizationStorage&) = delete;
|
||||
|
||||
~SynchronizationStorage() {
|
||||
if (is_dynamic_) {
|
||||
if (destruct_) {
|
||||
get()->~T();
|
||||
}
|
||||
}
|
||||
|
||||
// Retrieve the object in storage. This is fast and thread safe, but does
|
||||
// incur the cost of absl::call_once().
|
||||
//
|
||||
// For instances in static storage constructed with the
|
||||
// LinkerInitialized constructor, may be called at any time without
|
||||
// regard for order of dynamic initialization or destruction of objects
|
||||
// in static storage. See the class comment for caveats.
|
||||
T* get() {
|
||||
absl::call_once(once_, SynchronizationStorage::Construct, this);
|
||||
return reinterpret_cast<T*>(&space_);
|
||||
|
|
@ -245,10 +236,7 @@ class SynchronizationStorage {
|
|||
}
|
||||
|
||||
// When true, T's destructor is run when this is destructed.
|
||||
//
|
||||
// The LinkerInitialized constructor assumes this value will be set
|
||||
// false by static initialization.
|
||||
bool is_dynamic_;
|
||||
const bool destruct_;
|
||||
|
||||
absl::once_flag once_;
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue