ATLAS Offline Software
Public Types | Public Member Functions | Private Attributes | List of all members
CxxUtils::ConcurrentBitset::Impl Class Reference

Implementation object. More...

Collaboration diagram for CxxUtils::ConcurrentBitset::Impl:

Public Types

typedef void operator_t(std::atomic< Block_t > &a, Block_t v)
 

Public Member Functions

void * operator new (size_t, bit_t nbits)
 Allocate an Impl structure. More...
 
void operator delete (void *p)
 
 Impl (bit_t nbits)
 Constructor. More...
 
 Impl (const Impl &other, bit_t nbits=0)
 Copy constructor. More...
 
Imploperator= (const Impl &)=delete
 
void assign (const Impl &other)
 Copy from another instance. More...
 
bit_t nbits () const
 Return the number of bits in the set. More...
 
bool test (bit_t bit) const
 Test to see if a bit is set. More...
 
bit_t count () const
 
bool none () const
 Return true if there are no 1 bits in the set. More...
 
bool all () const
 Return true if all bits in the set are 1. More...
 
std::atomic< Block_t > * block (bit_t bit)
 Return a pointer to the block containing bit. More...
 
void set (bit_t bit)
 Turn on one bit. More...
 
void reset (bit_t bit)
 Turn off one bit. More...
 
void flip (bit_t bit)
 Flip the value of one bit. More...
 
void clear ()
 Clear all bits in the set. More...
 
void set ()
 Turn on all bits in the set. More...
 
void flip ()
 Flip the state of all bits in the set. More...
 
void operate (operator_t op, const Impl &other)
 Apply a binary operation. More...
 
bool operator== (const Impl &other) const
 Compare with another set. More...
 
const_iterator begin () const
 Return an iterator referencing the first 1 bit. More...
 
const_iterator end () const
 Return the end iterator. More...
 
const_iterator find (bit_t bit) const
 If bit bit is set, return an iterator pointing to it. More...
 

Private Attributes

size_t m_nbits
 Number of bits in the container. More...
 
size_t m_nblocks
 Number of blocks in the container. More...
 
std::atomic< size_t > m_hwm
 High-water mark: index of last block with a 1 bit. More...
 
std::atomic< Block_tm_data [1]
 The set data. More...
 

Detailed Description

Implementation object.

An instance of this holds the set data for a fixed size. If the set needs to be expanded, a new implementation object must be allocated and the data copied.

This object consists of a fixed header, followed by a variable-sized array containing the actual set data. In this class, the array is declared with a size of 1; however, we allocate these objects (using the newImpl function) with enough space to hold the entire set.

This class also contains the basic methods for operating on the set.

Definition at line 845 of file ConcurrentBitset.h.

Member Typedef Documentation

◆ operator_t

typedef void CxxUtils::ConcurrentBitset::Impl::operator_t(std::atomic< Block_t > &a, Block_t v)

Definition at line 1005 of file ConcurrentBitset.h.

Constructor & Destructor Documentation

◆ Impl() [1/2]

CxxUtils::ConcurrentBitset::Impl::Impl ( bit_t  nbits)

Constructor.

Parameters
nbitsNumber of bits in the set.

◆ Impl() [2/2]

CxxUtils::ConcurrentBitset::Impl::Impl ( const Impl other,
bit_t  nbits = 0 
)

Copy constructor.

Other object to copy.

Number of bits to use for this container.

If nbits is smaller than the size of other, then the size of other will be used instead.

Member Function Documentation

◆ all()

bool CxxUtils::ConcurrentBitset::Impl::all ( ) const

Return true if all bits in the set are 1.

Definition at line 234 of file ConcurrentBitset.cxx.

235 {
236  if (m_nblocks == 0) {
237  return true;
238  }
239 
240  // Check all blocks except the last.
241  for (bit_t i = 0; i < m_nblocks-1; i++) {
242  if (m_data[i] != ~static_cast<Block_t>(0)) return false;
243  }
244  // Special case for the last, since the last block may not be full.
245  if (m_data[m_nblocks] != ones<Block_t> (m_nbits - (m_nblocks-1)*BLOCKSIZE)) {
246  return false;
247  }
248  return true;
249 }

◆ assign()

void CxxUtils::ConcurrentBitset::Impl::assign ( const Impl other)

Copy from another instance.

Parameters
otherObject from which to copy.

This does not change the size of the container. If This container is larger than other, then the remainder will be filled with zeros. If other is larger than this container, then the remainder will be ignored.

◆ begin()

const_iterator CxxUtils::ConcurrentBitset::Impl::begin ( ) const

Return an iterator referencing the first 1 bit.

◆ block()

std::atomic<Block_t>* CxxUtils::ConcurrentBitset::Impl::block ( bit_t  bit)

Return a pointer to the block containing bit.

Parameters
bitDesired bit number.

Returns nullptr if bit is past the end of the set.

◆ clear()

void CxxUtils::ConcurrentBitset::Impl::clear ( )

Clear all bits in the set.

This operation is not necessarily atomic; a simultaneous read may be able to see the operation partially done.

◆ count()

ConcurrentBitset::bit_t CxxUtils::ConcurrentBitset::Impl::count ( ) const

Definition at line 209 of file ConcurrentBitset.cxx.

210 {
211  bit_t n = 0;
212  for (bit_t i=0; i<m_nblocks; i++) {
214  }
215  return n;
216 }

◆ end()

const_iterator CxxUtils::ConcurrentBitset::Impl::end ( ) const

Return the end iterator.

◆ find()

const_iterator CxxUtils::ConcurrentBitset::Impl::find ( bit_t  bit) const

If bit bit is set, return an iterator pointing to it.

Otherwise, return an end iterator.

Parameters
bitBit number to test.

◆ flip() [1/2]

void CxxUtils::ConcurrentBitset::Impl::flip ( )

Flip the state of all bits in the set.

This operation is not necessarily atomic; a simultaneous read may be able to see the operation partially done.

Definition at line 276 of file ConcurrentBitset.cxx.

277 {
278  for (bit_t i=0; i<m_nblocks; i++) {
279  m_data[i] ^= ~static_cast<Block_t>(0);
280  }
281  if (m_nblocks > 0) {
282  m_hwm = m_nblocks-1;
283  }
284 }

◆ flip() [2/2]

void CxxUtils::ConcurrentBitset::Impl::flip ( bit_t  bit)

Flip the value of one bit.

Parameters
bitThe bit to turn flip.

Does nothing if bit beyond the end of the set.

◆ nbits()

bit_t CxxUtils::ConcurrentBitset::Impl::nbits ( ) const

Return the number of bits in the set.

◆ none()

bool CxxUtils::ConcurrentBitset::Impl::none ( ) const

Return true if there are no 1 bits in the set.

Definition at line 222 of file ConcurrentBitset.cxx.

223 {
224  for (bit_t i = 0; i < m_nblocks; i++) {
225  if (m_data[i]) return false;
226  }
227  return true;
228 }

◆ operate()

void CxxUtils::ConcurrentBitset::Impl::operate ( operator_t  op,
const Impl other 
)

Apply a binary operation.

Parameters
opOperation to apply.
otherSecond set for the operation.

Each block B in this set is replaced by B OP OTHER, where OTHER is the corresponding block in the other container. (If this set is larger than other, then the trailing blocks will be 0.)

◆ operator delete()

void CxxUtils::ConcurrentBitset::Impl::operator delete ( void *  p)

◆ operator new()

void* CxxUtils::ConcurrentBitset::Impl::operator new ( size_t  ,
bit_t  nbits 
)

Allocate an Impl structure.

Parameters
szSize of an Impl structure.
nbitsNumber of bits to allocate.

◆ operator=()

Impl& CxxUtils::ConcurrentBitset::Impl::operator= ( const Impl )
delete

