Import Geant4 10.7.0.beta source tree
This commit is contained in:
@@ -42,9 +42,6 @@
|
||||
//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
|
||||
//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
|
||||
|
||||
|
||||
|
||||
|
||||
#ifndef G4TAtomicHitsCollection_h
|
||||
#define G4TAtomicHitsCollection_h 1
|
||||
|
||||
@@ -80,50 +77,43 @@
|
||||
void* theCollection;
|
||||
};*/
|
||||
|
||||
|
||||
template <class T>
|
||||
class G4TAtomicHitsCollection : public G4VHitsCollection
|
||||
{
|
||||
protected:
|
||||
protected:
|
||||
static_assert(std::is_fundamental<T>::value,
|
||||
"G4TAtomicHitsCollection must use fundamental type");
|
||||
|
||||
public:
|
||||
typedef T base_type;
|
||||
typedef G4atomic<T> value_type;
|
||||
typedef typename std::deque<value_type*> container_type;
|
||||
public:
|
||||
typedef T base_type;
|
||||
typedef G4atomic<T> value_type;
|
||||
typedef typename std::deque<value_type*> container_type;
|
||||
|
||||
public:
|
||||
public:
|
||||
G4TAtomicHitsCollection();
|
||||
|
||||
public:
|
||||
public:
|
||||
// with description
|
||||
G4TAtomicHitsCollection(G4String detName, G4String colNam);
|
||||
|
||||
// constructor.
|
||||
public:
|
||||
public:
|
||||
virtual ~G4TAtomicHitsCollection();
|
||||
G4bool operator==(const G4TAtomicHitsCollection<T> &right) const;
|
||||
G4bool operator==(const G4TAtomicHitsCollection<T>& right) const;
|
||||
|
||||
//inline void *operator new(size_t);
|
||||
//inline void operator delete(void* anHC);
|
||||
// inline void *operator new(size_t);
|
||||
// inline void operator delete(void* anHC);
|
||||
|
||||
public: // with description
|
||||
public: // with description
|
||||
virtual void DrawAllHits();
|
||||
virtual void PrintAllHits();
|
||||
// These two methods invokes Draw() and Print() methods of all of
|
||||
// hit objects stored in this collection, respectively.
|
||||
|
||||
public: // with description
|
||||
inline value_type* operator[](size_t i) const
|
||||
{
|
||||
return (*theCollection)[i];
|
||||
}
|
||||
public: // with description
|
||||
inline value_type* operator[](size_t i) const { return (*theCollection)[i]; }
|
||||
// Returns a pointer to a concrete hit object.
|
||||
inline container_type* GetVector() const
|
||||
{
|
||||
return theCollection;
|
||||
}
|
||||
inline container_type* GetVector() const { return theCollection; }
|
||||
// Returns a collection vector.
|
||||
inline G4int insert(T* aHit)
|
||||
{
|
||||
@@ -140,49 +130,46 @@ public: // with description
|
||||
}
|
||||
// Returns the number of hit objects stored in this collection
|
||||
|
||||
public:
|
||||
virtual G4VHit* GetHit(size_t i) const
|
||||
{
|
||||
return (*theCollection)[i];
|
||||
}
|
||||
public:
|
||||
virtual G4VHit* GetHit(size_t i) const { return (*theCollection)[i]; }
|
||||
virtual size_t GetSize() const
|
||||
{
|
||||
G4AutoLock l(&fMutex);
|
||||
return theCollection->size();
|
||||
}
|
||||
|
||||
protected:
|
||||
protected:
|
||||
container_type* theCollection;
|
||||
G4Mutex fMutex;
|
||||
|
||||
G4Mutex fMutex;
|
||||
};
|
||||
|
||||
//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
|
||||
template <class T>
|
||||
G4TAtomicHitsCollection<T>::G4TAtomicHitsCollection()
|
||||
: theCollection(new container_type)
|
||||
{ }
|
||||
{}
|
||||
//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
|
||||
template <class T>
|
||||
G4TAtomicHitsCollection<T>::G4TAtomicHitsCollection(G4String detName,
|
||||
G4String colNam)
|
||||
: G4VHitsCollection(detName,colNam),
|
||||
theCollection(new container_type)
|
||||
{ }
|
||||
: G4VHitsCollection(detName, colNam)
|
||||
, theCollection(new container_type)
|
||||
{}
|
||||
//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
|
||||
template <class T> G4TAtomicHitsCollection<T>::~G4TAtomicHitsCollection()
|
||||
template <class T>
|
||||
G4TAtomicHitsCollection<T>::~G4TAtomicHitsCollection()
|
||||
{
|
||||
for(size_t i = 0; i < theCollection->size(); i++)
|
||||
delete (*theCollection)[i];
|
||||
delete(*theCollection)[i];
|
||||
theCollection->clear();
|
||||
delete theCollection;
|
||||
}
|
||||
//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
|
||||
template <class T>
|
||||
G4bool G4TAtomicHitsCollection<T>
|
||||
::operator==(const G4TAtomicHitsCollection<T> &right) const
|
||||
G4bool G4TAtomicHitsCollection<T>::operator==(
|
||||
const G4TAtomicHitsCollection<T>& right) const
|
||||
{
|
||||
return (collectionName == right.collectionName);
|
||||
return (collectionName == right.collectionName);
|
||||
}
|
||||
//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
|
||||
template <class T>
|
||||
|
||||
@@ -42,9 +42,6 @@
|
||||
//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
|
||||
//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
|
||||
|
||||
|
||||
|
||||
|
||||
#ifndef G4TAtomicHitsMap_h
|
||||
#define G4TAtomicHitsMap_h 1
|
||||
|
||||
@@ -71,68 +68,61 @@
|
||||
template <typename T>
|
||||
class G4TAtomicHitsMap : public G4VHitsCollection
|
||||
{
|
||||
protected:
|
||||
protected:
|
||||
static_assert(std::is_fundamental<T>::value,
|
||||
"G4TAtomicHitsMap must use fundamental type");
|
||||
|
||||
public:
|
||||
typedef G4atomic<T> value_type;
|
||||
typedef value_type* mapped_type;
|
||||
typedef typename std::map<G4int, mapped_type> container_type;
|
||||
typedef typename container_type::iterator iterator;
|
||||
public:
|
||||
typedef G4atomic<T> value_type;
|
||||
typedef value_type* mapped_type;
|
||||
typedef typename std::map<G4int, mapped_type> container_type;
|
||||
typedef typename container_type::iterator iterator;
|
||||
typedef typename container_type::const_iterator const_iterator;
|
||||
|
||||
public:
|
||||
public:
|
||||
G4TAtomicHitsMap();
|
||||
|
||||
public: // with description
|
||||
public: // with description
|
||||
G4TAtomicHitsMap(G4String detName, G4String colNam);
|
||||
// constructor.
|
||||
|
||||
public:
|
||||
public:
|
||||
virtual ~G4TAtomicHitsMap();
|
||||
G4bool operator==(const G4TAtomicHitsMap<T> &right) const;
|
||||
G4TAtomicHitsMap<T> & operator+=(const G4TAtomicHitsMap<T> &right) const;
|
||||
G4TAtomicHitsMap<T> & operator+=(const G4THitsMap<T> &right) const;
|
||||
G4bool operator==(const G4TAtomicHitsMap<T>& right) const;
|
||||
G4TAtomicHitsMap<T>& operator+=(const G4TAtomicHitsMap<T>& right) const;
|
||||
G4TAtomicHitsMap<T>& operator+=(const G4THitsMap<T>& right) const;
|
||||
|
||||
public: // with description
|
||||
public: // with description
|
||||
virtual void DrawAllHits();
|
||||
virtual void PrintAllHits();
|
||||
// These two methods invokes Draw() and Print() methods of all of
|
||||
// hit objects stored in this map, respectively.
|
||||
|
||||
public: // with description
|
||||
public: // with description
|
||||
inline value_type* operator[](G4int key) const;
|
||||
|
||||
// Returns a pointer to a concrete hit object.
|
||||
inline container_type* GetMap() const
|
||||
{ return theCollection; }
|
||||
inline container_type* GetMap() const { return theCollection; }
|
||||
// Returns a collection map.
|
||||
inline G4int add(const G4int & key, value_type*& aHit) const;
|
||||
inline G4int add(const G4int & key, T& aHit) const;
|
||||
inline G4int add(const G4int& key, value_type*& aHit) const;
|
||||
inline G4int add(const G4int& key, T& aHit) const;
|
||||
// Insert a hit object. Total number of hit objects stored in this
|
||||
// map is returned.
|
||||
inline G4int set(const G4int & key, value_type*& aHit) const;
|
||||
inline G4int set(const G4int & key, T& aHit) const;
|
||||
inline G4int set(const G4int& key, value_type*& aHit) const;
|
||||
inline G4int set(const G4int& key, T& aHit) const;
|
||||
// Overwrite a hit object. Total number of hit objects stored in this
|
||||
// map is returned.
|
||||
inline G4int entries() const
|
||||
{
|
||||
return theCollection->size();
|
||||
}
|
||||
inline G4int entries() const { return theCollection->size(); }
|
||||
// Returns the number of hit objects stored in this map
|
||||
inline void clear();
|
||||
|
||||
public:
|
||||
virtual G4VHit* GetHit(size_t) const {return 0;}
|
||||
virtual size_t GetSize() const
|
||||
{
|
||||
return theCollection->size();
|
||||
}
|
||||
public:
|
||||
virtual G4VHit* GetHit(size_t) const { return 0; }
|
||||
virtual size_t GetSize() const { return theCollection->size(); }
|
||||
|
||||
virtual size_t size() const { return theCollection->size(); }
|
||||
|
||||
public:
|
||||
public:
|
||||
iterator begin() { return theCollection->begin(); }
|
||||
iterator end() { return theCollection->end(); }
|
||||
|
||||
@@ -145,63 +135,62 @@ public:
|
||||
iterator find(G4int p) { return theCollection->find(p); }
|
||||
const_iterator find(G4int p) const { return theCollection->find(p); }
|
||||
|
||||
private:
|
||||
container_type* theCollection;
|
||||
mutable G4Mutex fMutex;
|
||||
|
||||
private:
|
||||
container_type* theCollection;
|
||||
mutable G4Mutex fMutex;
|
||||
};
|
||||
|
||||
//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
|
||||
template <typename T>
|
||||
G4TAtomicHitsMap<T>::G4TAtomicHitsMap()
|
||||
: theCollection(new container_type)
|
||||
{ }
|
||||
{}
|
||||
//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
|
||||
template <typename T>
|
||||
G4TAtomicHitsMap<T>::G4TAtomicHitsMap(G4String detName,
|
||||
G4String colNam)
|
||||
: G4VHitsCollection(detName,colNam),
|
||||
theCollection(new container_type)
|
||||
{ }
|
||||
G4TAtomicHitsMap<T>::G4TAtomicHitsMap(G4String detName, G4String colNam)
|
||||
: G4VHitsCollection(detName, colNam)
|
||||
, theCollection(new container_type)
|
||||
{}
|
||||
//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
|
||||
template <typename T>
|
||||
G4TAtomicHitsMap<T>::~G4TAtomicHitsMap()
|
||||
{
|
||||
for(auto itr = theCollection->begin(); itr != theCollection->end(); itr++)
|
||||
delete itr->second;
|
||||
delete itr->second;
|
||||
|
||||
delete theCollection;
|
||||
}
|
||||
//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
|
||||
template <typename T>
|
||||
G4bool G4TAtomicHitsMap<T>::operator==(const G4TAtomicHitsMap<T> &right) const
|
||||
G4bool G4TAtomicHitsMap<T>::operator==(const G4TAtomicHitsMap<T>& right) const
|
||||
{
|
||||
return (collectionName == right.collectionName);
|
||||
}
|
||||
//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
|
||||
template <typename T>
|
||||
G4TAtomicHitsMap<T>&
|
||||
G4TAtomicHitsMap<T>::operator+=(const G4TAtomicHitsMap<T>& rhs) const
|
||||
G4TAtomicHitsMap<T>& G4TAtomicHitsMap<T>::operator+=(
|
||||
const G4TAtomicHitsMap<T>& rhs) const
|
||||
{
|
||||
for(auto itr = rhs.GetMap()->begin(); itr != rhs.GetMap()->end(); itr++)
|
||||
add(itr->first, *(itr->second));
|
||||
|
||||
return (G4TAtomicHitsMap<T>&)(*this);
|
||||
return (G4TAtomicHitsMap<T>&) (*this);
|
||||
}
|
||||
//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
|
||||
template <typename T>
|
||||
G4TAtomicHitsMap<T>&
|
||||
G4TAtomicHitsMap<T>::operator+=(const G4THitsMap<T>& rhs) const
|
||||
G4TAtomicHitsMap<T>& G4TAtomicHitsMap<T>::operator+=(
|
||||
const G4THitsMap<T>& rhs) const
|
||||
{
|
||||
for(auto itr = rhs.GetMap()->begin(); itr != rhs.GetMap()->end(); itr++)
|
||||
add(itr->first, *(itr->second));
|
||||
|
||||
return (G4TAtomicHitsMap<T>&)(*this);
|
||||
return (G4TAtomicHitsMap<T>&) (*this);
|
||||
}
|
||||
//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
|
||||
template <typename T>
|
||||
inline typename G4TAtomicHitsMap<T>::value_type*
|
||||
G4TAtomicHitsMap<T>::operator[](G4int key) const
|
||||
inline
|
||||
typename G4TAtomicHitsMap<T>::value_type* G4TAtomicHitsMap<T>::operator[](
|
||||
G4int key) const
|
||||
{
|
||||
if(theCollection->find(key) != theCollection->end())
|
||||
return theCollection->find(key)->second;
|
||||
@@ -210,17 +199,17 @@ G4TAtomicHitsMap<T>::operator[](G4int key) const
|
||||
G4AutoLock l(&fMutex);
|
||||
if(theCollection->find(key) == theCollection->end())
|
||||
{
|
||||
value_type* ptr = new value_type;
|
||||
value_type* ptr = new value_type;
|
||||
(*theCollection)[key] = ptr;
|
||||
return ptr;
|
||||
} else
|
||||
}
|
||||
else
|
||||
return theCollection->find(key)->second;
|
||||
}
|
||||
}
|
||||
//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
|
||||
template <typename T>
|
||||
inline G4int
|
||||
G4TAtomicHitsMap<T>::add(const G4int& key, value_type*& aHit) const
|
||||
inline G4int G4TAtomicHitsMap<T>::add(const G4int& key, value_type*& aHit) const
|
||||
{
|
||||
if(theCollection->find(key) != theCollection->end())
|
||||
*(*theCollection)[key] += *aHit;
|
||||
@@ -234,16 +223,14 @@ G4TAtomicHitsMap<T>::add(const G4int& key, value_type*& aHit) const
|
||||
}
|
||||
//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
|
||||
template <typename T>
|
||||
inline G4int
|
||||
G4TAtomicHitsMap<T>::add(const G4int& key, T& aHit) const
|
||||
inline G4int G4TAtomicHitsMap<T>::add(const G4int& key, T& aHit) const
|
||||
{
|
||||
|
||||
if(theCollection->find(key) != theCollection->end())
|
||||
*(*theCollection)[key] += aHit;
|
||||
else
|
||||
{
|
||||
value_type* hit = new value_type;
|
||||
*hit = aHit;
|
||||
*hit = aHit;
|
||||
G4AutoLock l(&fMutex);
|
||||
(*theCollection)[key] = hit;
|
||||
}
|
||||
@@ -252,11 +239,10 @@ G4TAtomicHitsMap<T>::add(const G4int& key, T& aHit) const
|
||||
}
|
||||
//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
|
||||
template <typename T>
|
||||
inline G4int
|
||||
G4TAtomicHitsMap<T>::set(const G4int& key, value_type*& aHit) const
|
||||
inline G4int G4TAtomicHitsMap<T>::set(const G4int& key, value_type*& aHit) const
|
||||
{
|
||||
if(theCollection->find(key) != theCollection->end())
|
||||
delete (*theCollection)[key]->second;
|
||||
delete(*theCollection)[key]->second;
|
||||
|
||||
(*theCollection)[key] = aHit;
|
||||
G4AutoLock l(&fMutex);
|
||||
@@ -264,24 +250,23 @@ G4TAtomicHitsMap<T>::set(const G4int& key, value_type*& aHit) const
|
||||
}
|
||||
//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
|
||||
template <typename T>
|
||||
inline G4int
|
||||
G4TAtomicHitsMap<T>::set(const G4int& key, T& aHit) const
|
||||
inline G4int G4TAtomicHitsMap<T>::set(const G4int& key, T& aHit) const
|
||||
{
|
||||
if(theCollection->find(key) != theCollection->end())
|
||||
*(*theCollection)[key] = aHit;
|
||||
else
|
||||
{
|
||||
value_type* hit = new value_type;
|
||||
*hit = aHit;
|
||||
(*theCollection)[key] = hit;
|
||||
}
|
||||
G4AutoLock l(&fMutex);
|
||||
return theCollection->size();
|
||||
if(theCollection->find(key) != theCollection->end())
|
||||
*(*theCollection)[key] = aHit;
|
||||
else
|
||||
{
|
||||
value_type* hit = new value_type;
|
||||
*hit = aHit;
|
||||
(*theCollection)[key] = hit;
|
||||
}
|
||||
G4AutoLock l(&fMutex);
|
||||
return theCollection->size();
|
||||
}
|
||||
//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
|
||||
template <typename T>
|
||||
void G4TAtomicHitsMap<T>::DrawAllHits()
|
||||
{ }
|
||||
{}
|
||||
//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
|
||||
template <typename T>
|
||||
void G4TAtomicHitsMap<T>::PrintAllHits()
|
||||
@@ -299,7 +284,6 @@ void G4TAtomicHitsMap<T>::clear()
|
||||
delete itr->second;
|
||||
|
||||
theCollection->clear();
|
||||
|
||||
}
|
||||
//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
|
||||
|
||||
|
||||
@@ -64,7 +64,6 @@
|
||||
//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
|
||||
//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
|
||||
|
||||
|
||||
#ifndef G4atomic_hh_
|
||||
#define G4atomic_hh_
|
||||
|
||||
@@ -72,199 +71,301 @@
|
||||
|
||||
#ifdef G4MULTITHREADED
|
||||
|
||||
#include "G4atomic_defines.hh"
|
||||
# include "G4atomic_defines.hh"
|
||||
|
||||
//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
|
||||
|
||||
template<typename _Tp>
|
||||
template <typename _Tp>
|
||||
class G4atomic
|
||||
{
|
||||
public:
|
||||
public:
|
||||
typedef typename std::atomic<_Tp> base_type;
|
||||
typedef _Tp value_type;
|
||||
|
||||
typedef typename std::atomic<_Tp> base_type;
|
||||
typedef _Tp value_type;
|
||||
private:
|
||||
using mem_ord = std::memory_order;
|
||||
|
||||
private:
|
||||
public:
|
||||
// constructors
|
||||
explicit G4atomic(mem_ord mo = std::memory_order_acq_rel)
|
||||
: fMemOrder(mo)
|
||||
{
|
||||
atomics::set(&fvalue, value_type());
|
||||
}
|
||||
|
||||
using mem_ord = std::memory_order;
|
||||
explicit G4atomic(const value_type& _init,
|
||||
mem_ord mo = std::memory_order_acq_rel)
|
||||
: fMemOrder(mo)
|
||||
{
|
||||
atomics::set(&fvalue, _init);
|
||||
}
|
||||
|
||||
public:
|
||||
// copy-constructor from pure C++11 atomic
|
||||
explicit G4atomic(const base_type& rhs,
|
||||
mem_ord mo = std::memory_order_acq_rel)
|
||||
: fMemOrder(mo)
|
||||
{
|
||||
atomics::set(&fvalue, rhs);
|
||||
}
|
||||
|
||||
// constructors
|
||||
explicit
|
||||
G4atomic(mem_ord mo = std::memory_order_acq_rel) : fMemOrder(mo)
|
||||
{ atomics::set(&fvalue, value_type()); }
|
||||
// copy-constructor
|
||||
explicit G4atomic(const G4atomic& rhs)
|
||||
: fMemOrder(rhs.fMemOrder)
|
||||
{
|
||||
atomics::set(&fvalue, rhs.base());
|
||||
}
|
||||
|
||||
explicit
|
||||
G4atomic(const value_type& _init,
|
||||
mem_ord mo = std::memory_order_acq_rel) : fMemOrder(mo)
|
||||
{ atomics::set(&fvalue, _init); }
|
||||
// assignment operators
|
||||
G4atomic& operator=(const G4atomic& rhs)
|
||||
{
|
||||
if(this != &rhs)
|
||||
atomics::set(&fvalue, rhs.fvalue);
|
||||
return *this;
|
||||
}
|
||||
|
||||
// copy-constructor from pure C++11 atomic
|
||||
explicit
|
||||
G4atomic(const base_type& rhs,
|
||||
mem_ord mo = std::memory_order_acq_rel) : fMemOrder(mo)
|
||||
{ atomics::set(&fvalue, rhs); }
|
||||
G4atomic& operator=(const value_type& rhs)
|
||||
{
|
||||
atomics::set(&fvalue, rhs);
|
||||
return *this;
|
||||
}
|
||||
|
||||
// copy-constructor
|
||||
explicit
|
||||
G4atomic(const G4atomic& rhs) : fMemOrder(rhs.fMemOrder)
|
||||
{ atomics::set(&fvalue, rhs.base()); }
|
||||
G4atomic& operator=(const base_type& rhs)
|
||||
{
|
||||
atomics::set(&fvalue, rhs);
|
||||
return *this;
|
||||
}
|
||||
|
||||
// assignment operators
|
||||
G4atomic& operator=(const G4atomic& rhs)
|
||||
{
|
||||
if(this != &rhs)
|
||||
atomics::set(&fvalue, rhs.fvalue);
|
||||
return *this;
|
||||
}
|
||||
// destructor
|
||||
~G4atomic() { fvalue.~base_type(); }
|
||||
|
||||
G4atomic& operator=(const value_type& rhs)
|
||||
{
|
||||
atomics::set(&fvalue, rhs);
|
||||
return *this;
|
||||
}
|
||||
// base version
|
||||
base_type& base() { return fvalue; }
|
||||
const base_type& base() const { return fvalue; }
|
||||
base_type& base() volatile { return fvalue; }
|
||||
const base_type& base() const volatile { return fvalue; }
|
||||
|
||||
G4atomic& operator=(const base_type& rhs)
|
||||
{
|
||||
atomics::set(&fvalue, rhs);
|
||||
return *this;
|
||||
}
|
||||
// check if atomic is lock-free
|
||||
bool is_lock_free() const { return fvalue.is_lock_free(); }
|
||||
bool is_lock_free() const volatile { return fvalue.is_lock_free(); }
|
||||
|
||||
// destructor
|
||||
~G4atomic() { fvalue.~base_type(); }
|
||||
// store functions
|
||||
void store(_Tp _desired, mem_ord mo = std::memory_order_seq_cst)
|
||||
{
|
||||
atomics::set(fvalue, _desired, mo);
|
||||
}
|
||||
void store(_Tp _desired, mem_ord mo = std::memory_order_seq_cst) volatile
|
||||
{
|
||||
atomics::set(fvalue, _desired, mo);
|
||||
}
|
||||
|
||||
// base version
|
||||
base_type& base() { return fvalue; }
|
||||
const base_type& base() const { return fvalue; }
|
||||
base_type& base() volatile { return fvalue; }
|
||||
const base_type& base() const volatile { return fvalue; }
|
||||
// load functions
|
||||
_Tp load(mem_ord mo = std::memory_order_seq_cst) const
|
||||
{
|
||||
return atomics::get(fvalue, mo);
|
||||
}
|
||||
_Tp load(mem_ord mo = std::memory_order_seq_cst) const volatile
|
||||
{
|
||||
return atomics::get(fvalue, mo);
|
||||
}
|
||||
|
||||
// check if atomic is lock-free
|
||||
bool is_lock_free() const { return fvalue.is_lock_free(); }
|
||||
bool is_lock_free() const volatile { return fvalue.is_lock_free(); }
|
||||
// implicit conversion functions
|
||||
operator _Tp() const { return this->load(); }
|
||||
operator _Tp() const volatile { return this->load(); }
|
||||
|
||||
// store functions
|
||||
void store(_Tp _desired, mem_ord mo = std::memory_order_seq_cst)
|
||||
{ atomics::set(fvalue, _desired, mo); }
|
||||
void store(_Tp _desired, mem_ord mo = std::memory_order_seq_cst) volatile
|
||||
{ atomics::set(fvalue, _desired, mo); }
|
||||
operator base_type&() const { return fvalue; }
|
||||
|
||||
// load functions
|
||||
_Tp load(mem_ord mo = std::memory_order_seq_cst) const
|
||||
{ return atomics::get(fvalue, mo); }
|
||||
_Tp load(mem_ord mo = std::memory_order_seq_cst) const volatile
|
||||
{ return atomics::get(fvalue, mo); }
|
||||
// compare-and-swap functions
|
||||
bool compare_exchange_weak(_Tp& _expected, _Tp _desired, mem_ord _success,
|
||||
mem_ord _failure)
|
||||
{
|
||||
return fvalue.compare_exchange_weak(_expected, _desired, _success,
|
||||
_failure);
|
||||
}
|
||||
bool compare_exchange_weak(_Tp& _expected, _Tp _desired, mem_ord _success,
|
||||
mem_ord _failure) volatile
|
||||
{
|
||||
return fvalue.compare_exchange_weak(_expected, _desired, _success,
|
||||
_failure);
|
||||
}
|
||||
|
||||
// implicit conversion functions
|
||||
operator _Tp() const { return this->load(); }
|
||||
operator _Tp() const volatile { return this->load(); }
|
||||
bool compare_exchange_weak(_Tp& _expected, _Tp _desired, mem_ord _order)
|
||||
{
|
||||
return fvalue.compare_exchange_weak(_expected, _desired, _order);
|
||||
}
|
||||
bool compare_exchange_weak(_Tp& _expected, _Tp _desired,
|
||||
mem_ord _order) volatile
|
||||
{
|
||||
return fvalue.compare_exchange_weak(_expected, _desired, _order);
|
||||
}
|
||||
|
||||
operator base_type&() const { return fvalue; }
|
||||
bool compare_exchange_strong(_Tp& _expected, _Tp _desired, mem_ord _success,
|
||||
mem_ord _failure)
|
||||
{
|
||||
return fvalue.compare_exchange_weak(_expected, _desired, _success,
|
||||
_failure);
|
||||
}
|
||||
bool compare_exchange_strong(_Tp& _expected, _Tp _desired, mem_ord _success,
|
||||
mem_ord _failure) volatile
|
||||
{
|
||||
return fvalue.compare_exchange_weak(_expected, _desired, _success,
|
||||
_failure);
|
||||
}
|
||||
|
||||
// compare-and-swap functions
|
||||
bool compare_exchange_weak(_Tp& _expected, _Tp _desired,
|
||||
mem_ord _success, mem_ord _failure)
|
||||
{ return fvalue.compare_exchange_weak(_expected, _desired,
|
||||
_success, _failure); }
|
||||
bool compare_exchange_weak(_Tp& _expected, _Tp _desired,
|
||||
mem_ord _success, mem_ord _failure) volatile
|
||||
{ return fvalue.compare_exchange_weak(_expected, _desired,
|
||||
_success, _failure); }
|
||||
|
||||
bool compare_exchange_weak(_Tp& _expected, _Tp _desired, mem_ord _order)
|
||||
{ return fvalue.compare_exchange_weak(_expected, _desired, _order); }
|
||||
bool compare_exchange_weak(_Tp& _expected, _Tp _desired,
|
||||
bool compare_exchange_strong(_Tp& _expected, _Tp _desired, mem_ord _order)
|
||||
{
|
||||
return fvalue.compare_exchange_weak(_expected, _desired, _order);
|
||||
}
|
||||
bool compare_exchange_strong(_Tp& _expected, _Tp _desired,
|
||||
mem_ord _order) volatile
|
||||
{ return fvalue.compare_exchange_weak(_expected, _desired, _order); }
|
||||
{
|
||||
return fvalue.compare_exchange_weak(_expected, _desired, _order);
|
||||
}
|
||||
|
||||
bool compare_exchange_strong(_Tp& _expected, _Tp _desired,
|
||||
mem_ord _success, mem_ord _failure)
|
||||
{ return fvalue.compare_exchange_weak(_expected, _desired,
|
||||
_success, _failure); }
|
||||
bool compare_exchange_strong(_Tp& _expected, _Tp _desired,
|
||||
mem_ord _success, mem_ord _failure) volatile
|
||||
{ return fvalue.compare_exchange_weak(_expected, _desired,
|
||||
_success, _failure); }
|
||||
// value_type operators
|
||||
G4atomic& operator+=(const value_type& rhs)
|
||||
{
|
||||
atomics::increment(&fvalue, rhs, fMemOrder);
|
||||
return *this;
|
||||
}
|
||||
G4atomic& operator-=(const value_type& rhs)
|
||||
{
|
||||
atomics::decrement(&fvalue, rhs, fMemOrder);
|
||||
return *this;
|
||||
}
|
||||
G4atomic& operator*=(const value_type& rhs)
|
||||
{
|
||||
atomics::multiply(&fvalue, rhs, fMemOrder);
|
||||
return *this;
|
||||
}
|
||||
G4atomic& operator/=(const value_type& rhs)
|
||||
{
|
||||
atomics::divide(&fvalue, rhs, fMemOrder);
|
||||
return *this;
|
||||
}
|
||||
|
||||
bool compare_exchange_strong(_Tp& _expected, _Tp _desired, mem_ord _order)
|
||||
{ return fvalue.compare_exchange_weak(_expected, _desired, _order); }
|
||||
bool compare_exchange_strong(_Tp& _expected, _Tp _desired,
|
||||
mem_ord _order) volatile
|
||||
{ return fvalue.compare_exchange_weak(_expected, _desired, _order); }
|
||||
// atomic operators
|
||||
G4atomic& operator+=(const G4atomic& rhs)
|
||||
{
|
||||
atomics::increment(&fvalue, rhs.fvalue);
|
||||
return *this;
|
||||
}
|
||||
G4atomic& operator-=(const G4atomic& rhs)
|
||||
{
|
||||
atomics::decrement(&fvalue, rhs.fvalue);
|
||||
return *this;
|
||||
}
|
||||
G4atomic& operator*=(const G4atomic& rhs)
|
||||
{
|
||||
atomics::multiply(&fvalue, rhs.fvalue);
|
||||
return *this;
|
||||
}
|
||||
G4atomic& operator/=(const G4atomic& rhs)
|
||||
{
|
||||
atomics::divide(&fvalue, rhs.fvalue);
|
||||
return *this;
|
||||
}
|
||||
|
||||
// value_type operators
|
||||
G4atomic& operator+=(const value_type& rhs)
|
||||
{ atomics::increment(&fvalue, rhs, fMemOrder); return *this; }
|
||||
G4atomic& operator-=(const value_type& rhs)
|
||||
{ atomics::decrement(&fvalue, rhs, fMemOrder); return *this; }
|
||||
G4atomic& operator*=(const value_type& rhs)
|
||||
{ atomics::multiply(&fvalue, rhs, fMemOrder); return *this; }
|
||||
G4atomic& operator/=(const value_type& rhs)
|
||||
{ atomics::divide(&fvalue, rhs, fMemOrder); return *this; }
|
||||
G4atomic& operator+=(const G4atomic& rhs) volatile
|
||||
{
|
||||
atomics::increment(&fvalue, rhs.fvalue);
|
||||
return *this;
|
||||
}
|
||||
G4atomic& operator-=(const G4atomic& rhs) volatile
|
||||
{
|
||||
atomics::decrement(&fvalue, rhs.fvalue);
|
||||
return *this;
|
||||
}
|
||||
G4atomic& operator*=(const G4atomic& rhs) volatile
|
||||
{
|
||||
atomics::multiply(&fvalue, rhs.fvalue);
|
||||
return *this;
|
||||
}
|
||||
G4atomic& operator/=(const G4atomic& rhs) volatile
|
||||
{
|
||||
atomics::divide(&fvalue, rhs.fvalue);
|
||||
return *this;
|
||||
}
|
||||
|
||||
// atomic operators
|
||||
G4atomic& operator+=(const G4atomic& rhs)
|
||||
{ atomics::increment(&fvalue, rhs.fvalue); return *this; }
|
||||
G4atomic& operator-=(const G4atomic& rhs)
|
||||
{ atomics::decrement(&fvalue, rhs.fvalue); return *this; }
|
||||
G4atomic& operator*=(const G4atomic& rhs)
|
||||
{ atomics::multiply(&fvalue, rhs.fvalue); return *this; }
|
||||
G4atomic& operator/=(const G4atomic& rhs)
|
||||
{ atomics::divide(&fvalue, rhs.fvalue); return *this; }
|
||||
// STL atomic operators
|
||||
G4atomic& operator+=(const std::atomic<_Tp>& rhs)
|
||||
{
|
||||
atomics::increment(&fvalue, rhs, fMemOrder);
|
||||
return *this;
|
||||
}
|
||||
G4atomic& operator-=(const std::atomic<_Tp>& rhs)
|
||||
{
|
||||
atomics::decrement(&fvalue, rhs, fMemOrder);
|
||||
return *this;
|
||||
}
|
||||
G4atomic& operator*=(const std::atomic<_Tp>& rhs)
|
||||
{
|
||||
atomics::multiply(&fvalue, rhs, fMemOrder);
|
||||
return *this;
|
||||
}
|
||||
G4atomic& operator/=(const std::atomic<_Tp>& rhs)
|
||||
{
|
||||
atomics::divide(&fvalue, rhs, fMemOrder);
|
||||
return *this;
|
||||
}
|
||||
|
||||
G4atomic& operator+=(const G4atomic& rhs) volatile
|
||||
{ atomics::increment(&fvalue, rhs.fvalue); return *this; }
|
||||
G4atomic& operator-=(const G4atomic& rhs) volatile
|
||||
{ atomics::decrement(&fvalue, rhs.fvalue); return *this; }
|
||||
G4atomic& operator*=(const G4atomic& rhs) volatile
|
||||
{ atomics::multiply(&fvalue, rhs.fvalue); return *this; }
|
||||
G4atomic& operator/=(const G4atomic& rhs) volatile
|
||||
{ atomics::divide(&fvalue, rhs.fvalue); return *this; }
|
||||
G4atomic& operator+=(const std::atomic<_Tp>& rhs) volatile
|
||||
{
|
||||
atomics::increment(&fvalue, rhs, fMemOrder);
|
||||
return *this;
|
||||
}
|
||||
G4atomic& operator-=(const std::atomic<_Tp>& rhs) volatile
|
||||
{
|
||||
atomics::decrement(&fvalue, rhs, fMemOrder);
|
||||
return *this;
|
||||
}
|
||||
G4atomic& operator*=(const std::atomic<_Tp>& rhs) volatile
|
||||
{
|
||||
atomics::multiply(&fvalue, rhs, fMemOrder);
|
||||
return *this;
|
||||
}
|
||||
G4atomic& operator/=(const std::atomic<_Tp>& rhs) volatile
|
||||
{
|
||||
atomics::divide(&fvalue, rhs, fMemOrder);
|
||||
return *this;
|
||||
}
|
||||
|
||||
// STL atomic operators
|
||||
G4atomic& operator+=(const std::atomic<_Tp>& rhs)
|
||||
{ atomics::increment(&fvalue, rhs, fMemOrder); return *this; }
|
||||
G4atomic& operator-=(const std::atomic<_Tp>& rhs)
|
||||
{ atomics::decrement(&fvalue, rhs, fMemOrder); return *this; }
|
||||
G4atomic& operator*=(const std::atomic<_Tp>& rhs)
|
||||
{ atomics::multiply(&fvalue, rhs, fMemOrder); return *this; }
|
||||
G4atomic& operator/=(const std::atomic<_Tp>& rhs)
|
||||
{ atomics::divide(&fvalue, rhs, fMemOrder); return *this; }
|
||||
// increment operators
|
||||
value_type operator++()
|
||||
{
|
||||
value_type _tmp = ++fvalue;
|
||||
return _tmp;
|
||||
}
|
||||
value_type operator++(int)
|
||||
{
|
||||
value_type _tmp = fvalue++;
|
||||
return _tmp;
|
||||
}
|
||||
|
||||
G4atomic& operator+=(const std::atomic<_Tp>& rhs) volatile
|
||||
{ atomics::increment(&fvalue, rhs, fMemOrder); return *this; }
|
||||
G4atomic& operator-=(const std::atomic<_Tp>& rhs) volatile
|
||||
{ atomics::decrement(&fvalue, rhs, fMemOrder); return *this; }
|
||||
G4atomic& operator*=(const std::atomic<_Tp>& rhs) volatile
|
||||
{ atomics::multiply(&fvalue, rhs, fMemOrder); return *this; }
|
||||
G4atomic& operator/=(const std::atomic<_Tp>& rhs) volatile
|
||||
{ atomics::divide(&fvalue, rhs, fMemOrder); return *this; }
|
||||
|
||||
// increment operators
|
||||
value_type operator++() { value_type _tmp = ++fvalue; return _tmp; }
|
||||
value_type operator++(int)
|
||||
{ value_type _tmp = fvalue++; return _tmp; }
|
||||
|
||||
value_type operator--() { value_type _tmp = --fvalue; return _tmp; }
|
||||
value_type operator--(int)
|
||||
{ value_type _tmp = fvalue--; return _tmp; }
|
||||
|
||||
protected:
|
||||
|
||||
base_type fvalue;
|
||||
mem_ord fMemOrder;
|
||||
value_type operator--()
|
||||
{
|
||||
value_type _tmp = --fvalue;
|
||||
return _tmp;
|
||||
}
|
||||
value_type operator--(int)
|
||||
{
|
||||
value_type _tmp = fvalue--;
|
||||
return _tmp;
|
||||
}
|
||||
|
||||
protected:
|
||||
base_type fvalue;
|
||||
mem_ord fMemOrder;
|
||||
};
|
||||
|
||||
//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
|
||||
|
||||
#else // ! G4MULTITHREADED
|
||||
#else // ! G4MULTITHREADED
|
||||
|
||||
template <typename _Tp> using G4atomic = _Tp;
|
||||
template <typename _Tp>
|
||||
using G4atomic = _Tp;
|
||||
|
||||
#endif // G4MULTITHREADED
|
||||
#endif // G4MULTITHREADED
|
||||
|
||||
//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
|
||||
|
||||
#endif // G4atomic_hh_
|
||||
#endif // G4atomic_hh_
|
||||
|
||||
@@ -37,7 +37,6 @@
|
||||
//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
|
||||
//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
|
||||
|
||||
|
||||
#ifndef G4atomic_defines_hh_
|
||||
#define G4atomic_defines_hh_
|
||||
|
||||
@@ -47,396 +46,363 @@
|
||||
|
||||
//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
|
||||
|
||||
#include <functional>
|
||||
#include <atomic>
|
||||
# include <functional>
|
||||
# include <atomic>
|
||||
|
||||
//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
|
||||
|
||||
namespace atomics
|
||||
{
|
||||
//------------------------------------------------------------------------//
|
||||
namespace details
|
||||
//------------------------------------------------------------------------//
|
||||
namespace details
|
||||
{
|
||||
//--------------------------------------------------------------------//
|
||||
template <typename _Tp>
|
||||
using OpFunction = std::function<_Tp(const _Tp&, const _Tp&)>;
|
||||
//--------------------------------------------------------------------//
|
||||
template <typename _Tp>
|
||||
inline void do_fetch_and_store(std::atomic<_Tp>* _atomic, const _Tp& _value,
|
||||
std::memory_order mem_odr)
|
||||
{
|
||||
//--------------------------------------------------------------------//
|
||||
template <typename _Tp>
|
||||
using OpFunction = std::function<_Tp(const _Tp&, const _Tp&)>;
|
||||
//--------------------------------------------------------------------//
|
||||
template <typename _Tp>
|
||||
inline void do_fetch_and_store(std::atomic<_Tp>* _atomic,
|
||||
const _Tp& _value,
|
||||
std::memory_order mem_odr)
|
||||
{
|
||||
_atomic->store(_value, mem_odr);
|
||||
}
|
||||
//--------------------------------------------------------------------//
|
||||
template <typename _Tp>
|
||||
inline void do_fetch_and_store(std::atomic<_Tp>* _atomic,
|
||||
const std::atomic<_Tp>& _value,
|
||||
std::memory_order mem_odr)
|
||||
{
|
||||
_atomic->store(_value.load(), mem_odr);
|
||||
}
|
||||
//--------------------------------------------------------------------//
|
||||
template <typename _Tp>
|
||||
inline void do_compare_and_swap(std::atomic<_Tp>* _atomic,
|
||||
const _Tp& _value,
|
||||
const OpFunction<_Tp>& _operator,
|
||||
std::memory_order mem_odr)
|
||||
{
|
||||
_Tp _expected = _Tp();
|
||||
do {
|
||||
_expected = _atomic->load();
|
||||
} while (!(_atomic->compare_exchange_weak(_expected,
|
||||
_operator(_expected,
|
||||
_value),
|
||||
mem_odr)));
|
||||
}
|
||||
//--------------------------------------------------------------------//
|
||||
template <typename _Tp>
|
||||
inline void do_compare_and_swap(std::atomic<_Tp>* _atomic,
|
||||
const std::atomic<_Tp>&
|
||||
_atomic_value,
|
||||
const OpFunction<_Tp>& _operator,
|
||||
_atomic->store(_value, mem_odr);
|
||||
}
|
||||
//--------------------------------------------------------------------//
|
||||
template <typename _Tp>
|
||||
inline void do_fetch_and_store(std::atomic<_Tp>* _atomic,
|
||||
const std::atomic<_Tp>& _value,
|
||||
std::memory_order mem_odr)
|
||||
{
|
||||
_atomic->store(_value.load(), mem_odr);
|
||||
}
|
||||
//--------------------------------------------------------------------//
|
||||
template <typename _Tp>
|
||||
inline void do_compare_and_swap(std::atomic<_Tp>* _atomic,
|
||||
const _Tp& _value,
|
||||
const OpFunction<_Tp>& _operator,
|
||||
std::memory_order mem_odr)
|
||||
{
|
||||
_Tp _expected = _Tp();
|
||||
do
|
||||
{
|
||||
_expected = _atomic->load();
|
||||
} while(!(_atomic->compare_exchange_weak(
|
||||
_expected, _operator(_expected, _value), mem_odr)));
|
||||
}
|
||||
//--------------------------------------------------------------------//
|
||||
template <typename _Tp>
|
||||
inline void do_compare_and_swap(std::atomic<_Tp>* _atomic,
|
||||
const std::atomic<_Tp>& _atomic_value,
|
||||
const OpFunction<_Tp>& _operator,
|
||||
std::memory_order mem_odr)
|
||||
{
|
||||
_Tp _expected = _Tp();
|
||||
do
|
||||
{
|
||||
_expected = _atomic->load();
|
||||
} while(!(_atomic->compare_exchange_weak(
|
||||
_expected, _operator(_expected, _atomic_value.load()), mem_odr)));
|
||||
}
|
||||
//--------------------------------------------------------------------//
|
||||
} // namespace details
|
||||
//------------------------------------------------------------------------//
|
||||
// WITH ATOMIC TEMPLATE BASE TYPE AS SECOND PARAMETER
|
||||
//------------------------------------------------------------------------//
|
||||
template <typename T>
|
||||
inline void set(std::atomic<T>* _atomic, const T& _desired,
|
||||
std::memory_order mem_odr = std::memory_order_seq_cst)
|
||||
{
|
||||
details::do_compare_and_swap(
|
||||
_atomic, _desired,
|
||||
details::OpFunction<T>([](const T&, const T& y) { return y; }), mem_odr);
|
||||
}
|
||||
//------------------------------------------------------------------------//
|
||||
template <typename T>
|
||||
inline void set(std::atomic<T>& _atomic, const T& _desired,
|
||||
std::memory_order mem_odr = std::memory_order_seq_cst)
|
||||
{
|
||||
set(&_atomic, _desired, mem_odr);
|
||||
}
|
||||
//------------------------------------------------------------------------//
|
||||
template <typename T>
|
||||
inline void increment(std::atomic<T>* _atomic, const T& _increment,
|
||||
std::memory_order mem_odr)
|
||||
{
|
||||
_Tp _expected = _Tp();
|
||||
do {
|
||||
_expected = _atomic->load();
|
||||
} while (!(_atomic->compare_exchange_weak(_expected,
|
||||
_operator(_expected,
|
||||
_atomic_value.load()),
|
||||
mem_odr)));
|
||||
}
|
||||
//--------------------------------------------------------------------//
|
||||
}
|
||||
//------------------------------------------------------------------------//
|
||||
// WITH ATOMIC TEMPLATE BASE TYPE AS SECOND PARAMETER
|
||||
//------------------------------------------------------------------------//
|
||||
template <typename T>
|
||||
inline void set(std::atomic<T>* _atomic,
|
||||
const T& _desired,
|
||||
std::memory_order mem_odr
|
||||
= std::memory_order_seq_cst)
|
||||
{
|
||||
details::do_compare_and_swap(_atomic,
|
||||
_desired,
|
||||
details::OpFunction<T>
|
||||
([](const T&, const T& y){return y;}),
|
||||
mem_odr);
|
||||
}
|
||||
//------------------------------------------------------------------------//
|
||||
template <typename T>
|
||||
inline void set(std::atomic<T>& _atomic,
|
||||
const T& _desired,
|
||||
std::memory_order mem_odr
|
||||
= std::memory_order_seq_cst)
|
||||
{
|
||||
set(&_atomic, _desired, mem_odr);
|
||||
}
|
||||
//------------------------------------------------------------------------//
|
||||
template <typename T>
|
||||
inline void increment(std::atomic<T>* _atomic,
|
||||
const T& _increment,
|
||||
std::memory_order mem_odr)
|
||||
{
|
||||
details::do_compare_and_swap(_atomic, _increment,
|
||||
details::OpFunction<T>
|
||||
([](const T& x, const T& y){return x+y;}),
|
||||
mem_odr);
|
||||
}
|
||||
//------------------------------------------------------------------------//
|
||||
template <typename T>
|
||||
inline void decrement(std::atomic<T>* _atomic, const T& _decrement,
|
||||
std::memory_order mem_odr)
|
||||
{
|
||||
details::do_compare_and_swap(_atomic, _decrement,
|
||||
details::OpFunction<T>
|
||||
([](const T& x, const T& y){return x-y;}),
|
||||
mem_odr);
|
||||
}
|
||||
//------------------------------------------------------------------------//
|
||||
template <typename T>
|
||||
inline void multiply(std::atomic<T>* _atomic, const T& _factor,
|
||||
std::memory_order mem_odr)
|
||||
{
|
||||
details::do_compare_and_swap(_atomic, _factor,
|
||||
details::OpFunction<T>
|
||||
([](const T& x, const T& y){return x*y;}),
|
||||
mem_odr);
|
||||
}
|
||||
//------------------------------------------------------------------------//
|
||||
template <typename T>
|
||||
inline void divide(std::atomic<T>* _atomic, const T& _factor,
|
||||
{
|
||||
details::do_compare_and_swap(
|
||||
_atomic, _increment,
|
||||
details::OpFunction<T>([](const T& x, const T& y) { return x + y; }),
|
||||
mem_odr);
|
||||
}
|
||||
//------------------------------------------------------------------------//
|
||||
template <typename T>
|
||||
inline void decrement(std::atomic<T>* _atomic, const T& _decrement,
|
||||
std::memory_order mem_odr)
|
||||
{
|
||||
details::do_compare_and_swap(
|
||||
_atomic, _decrement,
|
||||
details::OpFunction<T>([](const T& x, const T& y) { return x - y; }),
|
||||
mem_odr);
|
||||
}
|
||||
//------------------------------------------------------------------------//
|
||||
template <typename T>
|
||||
inline void multiply(std::atomic<T>* _atomic, const T& _factor,
|
||||
std::memory_order mem_odr)
|
||||
{
|
||||
details::do_compare_and_swap(_atomic, _factor,
|
||||
details::OpFunction<T>
|
||||
([](const T& x, const T& y){return x/y;}),
|
||||
mem_odr);
|
||||
}
|
||||
//------------------------------------------------------------------------//
|
||||
// WITH ATOMICS AS SECOND PARAMETER
|
||||
//------------------------------------------------------------------------//
|
||||
template <typename T>
|
||||
inline void set(std::atomic<T>* _atomic,
|
||||
const std::atomic<T>& _atomic_desired,
|
||||
std::memory_order mem_odr
|
||||
= std::memory_order_seq_cst)
|
||||
{
|
||||
//details::do_fetch_and_store(_atomic, _desired);
|
||||
details::do_compare_and_swap(_atomic, _atomic_desired,
|
||||
details::OpFunction<T>
|
||||
([](const T&, const T& y){return y;}),
|
||||
mem_odr);
|
||||
}
|
||||
//------------------------------------------------------------------------//
|
||||
template <typename T>
|
||||
inline void set(std::atomic<T>& _atomic,
|
||||
const std::atomic<T>& _atomic_desired,
|
||||
std::memory_order mem_odr)
|
||||
{
|
||||
set(&_atomic, _atomic_desired, mem_odr);
|
||||
}
|
||||
//------------------------------------------------------------------------//
|
||||
template <typename T>
|
||||
inline void increment(std::atomic<T>* _atomic,
|
||||
const std::atomic<T>& _atomic_increment,
|
||||
std::memory_order mem_odr)
|
||||
{
|
||||
details::do_compare_and_swap(_atomic, _atomic_increment,
|
||||
details::OpFunction<T>
|
||||
([](const T& x, const T& y){return x+y;}),
|
||||
mem_odr);
|
||||
}
|
||||
//------------------------------------------------------------------------//
|
||||
template <typename T>
|
||||
inline void decrement(std::atomic<T>* _atomic,
|
||||
const std::atomic<T>& _atomic_decrement,
|
||||
std::memory_order mem_odr)
|
||||
{
|
||||
details::do_compare_and_swap(_atomic, _atomic_decrement,
|
||||
details::OpFunction<T>
|
||||
([](const T& x, const T& y){return x-y;}),
|
||||
mem_odr);
|
||||
}
|
||||
//------------------------------------------------------------------------//
|
||||
template <typename T>
|
||||
inline void multiply(std::atomic<T>* _atomic,
|
||||
const std::atomic<T>& _atomic_factor,
|
||||
std::memory_order mem_odr)
|
||||
{
|
||||
details::do_compare_and_swap(_atomic, _atomic_factor,
|
||||
details::OpFunction<T>
|
||||
([](const T& x, const T& y){return x*y;}),
|
||||
mem_odr);
|
||||
}
|
||||
//------------------------------------------------------------------------//
|
||||
template <typename T>
|
||||
inline void divide(std::atomic<T>* _atomic,
|
||||
{
|
||||
details::do_compare_and_swap(
|
||||
_atomic, _factor,
|
||||
details::OpFunction<T>([](const T& x, const T& y) { return x * y; }),
|
||||
mem_odr);
|
||||
}
|
||||
//------------------------------------------------------------------------//
|
||||
template <typename T>
|
||||
inline void divide(std::atomic<T>* _atomic, const T& _factor,
|
||||
std::memory_order mem_odr)
|
||||
{
|
||||
details::do_compare_and_swap(
|
||||
_atomic, _factor,
|
||||
details::OpFunction<T>([](const T& x, const T& y) { return x / y; }),
|
||||
mem_odr);
|
||||
}
|
||||
//------------------------------------------------------------------------//
|
||||
// WITH ATOMICS AS SECOND PARAMETER
|
||||
//------------------------------------------------------------------------//
|
||||
template <typename T>
|
||||
inline void set(std::atomic<T>* _atomic,
|
||||
const std::atomic<T>& _atomic_desired,
|
||||
std::memory_order mem_odr = std::memory_order_seq_cst)
|
||||
{
|
||||
// details::do_fetch_and_store(_atomic, _desired);
|
||||
details::do_compare_and_swap(
|
||||
_atomic, _atomic_desired,
|
||||
details::OpFunction<T>([](const T&, const T& y) { return y; }), mem_odr);
|
||||
}
|
||||
//------------------------------------------------------------------------//
|
||||
template <typename T>
|
||||
inline void set(std::atomic<T>& _atomic,
|
||||
const std::atomic<T>& _atomic_desired,
|
||||
std::memory_order mem_odr)
|
||||
{
|
||||
set(&_atomic, _atomic_desired, mem_odr);
|
||||
}
|
||||
//------------------------------------------------------------------------//
|
||||
template <typename T>
|
||||
inline void increment(std::atomic<T>* _atomic,
|
||||
const std::atomic<T>& _atomic_increment,
|
||||
std::memory_order mem_odr)
|
||||
{
|
||||
details::do_compare_and_swap(
|
||||
_atomic, _atomic_increment,
|
||||
details::OpFunction<T>([](const T& x, const T& y) { return x + y; }),
|
||||
mem_odr);
|
||||
}
|
||||
//------------------------------------------------------------------------//
|
||||
template <typename T>
|
||||
inline void decrement(std::atomic<T>* _atomic,
|
||||
const std::atomic<T>& _atomic_decrement,
|
||||
std::memory_order mem_odr)
|
||||
{
|
||||
details::do_compare_and_swap(
|
||||
_atomic, _atomic_decrement,
|
||||
details::OpFunction<T>([](const T& x, const T& y) { return x - y; }),
|
||||
mem_odr);
|
||||
}
|
||||
//------------------------------------------------------------------------//
|
||||
template <typename T>
|
||||
inline void multiply(std::atomic<T>* _atomic,
|
||||
const std::atomic<T>& _atomic_factor,
|
||||
std::memory_order mem_odr)
|
||||
{
|
||||
details::do_compare_and_swap(_atomic, _atomic_factor,
|
||||
details::OpFunction<T>
|
||||
([](const T& x, const T& y){return x/y;}),
|
||||
mem_odr);
|
||||
}
|
||||
{
|
||||
details::do_compare_and_swap(
|
||||
_atomic, _atomic_factor,
|
||||
details::OpFunction<T>([](const T& x, const T& y) { return x * y; }),
|
||||
mem_odr);
|
||||
}
|
||||
//------------------------------------------------------------------------//
|
||||
template <typename T>
|
||||
inline void divide(std::atomic<T>* _atomic,
|
||||
const std::atomic<T>& _atomic_factor,
|
||||
std::memory_order mem_odr)
|
||||
{
|
||||
details::do_compare_and_swap(
|
||||
_atomic, _atomic_factor,
|
||||
details::OpFunction<T>([](const T& x, const T& y) { return x / y; }),
|
||||
mem_odr);
|
||||
}
|
||||
|
||||
//------------------------------------------------------------------------//
|
||||
// STANDARD OVERLOAD //
|
||||
//------------------------------------------------------------------------//
|
||||
template <typename T>
|
||||
inline void set(T* _non_atomic, const T& _desired)
|
||||
{
|
||||
*_non_atomic = _desired;
|
||||
}
|
||||
//------------------------------------------------------------------------//
|
||||
template <typename T>
|
||||
inline void set(T& _non_atomic, const T& _desired)
|
||||
{
|
||||
set(&_non_atomic, _desired);
|
||||
}
|
||||
//------------------------------------------------------------------------//
|
||||
// STL PAIR OVERLOAD //
|
||||
//------------------------------------------------------------------------//
|
||||
//
|
||||
//------------------------------------------------------------------------//
|
||||
// WITH ATOMIC TEMPLATE TYPE AS SECOND PARAMETER
|
||||
//------------------------------------------------------------------------//
|
||||
template <typename T, typename U>
|
||||
inline void set(std::pair<std::atomic<T>,
|
||||
std::atomic<U> >* _atomic,
|
||||
const std::pair<T, U>& _desired)
|
||||
{
|
||||
set(&_atomic->first, _desired.first);
|
||||
set(&_atomic->second, _desired.second);
|
||||
}
|
||||
//------------------------------------------------------------------------//
|
||||
template <typename T, typename U>
|
||||
inline void set(std::pair<std::atomic<T>,
|
||||
std::atomic<U> >& _atomic,
|
||||
const std::pair<T, U>& _desired)
|
||||
{
|
||||
set(&_atomic, _desired);
|
||||
}
|
||||
//------------------------------------------------------------------------//
|
||||
template <typename T, typename U>
|
||||
inline void increment(std::pair<std::atomic<T>,
|
||||
std::atomic<U> >* _atomic,
|
||||
const std::pair<T, U>& _increment)
|
||||
{
|
||||
increment(&_atomic->first, _increment.first);
|
||||
increment(&_atomic->second, _increment.second);
|
||||
}
|
||||
//------------------------------------------------------------------------//
|
||||
template <typename T, typename U>
|
||||
inline void decrement(std::pair<std::atomic<T>,
|
||||
std::atomic<U> >* _atomic,
|
||||
const std::pair<T, U>& _decrement)
|
||||
{
|
||||
decrement(&_atomic->first, _decrement.first);
|
||||
decrement(&_atomic->second, _decrement.second);
|
||||
}
|
||||
//------------------------------------------------------------------------//
|
||||
template <typename T, typename U>
|
||||
inline void multiply(std::pair<std::atomic<T>,
|
||||
std::atomic<U> >* _atomic,
|
||||
const std::pair<T, U>& _factor)
|
||||
{
|
||||
multiply(&_atomic->first, _factor.first);
|
||||
multiply(&_atomic->second, _factor.second);
|
||||
}
|
||||
//------------------------------------------------------------------------//
|
||||
template <typename T, typename U>
|
||||
inline void divide(std::pair<std::atomic<T>,
|
||||
std::atomic<U> >* _atomic,
|
||||
//------------------------------------------------------------------------//
|
||||
// STANDARD OVERLOAD //
|
||||
//------------------------------------------------------------------------//
|
||||
template <typename T>
|
||||
inline void set(T* _non_atomic, const T& _desired)
|
||||
{
|
||||
*_non_atomic = _desired;
|
||||
}
|
||||
//------------------------------------------------------------------------//
|
||||
template <typename T>
|
||||
inline void set(T& _non_atomic, const T& _desired)
|
||||
{
|
||||
set(&_non_atomic, _desired);
|
||||
}
|
||||
//------------------------------------------------------------------------//
|
||||
// STL PAIR OVERLOAD //
|
||||
//------------------------------------------------------------------------//
|
||||
//
|
||||
//------------------------------------------------------------------------//
|
||||
// WITH ATOMIC TEMPLATE TYPE AS SECOND PARAMETER
|
||||
//------------------------------------------------------------------------//
|
||||
template <typename T, typename U>
|
||||
inline void set(std::pair<std::atomic<T>, std::atomic<U>>* _atomic,
|
||||
const std::pair<T, U>& _desired)
|
||||
{
|
||||
set(&_atomic->first, _desired.first);
|
||||
set(&_atomic->second, _desired.second);
|
||||
}
|
||||
//------------------------------------------------------------------------//
|
||||
template <typename T, typename U>
|
||||
inline void set(std::pair<std::atomic<T>, std::atomic<U>>& _atomic,
|
||||
const std::pair<T, U>& _desired)
|
||||
{
|
||||
set(&_atomic, _desired);
|
||||
}
|
||||
//------------------------------------------------------------------------//
|
||||
template <typename T, typename U>
|
||||
inline void increment(std::pair<std::atomic<T>, std::atomic<U>>* _atomic,
|
||||
const std::pair<T, U>& _increment)
|
||||
{
|
||||
increment(&_atomic->first, _increment.first);
|
||||
increment(&_atomic->second, _increment.second);
|
||||
}
|
||||
//------------------------------------------------------------------------//
|
||||
template <typename T, typename U>
|
||||
inline void decrement(std::pair<std::atomic<T>, std::atomic<U>>* _atomic,
|
||||
const std::pair<T, U>& _decrement)
|
||||
{
|
||||
decrement(&_atomic->first, _decrement.first);
|
||||
decrement(&_atomic->second, _decrement.second);
|
||||
}
|
||||
//------------------------------------------------------------------------//
|
||||
template <typename T, typename U>
|
||||
inline void multiply(std::pair<std::atomic<T>, std::atomic<U>>* _atomic,
|
||||
const std::pair<T, U>& _factor)
|
||||
{
|
||||
divide(&_atomic->first, _factor.first);
|
||||
divide(&_atomic->second, _factor.second);
|
||||
}
|
||||
//------------------------------------------------------------------------//
|
||||
// WITH ATOMICS AS SECOND PARAMETER
|
||||
//------------------------------------------------------------------------//
|
||||
template <typename T, typename U>
|
||||
inline void set(std::pair<std::atomic<T>,
|
||||
std::atomic<U> >* _atomic,
|
||||
const std::pair<std::atomic<T>,
|
||||
std::atomic<U> >& _desired)
|
||||
{
|
||||
set(&_atomic->first, _desired.first);
|
||||
set(&_atomic->second, _desired.second);
|
||||
}
|
||||
//------------------------------------------------------------------------//
|
||||
template <typename T, typename U>
|
||||
inline void set(std::pair<std::atomic<T>,
|
||||
std::atomic<U> >& _atomic,
|
||||
const std::pair<std::atomic<T>,
|
||||
std::atomic<U> >& _desired)
|
||||
{
|
||||
set(&_atomic, _desired);
|
||||
}
|
||||
//------------------------------------------------------------------------//
|
||||
template <typename T, typename U>
|
||||
inline void increment(std::pair<std::atomic<T>,
|
||||
std::atomic<U> >* _atomic,
|
||||
const std::pair<std::atomic<T>,
|
||||
std::atomic<U> >& _increment)
|
||||
{
|
||||
increment(&_atomic->first, _increment.first);
|
||||
increment(&_atomic->second, _increment.second);
|
||||
}
|
||||
//------------------------------------------------------------------------//
|
||||
template <typename T, typename U>
|
||||
inline void decrement(std::pair<std::atomic<T>,
|
||||
std::atomic<U> >* _atomic,
|
||||
const std::pair<std::atomic<T>,
|
||||
std::atomic<U> >& _decrement)
|
||||
{
|
||||
decrement(&_atomic->first, _decrement.first);
|
||||
decrement(&_atomic->second, _decrement.second);
|
||||
}
|
||||
//------------------------------------------------------------------------//
|
||||
template <typename T, typename U>
|
||||
inline void multiply(std::pair<std::atomic<T>,
|
||||
std::atomic<U> >* _atomic,
|
||||
const std::pair<std::atomic<T>,
|
||||
std::atomic<U> >& _factor)
|
||||
{
|
||||
multiply(&_atomic->first, _factor.first);
|
||||
multiply(&_atomic->second, _factor.second);
|
||||
}
|
||||
//------------------------------------------------------------------------//
|
||||
template <typename T, typename U>
|
||||
inline void divide(std::pair<std::atomic<T>,
|
||||
std::atomic<U> >* _atomic,
|
||||
const std::pair<std::atomic<T>,
|
||||
std::atomic<U> >& _factor)
|
||||
{
|
||||
divide(&_atomic->first, _factor.first);
|
||||
divide(&_atomic->second, _factor.second);
|
||||
}
|
||||
//------------------------------------------------------------------------//
|
||||
{
|
||||
multiply(&_atomic->first, _factor.first);
|
||||
multiply(&_atomic->second, _factor.second);
|
||||
}
|
||||
//------------------------------------------------------------------------//
|
||||
template <typename T, typename U>
|
||||
inline void divide(std::pair<std::atomic<T>, std::atomic<U>>* _atomic,
|
||||
const std::pair<T, U>& _factor)
|
||||
{
|
||||
divide(&_atomic->first, _factor.first);
|
||||
divide(&_atomic->second, _factor.second);
|
||||
}
|
||||
//------------------------------------------------------------------------//
|
||||
// WITH ATOMICS AS SECOND PARAMETER
|
||||
//------------------------------------------------------------------------//
|
||||
template <typename T, typename U>
|
||||
inline void set(std::pair<std::atomic<T>, std::atomic<U>>* _atomic,
|
||||
const std::pair<std::atomic<T>, std::atomic<U>>& _desired)
|
||||
{
|
||||
set(&_atomic->first, _desired.first);
|
||||
set(&_atomic->second, _desired.second);
|
||||
}
|
||||
//------------------------------------------------------------------------//
|
||||
template <typename T, typename U>
|
||||
inline void set(std::pair<std::atomic<T>, std::atomic<U>>& _atomic,
|
||||
const std::pair<std::atomic<T>, std::atomic<U>>& _desired)
|
||||
{
|
||||
set(&_atomic, _desired);
|
||||
}
|
||||
//------------------------------------------------------------------------//
|
||||
template <typename T, typename U>
|
||||
inline void increment(
|
||||
std::pair<std::atomic<T>, std::atomic<U>>* _atomic,
|
||||
const std::pair<std::atomic<T>, std::atomic<U>>& _increment)
|
||||
{
|
||||
increment(&_atomic->first, _increment.first);
|
||||
increment(&_atomic->second, _increment.second);
|
||||
}
|
||||
//------------------------------------------------------------------------//
|
||||
template <typename T, typename U>
|
||||
inline void decrement(
|
||||
std::pair<std::atomic<T>, std::atomic<U>>* _atomic,
|
||||
const std::pair<std::atomic<T>, std::atomic<U>>& _decrement)
|
||||
{
|
||||
decrement(&_atomic->first, _decrement.first);
|
||||
decrement(&_atomic->second, _decrement.second);
|
||||
}
|
||||
//------------------------------------------------------------------------//
|
||||
template <typename T, typename U>
|
||||
inline void multiply(std::pair<std::atomic<T>, std::atomic<U>>* _atomic,
|
||||
const std::pair<std::atomic<T>, std::atomic<U>>& _factor)
|
||||
{
|
||||
multiply(&_atomic->first, _factor.first);
|
||||
multiply(&_atomic->second, _factor.second);
|
||||
}
|
||||
//------------------------------------------------------------------------//
|
||||
template <typename T, typename U>
|
||||
inline void divide(std::pair<std::atomic<T>, std::atomic<U>>* _atomic,
|
||||
const std::pair<std::atomic<T>, std::atomic<U>>& _factor)
|
||||
{
|
||||
divide(&_atomic->first, _factor.first);
|
||||
divide(&_atomic->second, _factor.second);
|
||||
}
|
||||
//------------------------------------------------------------------------//
|
||||
|
||||
//------------------------------------------------------------------------//
|
||||
template <typename T>
|
||||
inline T get(const T& _non_atomic)
|
||||
{
|
||||
return _non_atomic;
|
||||
}
|
||||
//------------------------------------------------------------------------//
|
||||
template <typename T>
|
||||
inline T get(const T& _non_atomic, std::memory_order)
|
||||
{
|
||||
return _non_atomic;
|
||||
}
|
||||
//------------------------------------------------------------------------//
|
||||
template <typename T>
|
||||
inline T get(const std::atomic<T>& _atomic)
|
||||
{
|
||||
return _atomic.load();
|
||||
}
|
||||
//------------------------------------------------------------------------//
|
||||
template <typename T>
|
||||
inline T get(const std::atomic<T>& _atomic, std::memory_order mem_odr)
|
||||
{
|
||||
return _atomic.load(mem_odr);
|
||||
}
|
||||
//------------------------------------------------------------------------//
|
||||
template <typename T, typename U>
|
||||
inline std::pair<T, U> get(
|
||||
const std::pair<std::atomic<T>, std::atomic<U>>& _atomic)
|
||||
{
|
||||
return std::pair<T, U>(get(_atomic.first), get(_atomic.second));
|
||||
}
|
||||
//------------------------------------------------------------------------//
|
||||
template <typename T, typename U>
|
||||
inline std::pair<T, U> get(
|
||||
const std::pair<std::atomic<T>, std::atomic<U>>& _atomic,
|
||||
std::memory_order mem_odr)
|
||||
{
|
||||
return std::pair<T, U>(get(_atomic.first, mem_odr),
|
||||
get(_atomic.second, mem_odr));
|
||||
}
|
||||
//------------------------------------------------------------------------//
|
||||
|
||||
//------------------------------------------------------------------------//
|
||||
template <typename T>
|
||||
inline T get(const T& _non_atomic)
|
||||
{
|
||||
return _non_atomic;
|
||||
}
|
||||
//------------------------------------------------------------------------//
|
||||
template <typename T>
|
||||
inline T get(const T& _non_atomic, std::memory_order)
|
||||
{
|
||||
return _non_atomic;
|
||||
}
|
||||
//------------------------------------------------------------------------//
|
||||
template <typename T>
|
||||
inline T get(const std::atomic<T>& _atomic)
|
||||
{
|
||||
return _atomic.load();
|
||||
}
|
||||
//------------------------------------------------------------------------//
|
||||
template <typename T>
|
||||
inline T get(const std::atomic<T>& _atomic,
|
||||
std::memory_order mem_odr)
|
||||
{
|
||||
return _atomic.load(mem_odr);
|
||||
}
|
||||
//------------------------------------------------------------------------//
|
||||
template <typename T, typename U>
|
||||
inline std::pair<T, U> get(const std::pair<std::atomic<T>,
|
||||
std::atomic<U> >& _atomic)
|
||||
{
|
||||
return std::pair<T, U>(get(_atomic.first), get(_atomic.second));
|
||||
}
|
||||
//------------------------------------------------------------------------//
|
||||
template <typename T, typename U>
|
||||
inline std::pair<T, U> get(const std::pair<std::atomic<T>,
|
||||
std::atomic<U> >& _atomic,
|
||||
std::memory_order mem_odr)
|
||||
{
|
||||
return std::pair<T, U>(get(_atomic.first, mem_odr),
|
||||
get(_atomic.second, mem_odr));
|
||||
}
|
||||
//------------------------------------------------------------------------//
|
||||
//------------------------------------------------------------------------//
|
||||
// for plain old data (POD) and pairs (e.g. std::pair<atomic<T>, atomic<U>>)
|
||||
template <typename _Tp_base, typename _Tp_atom>
|
||||
inline _Tp_base base(const _Tp_atom& _atomic)
|
||||
{
|
||||
return get(_atomic);
|
||||
}
|
||||
//------------------------------------------------------------------------//
|
||||
|
||||
|
||||
|
||||
//------------------------------------------------------------------------//
|
||||
// for plain old data (POD) and pairs (e.g. std::pair<atomic<T>, atomic<U>>)
|
||||
template <typename _Tp_base, typename _Tp_atom>
|
||||
inline _Tp_base base(const _Tp_atom& _atomic)
|
||||
{
|
||||
return get(_atomic);
|
||||
}
|
||||
//------------------------------------------------------------------------//
|
||||
|
||||
} // namespace atomics
|
||||
} // namespace atomics
|
||||
|
||||
//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
|
||||
|
||||
#endif // G4MULTITHREADED
|
||||
#endif // G4MULTITHREADED
|
||||
|
||||
#endif // atomic_typedefs_hh_
|
||||
|
||||
@@ -37,9 +37,6 @@
|
||||
//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
|
||||
//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
|
||||
|
||||
|
||||
|
||||
|
||||
#ifndef tsactioninitialization_hh_
|
||||
#define tsactioninitialization_hh_
|
||||
|
||||
@@ -51,21 +48,20 @@
|
||||
|
||||
class TSActionInitialization : public G4VUserActionInitialization
|
||||
{
|
||||
public:
|
||||
// Constructor and Destructors
|
||||
TSActionInitialization();
|
||||
virtual ~TSActionInitialization();
|
||||
public:
|
||||
// Constructor and Destructors
|
||||
TSActionInitialization();
|
||||
virtual ~TSActionInitialization();
|
||||
|
||||
static TSActionInitialization* Instance();
|
||||
static TSActionInitialization* Instance();
|
||||
|
||||
public:
|
||||
virtual void BuildForMaster() const;
|
||||
virtual void Build() const;
|
||||
|
||||
private:
|
||||
// Private functions
|
||||
static TSActionInitialization* fgInstance;
|
||||
public:
|
||||
virtual void BuildForMaster() const;
|
||||
virtual void Build() const;
|
||||
|
||||
private:
|
||||
// Private functions
|
||||
static TSActionInitialization* fgInstance;
|
||||
};
|
||||
|
||||
#endif
|
||||
|
||||
@@ -51,11 +51,9 @@
|
||||
//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
|
||||
//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
|
||||
|
||||
|
||||
#ifndef tsdetectorconstruction_hh
|
||||
#define tsdetectorconstruction_hh 1
|
||||
|
||||
|
||||
#include "globals.hh"
|
||||
#include "G4VUserDetectorConstruction.hh"
|
||||
#include "G4ThreeVector.hh"
|
||||
@@ -72,41 +70,45 @@ class G4Material;
|
||||
|
||||
class TSDetectorConstruction : public G4VUserDetectorConstruction
|
||||
{
|
||||
public:
|
||||
typedef std::map<G4String, G4Material*> MaterialCollection_t;
|
||||
typedef std::set<G4LogicalVolume*> ScoringVolumes_t;
|
||||
public:
|
||||
typedef std::map<G4String, G4Material*> MaterialCollection_t;
|
||||
typedef std::set<G4LogicalVolume*> ScoringVolumes_t;
|
||||
|
||||
public:
|
||||
TSDetectorConstruction();
|
||||
virtual ~TSDetectorConstruction();
|
||||
public:
|
||||
TSDetectorConstruction();
|
||||
virtual ~TSDetectorConstruction();
|
||||
|
||||
static TSDetectorConstruction* Instance();
|
||||
static TSDetectorConstruction* Instance();
|
||||
|
||||
public:
|
||||
G4VPhysicalVolume* Construct();
|
||||
inline const G4ThreeVector& GetWorldDimensions() const { return fWorldDim; }
|
||||
inline const ScoringVolumes_t& GetScoringVolumes() const
|
||||
{ return fScoringVolumes; }
|
||||
inline const G4String& GetMFDName() const { return fMfdName; }
|
||||
inline G4int GetTotalTargets() const
|
||||
{ return fTargetSections.x() * fTargetSections.y() * fTargetSections.z(); }
|
||||
public:
|
||||
G4VPhysicalVolume* Construct();
|
||||
inline const G4ThreeVector& GetWorldDimensions() const { return fWorldDim; }
|
||||
inline const ScoringVolumes_t& GetScoringVolumes() const
|
||||
{
|
||||
return fScoringVolumes;
|
||||
}
|
||||
inline const G4String& GetMFDName() const { return fMfdName; }
|
||||
inline G4int GetTotalTargets() const
|
||||
{
|
||||
return fTargetSections.x() * fTargetSections.y() * fTargetSections.z();
|
||||
}
|
||||
|
||||
protected:
|
||||
virtual MaterialCollection_t ConstructMaterials();
|
||||
virtual G4VPhysicalVolume* ConstructWorld(const MaterialCollection_t&);
|
||||
virtual void ConstructSDandField();
|
||||
protected:
|
||||
virtual MaterialCollection_t ConstructMaterials();
|
||||
virtual G4VPhysicalVolume* ConstructWorld(const MaterialCollection_t&);
|
||||
virtual void ConstructSDandField();
|
||||
|
||||
private:
|
||||
static TSDetectorConstruction* fgInstance;
|
||||
G4VPhysicalVolume* fWorldPhys;
|
||||
ScoringVolumes_t fScoringVolumes;
|
||||
G4String fWorldMaterialName;
|
||||
G4String fTargetMaterialName;
|
||||
G4String fCasingMaterialName;
|
||||
G4ThreeVector fWorldDim;
|
||||
G4ThreeVector fTargetDim;
|
||||
G4ThreeVector fTargetSections;
|
||||
G4String fMfdName;
|
||||
private:
|
||||
static TSDetectorConstruction* fgInstance;
|
||||
G4VPhysicalVolume* fWorldPhys;
|
||||
ScoringVolumes_t fScoringVolumes;
|
||||
G4String fWorldMaterialName;
|
||||
G4String fTargetMaterialName;
|
||||
G4String fCasingMaterialName;
|
||||
G4ThreeVector fWorldDim;
|
||||
G4ThreeVector fTargetDim;
|
||||
G4ThreeVector fTargetSections;
|
||||
G4String fMfdName;
|
||||
};
|
||||
|
||||
#endif
|
||||
|
||||
@@ -39,11 +39,9 @@
|
||||
//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
|
||||
//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
|
||||
|
||||
|
||||
#ifndef tsphysicslist_hh
|
||||
#define tsphysicslist_hh 1
|
||||
|
||||
|
||||
#include "globals.hh"
|
||||
#include "G4VUserPhysicsList.hh"
|
||||
#include "G4VPhysicsConstructor.hh"
|
||||
@@ -51,24 +49,23 @@
|
||||
#include <deque>
|
||||
class TSPhysicsList : public G4VUserPhysicsList
|
||||
{
|
||||
public:
|
||||
typedef std::deque<G4VPhysicsConstructor*> PhysicsSet_t;
|
||||
public:
|
||||
typedef std::deque<G4VPhysicsConstructor*> PhysicsSet_t;
|
||||
|
||||
public:
|
||||
TSPhysicsList();
|
||||
virtual ~TSPhysicsList();
|
||||
public:
|
||||
TSPhysicsList();
|
||||
virtual ~TSPhysicsList();
|
||||
|
||||
public:
|
||||
static TSPhysicsList* Instance();
|
||||
void ConstructParticle();
|
||||
void ConstructProcess();
|
||||
void SetCuts();
|
||||
|
||||
private:
|
||||
static TSPhysicsList* fgInstance;
|
||||
PhysicsSet_t fConstructors;
|
||||
G4double fDefaultCutValue;
|
||||
public:
|
||||
static TSPhysicsList* Instance();
|
||||
void ConstructParticle();
|
||||
void ConstructProcess();
|
||||
void SetCuts();
|
||||
|
||||
private:
|
||||
static TSPhysicsList* fgInstance;
|
||||
PhysicsSet_t fConstructors;
|
||||
G4double fDefaultCutValue;
|
||||
};
|
||||
|
||||
#endif
|
||||
|
||||
@@ -36,7 +36,6 @@
|
||||
//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
|
||||
//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
|
||||
|
||||
|
||||
#ifndef tsprimarygeneratoraction_hh
|
||||
#define tsprimarygeneratoraction_hh 1
|
||||
|
||||
@@ -48,16 +47,15 @@ class G4ParticleGun;
|
||||
|
||||
class TSPrimaryGeneratorAction : public G4VUserPrimaryGeneratorAction
|
||||
{
|
||||
public:
|
||||
TSPrimaryGeneratorAction();
|
||||
virtual ~TSPrimaryGeneratorAction();
|
||||
public:
|
||||
TSPrimaryGeneratorAction();
|
||||
virtual ~TSPrimaryGeneratorAction();
|
||||
|
||||
public:
|
||||
void GeneratePrimaries(G4Event*);
|
||||
|
||||
private:
|
||||
G4ParticleGun* fGun;
|
||||
public:
|
||||
void GeneratePrimaries(G4Event*);
|
||||
|
||||
private:
|
||||
G4ParticleGun* fGun;
|
||||
};
|
||||
|
||||
#endif
|
||||
|
||||
@@ -51,7 +51,6 @@
|
||||
//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
|
||||
//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
|
||||
|
||||
|
||||
#ifndef tsrun_h
|
||||
#define tsrun_h 1
|
||||
|
||||
@@ -69,44 +68,44 @@
|
||||
|
||||
class G4Event;
|
||||
|
||||
//template <typename _Tp> using G4StatContainer = G4THitsMap<_Tp>;
|
||||
//template <typename _Tp> using G4StatContainer = G4THitsVector<_Tp>;
|
||||
template <typename _Tp> using G4StatContainer = G4THitsDeque<_Tp>;
|
||||
// template <typename _Tp> using G4StatContainer = G4THitsMap<_Tp>;
|
||||
// template <typename _Tp> using G4StatContainer = G4THitsVector<_Tp>;
|
||||
template <typename _Tp>
|
||||
using G4StatContainer = G4THitsDeque<_Tp>;
|
||||
|
||||
class TSRun : public G4Run
|
||||
{
|
||||
public:
|
||||
typedef std::map<G4int, G4double> MutexHitsMap_t;
|
||||
public:
|
||||
typedef std::map<G4int, G4double> MutexHitsMap_t;
|
||||
|
||||
public:
|
||||
TSRun(const G4String&);
|
||||
virtual ~TSRun();
|
||||
public:
|
||||
TSRun(const G4String&);
|
||||
virtual ~TSRun();
|
||||
|
||||
// virtual method from G4Run.
|
||||
// The method is overriden in this class for scoring.
|
||||
virtual void RecordEvent(const G4Event*);
|
||||
// virtual method from G4Run.
|
||||
// The method is overriden in this class for scoring.
|
||||
virtual void RecordEvent(const G4Event*);
|
||||
|
||||
// Access methods for scoring information.
|
||||
// - Get HitsMap of this RUN.
|
||||
G4THitsMap<G4double>* GetHitsMap(const G4String& collname) const;
|
||||
G4TAtomicHitsMap<G4double>* GetAtomicHitsMap(const G4String&) const;
|
||||
MutexHitsMap_t* GetMutexHitsMap(const G4String&) const;
|
||||
G4StatContainer<G4StatAnalysis>* GetStatMap(const G4String& collname) const;
|
||||
G4StatContainer<G4ConvergenceTester>* GetConvMap(const G4String&) const;
|
||||
// Access methods for scoring information.
|
||||
// - Get HitsMap of this RUN.
|
||||
G4THitsMap<G4double>* GetHitsMap(const G4String& collname) const;
|
||||
G4TAtomicHitsMap<G4double>* GetAtomicHitsMap(const G4String&) const;
|
||||
MutexHitsMap_t* GetMutexHitsMap(const G4String&) const;
|
||||
G4StatContainer<G4StatAnalysis>* GetStatMap(const G4String& collname) const;
|
||||
G4StatContainer<G4ConvergenceTester>* GetConvMap(const G4String&) const;
|
||||
|
||||
void ConstructMFD(const G4String&);
|
||||
void ConstructMFD(const G4String&);
|
||||
|
||||
virtual void Merge(const G4Run*);
|
||||
|
||||
private:
|
||||
std::vector<G4String> fCollNames;
|
||||
std::vector<G4int> fCollIDs;
|
||||
std::vector<G4THitsMap<G4double>*> fRunMaps;
|
||||
std::vector<G4StatContainer<G4StatAnalysis>*> fStatMaps;
|
||||
static std::vector<G4TAtomicHitsMap<G4double>*> fAtomicRunMaps;
|
||||
static std::map<G4String, MutexHitsMap_t> fMutexRunMaps;
|
||||
static std::vector<G4StatContainer<G4ConvergenceTester>*> fConvMaps;
|
||||
virtual void Merge(const G4Run*);
|
||||
|
||||
private:
|
||||
std::vector<G4String> fCollNames;
|
||||
std::vector<G4int> fCollIDs;
|
||||
std::vector<G4THitsMap<G4double>*> fRunMaps;
|
||||
std::vector<G4StatContainer<G4StatAnalysis>*> fStatMaps;
|
||||
static std::vector<G4TAtomicHitsMap<G4double>*> fAtomicRunMaps;
|
||||
static std::map<G4String, MutexHitsMap_t> fMutexRunMaps;
|
||||
static std::vector<G4StatContainer<G4ConvergenceTester>*> fConvMaps;
|
||||
};
|
||||
|
||||
#endif
|
||||
|
||||
@@ -34,7 +34,6 @@
|
||||
//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
|
||||
//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
|
||||
|
||||
|
||||
#ifndef tsrunaction_hh
|
||||
#define tsrunaction_hh 1
|
||||
|
||||
@@ -50,25 +49,24 @@ class TSDetectorConstruction;
|
||||
|
||||
class TSRunAction : public G4UserRunAction
|
||||
{
|
||||
public:
|
||||
typedef std::tuple<G4double, G4double, G4double> Compare_t;
|
||||
typedef std::map<G4int, Compare_t> IDcompare_t;
|
||||
typedef std::map<G4String, IDcompare_t> TypeCompare_t;
|
||||
public:
|
||||
typedef std::tuple<G4double, G4double, G4double> Compare_t;
|
||||
typedef std::map<G4int, Compare_t> IDcompare_t;
|
||||
typedef std::map<G4String, IDcompare_t> TypeCompare_t;
|
||||
|
||||
public:
|
||||
TSRunAction();
|
||||
virtual ~TSRunAction();
|
||||
public:
|
||||
TSRunAction();
|
||||
virtual ~TSRunAction();
|
||||
|
||||
public:
|
||||
virtual void BeginOfRunAction(const G4Run*);
|
||||
virtual void EndOfRunAction(const G4Run*);
|
||||
virtual G4Run* GenerateRun();
|
||||
|
||||
private:
|
||||
TSDetectorConstruction* fDetector;
|
||||
G4String fName;
|
||||
TypeCompare_t fTypeCompare;
|
||||
public:
|
||||
virtual void BeginOfRunAction(const G4Run*);
|
||||
virtual void EndOfRunAction(const G4Run*);
|
||||
virtual G4Run* GenerateRun();
|
||||
|
||||
private:
|
||||
TSDetectorConstruction* fDetector;
|
||||
G4String fName;
|
||||
TypeCompare_t fTypeCompare;
|
||||
};
|
||||
|
||||
#endif
|
||||
|
||||
Reference in New Issue
Block a user