24#ifndef MEMORY_ALIGNED_ATOMIC_H 
   25#define MEMORY_ALIGNED_ATOMIC_H 
   34#include <sys/sysctl.h> 
   38#elif defined(__linux__) 
   53  size_t sizeof_line_size = 
sizeof(line_size);
 
   54  sysctlbyname(
"hw.cachelinesize", &line_size, &sizeof_line_size, 0, 0);
 
   63  SYSTEM_LOGICAL_PROCESSOR_INFORMATION *
buffer = 0;
 
   69  for (i = 0; i != 
buffer_size / 
sizeof(SYSTEM_LOGICAL_PROCESSOR_INFORMATION);
 
   72      line_size = 
buffer[i].Cache.LineSize;
 
   81#elif defined(__GLIBC__) 
   83  long size = sysconf(_SC_LEVEL1_DCACHE_LINESIZE);
 
   84  if (size == -1) 
return 64;
 
   89        "/sys/devices/system/cpu/cpu0/cache/index0/coherency_line_size", 
"r");
 
   91      if (fscanf(
p, 
"%ld", &size) != 1) size = 0;
 
   96  if (size > 0) 
return static_cast<size_t>(size);
 
  119  size_t size{
static_cast<size_t>(std::ceil(
static_cast<double>(
sizeof(T)) /
 
  120                                            static_cast<double>(csize))) *
 
  135  static const size_t size{memory::_cacheline_for<T>()};
 
  324  if (this->m_underlying != 
nullptr) {
 
  325    this->m_underlying->~atomic();
 
  328  this->m_storage = rhs.m_storage;
 
  329  this->m_storage_size = rhs.m_storage_size;
 
  330  this->m_underlying = rhs.m_underlying;
 
  331  rhs.m_storage = 
nullptr;
 
  332  rhs.m_storage_size = 0;
 
  333  rhs.m_underlying = 
nullptr;
 
  338  if (this->m_underlying != 
nullptr) {
 
  339    this->m_underlying->~atomic();
 
  342  this->m_storage = 
nullptr;
 
  343  this->m_storage_size = 0;
 
  344  this->m_underlying = 
nullptr;
 
  350  if (this->m_underlying != 
nullptr) {
 
  351    this->m_underlying->~atomic();
 
  354  this->m_storage = rhs.m_storage;
 
  355  this->m_storage_size = rhs.m_storage_size;
 
  356  this->m_underlying = rhs.m_underlying;
 
  357  rhs.m_storage = 
nullptr;
 
  358  rhs.m_storage_size = 0;
 
  359  rhs.m_underlying = 
nullptr;
 
  365  assert(this->m_underlying != 
nullptr);
 
  366  this->m_underlying->store(rhs, std::memory_order_seq_cst);
 
  372  assert(this->m_underlying != 
nullptr);
 
  373  return this->m_underlying->load(std::memory_order_relaxed);
 
  378  return this->m_underlying == 
nullptr;
 
  383  return this->m_underlying != 
nullptr;
 
  388  if (this->m_underlying == 
nullptr) 
return false;
 
  389  return this->m_underlying->load(std::memory_order_relaxed) == rhs;
 
  394  return !((*this) == rhs);
 
  399  assert(this->m_underlying != 
nullptr);
 
  400  return this->m_underlying;
 
  405  assert(this->m_underlying != 
nullptr);
 
  406  return this->m_underlying;
 
  411  assert(this->m_underlying != 
nullptr);
 
  412  return *this->m_underlying;
 
  417  assert(this->m_underlying != 
nullptr);
 
  418  return *this->m_underlying;
 
  423  return sizeof(std::atomic<T>);
 
  428  return this->m_storage_size;
 
Templated class that encapsulates an std::atomic within a byte buffer that is padded to the processor...
Definition: aligned_atomic.h:154
 
Aligned_atomic< T > & operator=(Aligned_atomic< T > const &rhs)=delete
 
Aligned_atomic(Aligned_atomic< T > &&rhs)
Definition: aligned_atomic.h:323
 
size_t allocated_size() const
Definition: aligned_atomic.h:427
 
const std::atomic< T > * operator->() const
Definition: aligned_atomic.h:404
 
Aligned_atomic< T > & operator=(Aligned_atomic< T > &&rhs)
Definition: aligned_atomic.h:348
 
virtual ~Aligned_atomic()
Definition: aligned_atomic.h:337
 
bool operator!=(std::nullptr_t rhs) const
Inequality operator to determine if the underlying storage memory is initialized.
Definition: aligned_atomic.h:382
 
bool operator==(T rhs) const
Equality operator for determining if the value stored in the underlying std::atomic equals the passed...
Definition: aligned_atomic.h:387
 
std::atomic< T > * operator->()
Definition: aligned_atomic.h:398
 
Aligned_atomic(Aligned_atomic< T > const &rhs)=delete
 
Aligned_atomic< T > & operator=(T rhs)
Definition: aligned_atomic.h:364
 
size_t size() const
Definition: aligned_atomic.h:422
 
Aligned_atomic()
Definition: aligned_atomic.h:310
 
std::atomic< T > & operator*()
Definition: aligned_atomic.h:410
 
size_t m_storage_size
The size of the byte buffer.
Definition: aligned_atomic.h:301
 
void * m_storage
The byte buffer to use as underlying storage.
Definition: aligned_atomic.h:303
 
bool operator==(std::nullptr_t rhs) const
Equality operator to determine if the underlying storage memory is initialized.
Definition: aligned_atomic.h:377
 
const std::atomic< T > & operator*() const
Definition: aligned_atomic.h:416
 
Aligned_atomic(T value)
Definition: aligned_atomic.h:317
 
std::atomic< T > * m_underlying
The pointer to the underlying std::atomic<T> object.
Definition: aligned_atomic.h:305
 
bool operator!=(T rhs) const
Inequality operator for determining if the value stored in the underlying std::atomic differs from th...
Definition: aligned_atomic.h:393
 
const char * p
Definition: ctype-mb.cc:1237
 
#define malloc(A)
Definition: lexyy.cc:914
 
#define free(A)
Definition: lexyy.cc:915
 
void * my_aligned_malloc(size_t size, size_t alignment)
Function allocates size bytes and returns a pointer to the allocated memory.
Definition: my_aligned_malloc.cc:38
 
void my_aligned_free(void *ptr)
Free allocated memory using my_aligned_malloc function.
Definition: my_aligned_malloc.cc:63
 
const std::string FILE("FILE")
 
std::unordered_map< meta::Metadata, Data_extension, meta::Metadata::Hash > Cache
Definition: cache.h:38
 
Definition: aligned_atomic.h:44
 
static size_t cache_line_size()
Definition: aligned_atomic.h:103
 
static size_t _cache_line_size()
Calculates and returns the size of the CPU cache line.
Definition: aligned_atomic.h:101
 
static size_t minimum_cacheline_for()
Retrieves the amount of bytes, multiple of the current cacheline size, needed to store an element of ...
Definition: aligned_atomic.h:134
 
static size_t _cacheline_for()
Retrieves the amount of bytes, multiple of the current cacheline size, needed to store an element of ...
Definition: aligned_atomic.h:117
 
mutable_buffer buffer(void *p, size_t n) noexcept
Definition: buffer.h:420
 
size_t buffer_size(const ConstBufferSequence &buffers) noexcept
Definition: buffer.h:315
 
Definition: gcs_xcom_synode.h:64