/* * AtomicInstance_impl.hpp * * Created on: Apr 26, 2016 * Author: heber */ #ifndef ATOMICINSTANCE_IMPL_HPP_ #define ATOMICINSTANCE_IMPL_HPP_ // include config.h #ifdef HAVE_CONFIG_H #include #endif #include "CodePatterns/Assert.hpp" #include "AtomicInstance.hpp" template boost::mutex AtomicInstance< T >::atomicLock; template AtomicInstance::AtomicInstance(T* _content) : content(_content) { if (content != NULL) AtomicInstance::atomicLock.lock(); } template AtomicInstance::AtomicInstance() : content(NULL) { } template AtomicInstance::~AtomicInstance() { if (content != NULL) AtomicInstance::atomicLock.unlock(); } template T& AtomicInstance::operator*() { return *content;} template const T& AtomicInstance::operator*() const { return *content;} template AtomicInstance& AtomicInstance::operator=(const AtomicInstance& rhs) { if (this != &rhs) { this->content = rhs.content; const_cast&>(rhs).content = NULL; } return *this; } template AtomicInstance::AtomicInstance(AtomicInstance& rhs) : content(rhs.content) { // check for self-copy if (this != &rhs) rhs.content = NULL; } template AtomicInstance::AtomicInstance(const AtomicInstance& rhs) : content(rhs.content) { // check for self-copy ASSERT (this != &rhs, "AtomicInstance::AtomicInstance() - self-assignment not allowed for rhs copy."); const_cast&>(rhs).content = NULL; } #endif /* ATOMICINSTANCE_IMPL_HPP_ */