Skip to content

Instantly share code, notes, and snippets.

@danlark1
Created January 11, 2020 21:10
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save danlark1/24e3f3dad0aef41f957162ccd15d7a30 to your computer and use it in GitHub Desktop.
Save danlark1/24e3f3dad0aef41f957162ccd15d7a30 to your computer and use it in GitHub Desktop.
// This is reserved space for an absl::Mutex to guard flag data. It will be
// initialized in FlagImpl::Init via placement new.
// We can't use "absl::Mutex data_guard_", since this class is not literal.
// We do not want to use "absl::Mutex* data_guard_", since this would require
// heap allocation during initialization, which is both slows program startup
// and can fail. Using reserved space + placement new allows us to avoid both
// problems.
alignas(absl::Mutex) mutable char data_guard_[sizeof(absl::Mutex)];
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment