ATLAS Offline Software
Loading...
Searching...
No Matches
SG::AuxVectorData::Cache Class Reference

Manage cache of pointers to aux element vectors. More...

#include <AuxVectorData.h>

Collaboration diagram for SG::AuxVectorData::Cache:

Public Member Functions

 Cache ()
 Cache manager constructor.
 Cache (Cache &&rhs)
 Cache manager move constructor.
Cacheoperator= (Cache &&rhs)
 Cache manager move assignment.
 ~Cache ()
 Cache manager destructor.
void * cachePtr (SG::auxid_t auxid)
 Test to see if auxid is valid in the cache.
void * getDataArray (SG::auxid_t auxid, AuxVectorData &parent)
 Return a pointer to the start of an aux data vector.
const void * getDataArray (SG::auxid_t auxid, const AuxVectorData &parent)
 Return a const pointer to the start of an aux data vector.
const void * getDataArrayAllowMissing (SG::auxid_t auxid, const AuxVectorData &parent)
 Return a const pointer to the start of an aux data vector.
void * getDecorationArray (SG::auxid_t auxid, const AuxVectorData &parent)
 Return a pointer to the start of an aux decoration vector.
const AuxDataSpanBasegetDataSpan (SG::auxid_t auxid, const AuxVectorData &parent)
 Return a reference to a description of this vector's start+size.
void swap (Cache &other)
 Swap this cache object with another.
void clear ()
 Clear the cache (and free any old cache vectors).
void clear (SG::auxid_t auxid)
 Clear the cached pointer for a single variable.
void store (SG::auxid_t auxid, void *ptr)
 Store a pointer for auxid in the cache.

Public Attributes

void ** m_cache [2]
 Pointer to the cache vector.
size_t m_cache_len
 Length of the cache vector.
std::vector< void ** > m_allcache
 All cache vectors that have been allocated.

Private Member Functions

 Cache (const Cache &)
Cacheoperator= (const Cache &)

Detailed Description

Manage cache of pointers to aux element vectors.

See the thread-safety comments at the start of this file for notes on what's going on here.

Definition at line 718 of file AuxVectorData.h.

Constructor & Destructor Documentation

◆ Cache() [1/3]

SG::AuxVectorData::Cache::Cache ( )

Cache manager constructor.

Definition at line 490 of file AuxVectorData.cxx.

491 : m_cache(),
492 m_cache_len(0)
493{
494}
void ** m_cache[2]
Pointer to the cache vector.
size_t m_cache_len
Length of the cache vector.

◆ Cache() [2/3]

SG::AuxVectorData::Cache::Cache ( Cache && rhs)

Cache manager move constructor.

Parameters
rhsThe cache from which to copy.

Definition at line 501 of file AuxVectorData.cxx.

502 : m_cache_len (rhs.m_cache_len),
503 m_allcache (std::move (rhs.m_allcache))
504{
505 m_cache[0] = rhs.m_cache[0];
506 m_cache[1] = rhs.m_cache[1];
507 rhs.m_cache[0] = 0;
508 rhs.m_cache[1] = 0;
509 rhs.m_cache_len = 0;
510}
std::vector< void ** > m_allcache
All cache vectors that have been allocated.

◆ ~Cache()

SG::AuxVectorData::Cache::~Cache ( )

Cache manager destructor.

Definition at line 537 of file AuxVectorData.cxx.

538{
539 for (size_t i=0; i < m_allcache.size(); i++) delete [] m_allcache[i];
540}

◆ Cache() [3/3]

SG::AuxVectorData::Cache::Cache ( const Cache & )
private

Member Function Documentation

◆ cachePtr()

void * SG::AuxVectorData::Cache::cachePtr ( SG::auxid_t auxid)

Test to see if auxid is valid in the cache.

Returns
If auxid is valid, return the pointer to the vector, else 0.

◆ clear() [1/2]

void SG::AuxVectorData::Cache::clear ( )

Clear the cache (and free any old cache vectors).

Definition at line 558 of file AuxVectorData.cxx.

559{
560 if (m_cache_len > 0) {
561 if (m_allcache.size() > 1) {
562 for (size_t i=0; i < m_allcache.size()-1; i++)
563 delete [] m_allcache[i];
564 m_allcache[0] = m_allcache.back();
565 m_allcache.resize(1);
566 }
567 std::fill (m_cache[0], m_cache[0] + m_cache_len, static_cast<void*>(0));
568 }
569}

◆ clear() [2/2]

void SG::AuxVectorData::Cache::clear ( SG::auxid_t auxid)

Clear the cached pointer for a single variable.

Parameters
auxidID of the variable to clear.

Not really safe to use if another thread may be accessing the same variable.

Definition at line 579 of file AuxVectorData.cxx.

580{
581 if (auxid < m_cache_len) {
582 m_cache[0][auxid] = nullptr;
583 }
584}

◆ getDataArray() [1/2]

void * SG::AuxVectorData::Cache::getDataArray ( SG::auxid_t auxid,
AuxVectorData & parent )

Return a pointer to the start of an aux data vector.

Parameters
auxidThe desired aux data item.
parentThe containing AuxVectorData object.

This will return a pointer to the start of the data for aux data item auxid. If the item doesn't exist, it will be created. Errors are signaled by raising an exception.

◆ getDataArray() [2/2]

const void * SG::AuxVectorData::Cache::getDataArray ( SG::auxid_t auxid,
const AuxVectorData & parent )

Return a const pointer to the start of an aux data vector.

Parameters
auxidThe desired aux data item.
parentThe containing AuxVectorData object.

This will return a pointer to the start of the data for aux data item auxid. Errors are signaled by raising an exception.

◆ getDataArrayAllowMissing()

const void * SG::AuxVectorData::Cache::getDataArrayAllowMissing ( SG::auxid_t auxid,
const AuxVectorData & parent )

Return a const pointer to the start of an aux data vector.

Parameters
auxidThe desired aux data item.
parentThe containing AuxVectorData object.

This will return a pointer to the start of the data for aux data item auxid. If the item does not exist, this will return nullptr rather than raising an exception.

◆ getDataSpan()

const AuxDataSpanBase * SG::AuxVectorData::Cache::getDataSpan ( SG::auxid_t auxid,
const AuxVectorData & parent )

Return a reference to a description of this vector's start+size.

Parameters
auxidThe desired aux data item.

◆ getDecorationArray()

void * SG::AuxVectorData::Cache::getDecorationArray ( SG::auxid_t auxid,
const AuxVectorData & parent )

Return a pointer to the start of an aux decoration vector.

Parameters
auxidThe desired aux decoration item.
parentThe containing AuxVectorData object.

This will return a pointer to the start of the data for aux decoration item auxid. If the item doesn't exist, it will be created. Errors are signaled by raising an exception.

The difference between getDecorationArray and getDataArray is that getDecorationArray takes a const container as input, but returns a non-const pointer. This will only succeed if either the container is not locked or the item was first accessed as a decoration.

◆ operator=() [1/2]

AuxVectorData::Cache & SG::AuxVectorData::Cache::operator= ( Cache && rhs)

Cache manager move assignment.

Parameters
rhsThe cache from which to copy.

Definition at line 517 of file AuxVectorData.cxx.

518{
519 if (this != &rhs) {
520 clear();
521 m_cache_len = rhs.m_cache_len;
522 m_allcache = std::move (rhs.m_allcache);
523
524 m_cache[0] = rhs.m_cache[0];
525 m_cache[1] = rhs.m_cache[1];
526 rhs.m_cache[0] = 0;
527 rhs.m_cache[1] = 0;
528 rhs.m_cache_len = 0;
529 }
530 return *this;
531}
void clear()
Clear the cache (and free any old cache vectors).

◆ operator=() [2/2]

Cache & SG::AuxVectorData::Cache::operator= ( const Cache & )
private

◆ store()

void SG::AuxVectorData::Cache::store ( SG::auxid_t auxid,
void * ptr )

Store a pointer for auxid in the cache.

Parameters
auxidThe aux data item being stored.
ptrPointer to the start of the aux vector for auxid.

Definition at line 592 of file AuxVectorData.cxx.

593{
594 // We must be holding the container lock m_mutex to call this.
595
596 if (auxid >= m_cache_len) {
597 // We need to expand the cache vector. Allocate a new one.
598 size_t newlen =
599 std::max (static_cast<SG::auxid_t>(AuxVectorData::s_minCacheLen),
600 (auxid+1)*3/2);
601 void** newcache = new void*[newlen];
602 m_allcache.push_back (newcache);
603 void** oldcache = m_cache[0];
604
605 // Copy old vector to the new one and clear the remainder.
606 std::copy (oldcache, oldcache + m_cache_len, newcache);
607 std::fill (newcache + m_cache_len, newcache + newlen,
608 static_cast<void*>(0));
609
610 // The above writes must be visible before we update the cache pointers.
612
613 // Store so that other threads can see it.
614 // The stores to m_cache must happen before the store to m_cache_len;
615 // we use a fence to ensure this.
616 m_cache[0] = newcache;
617 m_cache[1] = newcache;
619 m_cache_len = newlen;
620 }
621
622 // We have room in the cache vector now. Store the pointer.
623 m_cache[0][auxid] = ptr;
624}
void fence_seq_cst()
A sequentially-consistent fence.
size_t auxid_t
Identifier for a particular aux data item.
Definition AuxTypes.h:27
void * ptr(T *p)
Definition SGImplSvc.cxx:74

◆ swap()

void SG::AuxVectorData::Cache::swap ( Cache & other)

Swap this cache object with another.

Parameters
otherThe cache object with which to swap.

Definition at line 547 of file AuxVectorData.cxx.

548{
549 m_allcache.swap (other.m_allcache);
550 std::swap (m_cache, other.m_cache);
551 std::swap (m_cache_len, other.m_cache_len);
552}
void swap(ElementLinkVector< DOBJ > &lhs, ElementLinkVector< DOBJ > &rhs)

Member Data Documentation

◆ m_allcache

std::vector<void**> SG::AuxVectorData::Cache::m_allcache

All cache vectors that have been allocated.

Definition at line 860 of file AuxVectorData.h.

◆ m_cache

void** SG::AuxVectorData::Cache::m_cache[2]

Pointer to the cache vector.

The two pointers here are the same; see the thread-safety discussion in the file header above.

Definition at line 851 of file AuxVectorData.h.

◆ m_cache_len

size_t SG::AuxVectorData::Cache::m_cache_len

Length of the cache vector.

Definition at line 854 of file AuxVectorData.h.


The documentation for this class was generated from the following files: