Skip to content

Commit

Permalink
manager: remove unneded private InstanceHolder class
Browse files Browse the repository at this point in the history
we realy need this so simplify this code a bit.

Also fixes desura#516

NOTE: this is a candidate for the stable branch
  • Loading branch information
karolherbst committed Mar 21, 2013
1 parent 248f5f3 commit ecca1bc
Showing 1 changed file with 6 additions and 57 deletions.
63 changes: 6 additions & 57 deletions src/static/managers/code/Managers.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -52,22 +52,8 @@ class SingletonHolder
static Class &Instance();

private:
class InstanceHolder
{
public:
bool operator !();
Class & operator *();
Class & operator =(Class* ref);
InstanceHolder();
~InstanceHolder();
MutexType & mutex();

private:
Class *_instance;
MutexType _mutex;
};

static InstanceHolder instance;
static Class* instance;
static MutexType mutex;

static void NewInstance();

Expand All @@ -89,57 +75,20 @@ template <typename Class>
inline void SingletonHolder<Class>::NewInstance()
{
// enter critical section
EnterCriticalSection(&instance.mutex());
EnterCriticalSection(&mutex);

// check again for creation (another thread could accessed the critical section before
if (!instance)
instance = new Class();

LeaveCriticalSection(&instance.mutex());
LeaveCriticalSection(&mutex);
}

template <typename Class>
typename SingletonHolder<Class>::InstanceHolder SingletonHolder<Class>::instance;

template <typename Class>
inline bool SingletonHolder<Class>::InstanceHolder::operator !()
{
return this->_instance == nullptr;
}
Class *SingletonHolder<Class>::instance = nullptr;

template <typename Class>
inline Class & SingletonHolder<Class>::InstanceHolder::operator *()
{
return *this->_instance;
}

template <typename Class>
inline Class & SingletonHolder<Class>::InstanceHolder::operator =(Class* ref)
{
this->_instance = ref;
}

template <typename Class>
SingletonHolder<Class>::InstanceHolder::InstanceHolder()
: _instance(nullptr){}

template <typename Class>
SingletonHolder<Class>::InstanceHolder::~InstanceHolder()
{
EnterCriticalSection(&mutex());
if (this->_instance != nullptr)
{
delete this->_instance;
this->_instance = nullptr;
}
LeaveCriticalSection(&mutex());
}

template <typename Class>
MutexType & SingletonHolder<Class>::InstanceHolder::mutex()
{
return this->_mutex;
}
MutexType SingletonHolder<Class>::mutex;

class ManagersImpl
{
Expand Down

0 comments on commit ecca1bc

Please sign in to comment.