◆ operator==()

bool CxxUtils::ConcurrentBitset::Impl::operator== ( const Impl other) const

Compare with another set.

Parameters
otherOther set with which to compare.

◆ reset()

void CxxUtils::ConcurrentBitset::Impl::reset ( bit_t  bit)

Turn off one bit.

Parameters
bitThe bit to turn off.

Does nothing if bit beyond the end of the set.

◆ set() [1/2]

void CxxUtils::ConcurrentBitset::Impl::set ( )

Turn on all bits in the set.

This operation is not necessarily atomic; a simultaneous read may be able to see the operation partially done.

Definition at line 258 of file ConcurrentBitset.cxx.

259 {
260  for (bit_t i=0; i<m_nblocks; i++) {
261  m_data[i].store (~static_cast<Block_t>(0), std::memory_order_relaxed);
262  }
263  std::atomic_thread_fence (std::memory_order_seq_cst);
264  if (m_nblocks > 0) {
265  m_hwm = m_nblocks-1;
266  }
267 }

◆ set() [2/2]

void CxxUtils::ConcurrentBitset::Impl::set ( bit_t  bit)

Turn on one bit.

Parameters
bitThe bit to turn on.

Does nothing if bit beyond the end of the set.

◆ test()

bool CxxUtils::ConcurrentBitset::Impl::test ( bit_t  bit) const

Test to see if a bit is set.

Parameters
bitNumber of the bit to test.
Returns
true if the bit is set; false otherwise.

Returns false if bit is beyond the end of the set.

Member Data Documentation

◆ m_data

std::atomic<Block_t> CxxUtils::ConcurrentBitset::Impl::m_data[1]
private

The set data.

The implementation objects are allocated such that there are actually m_nblocks entries available in this array.

Definition at line 1059 of file ConcurrentBitset.h.

◆ m_hwm

std::atomic<size_t> CxxUtils::ConcurrentBitset::Impl::m_hwm
private

High-water mark: index of last block with a 1 bit.

Definition at line 1054 of file ConcurrentBitset.h.

◆ m_nbits

size_t CxxUtils::ConcurrentBitset::Impl::m_nbits
private

Number of bits in the container.

Definition at line 1048 of file ConcurrentBitset.h.

◆ m_nblocks

size_t CxxUtils::ConcurrentBitset::Impl::m_nblocks
private

Number of blocks in the container.

Definition at line 1051 of file ConcurrentBitset.h.


The documentation for this class was generated from the following files:
CxxUtils::ConcurrentBitset::Impl::m_nblocks
size_t m_nblocks
Number of blocks in the container.
Definition: ConcurrentBitset.h:1051
CxxUtils::ConcurrentBitset::Block_t
unsigned long Block_t
Internal type used to hold the bitset data.
Definition: ConcurrentBitset.h:149
CxxUtils::ConcurrentBitset::bit_t
size_t bit_t
A bit number.
Definition: ConcurrentBitset.h:164
lumiFormat.i
int i
Definition: lumiFormat.py:85
CxxUtils::ConcurrentBitset::Impl::m_data
std::atomic< Block_t > m_data[1]
The set data.
Definition: ConcurrentBitset.h:1059
beamspotman.n
n
Definition: beamspotman.py:731
CxxUtils::count_ones
constexpr unsigned count_ones(unsigned x)
Count number of set bits.
Definition: bitscan.h:141
CxxUtils::ConcurrentBitset::Impl::m_nbits
size_t m_nbits
Number of bits in the container.
Definition: ConcurrentBitset.h:1048
CxxUtils::ConcurrentBitset::BLOCKSIZE
static const size_t BLOCKSIZE
Size, in bits, of Block_t.
Definition: ConcurrentBitset.h:158
CxxUtils::ConcurrentBitset::Impl::m_hwm
std::atomic< size_t > m_hwm
High-water mark: index of last block with a 1 bit.
Definition: ConcurrentBitset.h:1054