//------------------------------------------------------------------------------
// File: AlignedArray.hh
// Author: Abhishek Lekshmanan - CERN
//------------------------------------------------------------------------------
/************************************************************************
* EOS - the CERN Disk Storage System *
* Copyright (C) 2023 CERN/Switzerland *
* *
* This program is free software: you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation, either version 3 of the License, or *
* (at your option) any later version. *
* *
* This program is distributed in the hope that it will be useful, *
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
* GNU General Public License for more details. *
* *
* You should have received a copy of the GNU General Public License *
* along with this program. If not, see .*
************************************************************************/
#pragma once
#include "common/concurrency/AlignMacros.hh"
#include
#include
namespace eos::common {
template
struct alignas(hardware_destructive_interference_size) AlignedAtomic
: private std::atomic {
using std::atomic::atomic;
using std::atomic::operator=;
using std::atomic::store;
using std::atomic::load;
using std::atomic::exchange;
using std::atomic::fetch_add;
using std::atomic::fetch_sub;
};
// Check some basic properties of AlignedAtomic; since we have this at compile
// time and asserts do not exist in actual code, compiler does the unit testing for us
static_assert(sizeof(AlignedAtomic) == hardware_destructive_interference_size,
"AlignedAtomic should be hardware_destructive_interference_size");
static_assert(alignof(AlignedAtomic) == hardware_destructive_interference_size,
"AlignedAtomic should be hardware_destructive_interference_size");
// An array where each element is aligned to hardware_destructive_interference_size
// ie. elements do not share cache lines
template
using AlignedAtomicArray = std::array, N>;
} // namespace eos::common