forked from boostorg/beast
New SharedSingleton, resolves destruction of objects with static storage duration.
This commit is contained in:
1 parent
41eb8a1e29
commit
55447b05ac
17 files changed
+150
-229
No files matched your search
@@ -17,18 +17,14 @@
|
||||
*/
|
||||
//==============================================================================
|
||||
|
||||
class DeadlineTimer::Manager
|
||||
: public SharedSingleton <DeadlineTimer::Manager>
|
||||
, protected Thread
|
||||
class DeadlineTimer::Manager : protected Thread
|
||||
{
|
||||
private:
|
||||
typedef CriticalSection LockType;
|
||||
typedef List <DeadlineTimer> Items;
|
||||
|
||||
public:
|
||||
Manager ()
|
||||
: SharedSingleton <Manager> (SingletonLifetime::persistAfterCreation)
|
||||
, Thread ("DeadlineTimer::Manager")
|
||||
Manager () : Thread ("DeadlineTimer::Manager")
|
||||
{
|
||||
startThread ();
|
||||
}
|
||||
@@ -200,11 +196,6 @@ public:
|
||||
}
|
||||
}
|
||||
|
||||
static Manager* createInstance ()
|
||||
{
|
||||
return new Manager;
|
||||
}
|
||||
|
||||
private:
|
||||
CriticalSection m_mutex;
|
||||
Items m_items;
|
||||
@@ -214,7 +205,8 @@ private:
|
||||
|
||||
DeadlineTimer::DeadlineTimer (Listener* listener)
|
||||
: m_listener (listener)
|
||||
, m_manager (Manager::getInstance ())
|
||||
, m_manager (SharedSingleton <Manager>::getInstance (
|
||||
SingletonLifetime::persistAfterCreation))
|
||||
, m_isActive (false)
|
||||
{
|
||||
}
|
||||
|
||||
@@ -112,7 +112,7 @@ private:
|
||||
class Manager;
|
||||
|
||||
Listener* const m_listener;
|
||||
SharedPtr <Manager> m_manager;
|
||||
SharedPtr <SharedSingleton <Manager> > m_manager;
|
||||
bool m_isActive;
|
||||
Time m_notificationTime;
|
||||
double m_secondsRecurring; // non zero if recurring
|
||||
|
||||
@@ -1,49 +0,0 @@
|
||||
//------------------------------------------------------------------------------
|
||||
/*
|
||||
This file is part of Beast: https://github.com/vinniefalco/Beast
|
||||
Copyright 2013, Vinnie Falco <vinnie.falco@gmail.com>
|
||||
|
||||
Permission to use, copy, modify, and/or distribute this software for any
|
||||
purpose with or without fee is hereby granted, provided that the above
|
||||
copyright notice and this permission notice appear in all copies.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
|
||||
WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
|
||||
MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
|
||||
ANY SPECIAL , DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
|
||||
WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
|
||||
ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
|
||||
OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
||||
*/
|
||||
//==============================================================================
|
||||
|
||||
#ifndef BEAST_GLOBALTHREADGROUP_H_INCLUDED
|
||||
#define BEAST_GLOBALTHREADGROUP_H_INCLUDED
|
||||
|
||||
/*============================================================================*/
|
||||
/**
|
||||
A ThreadGroup singleton.
|
||||
|
||||
@see ThreadGroup
|
||||
|
||||
@ingroup beast_concurrent
|
||||
*/
|
||||
class BEAST_API GlobalThreadGroup : public ThreadGroup,
|
||||
public SharedSingleton <GlobalThreadGroup>
|
||||
{
|
||||
private:
|
||||
friend class SharedSingleton <GlobalThreadGroup>;
|
||||
|
||||
GlobalThreadGroup ()
|
||||
: SharedSingleton <GlobalThreadGroup> (
|
||||
SingletonLifetime::persistAfterCreation)
|
||||
{
|
||||
}
|
||||
|
||||
static GlobalThreadGroup* createInstance ()
|
||||
{
|
||||
return new GlobalThreadGroup;
|
||||
}
|
||||
};
|
||||
|
||||
#endif
|
||||
@@ -616,7 +616,7 @@ void ListenersBase::remove_void (void* const listener)
|
||||
|
||||
// Remove it from the list and manually release
|
||||
// the reference since the list uses raw pointers.
|
||||
m_groups.erase (m_groups.iterator_to (*group);
|
||||
m_groups.erase (m_groups.iterator_to (*group));
|
||||
group->decReferenceCount ();
|
||||
|
||||
// It is still possible for the group to exist at this
|
||||
|
||||
@@ -60,10 +60,9 @@ public:
|
||||
It is best to keep this object around instead of creating and destroying
|
||||
it every time you need to run a loop.
|
||||
|
||||
@param pool The ThreadGroup to use. If this is omitted then a singleton
|
||||
ThreadGroup is used which contains one thread per CPU.
|
||||
@param pool The ThreadGroup to use.
|
||||
*/
|
||||
explicit ParallelFor (ThreadGroup& pool = *GlobalThreadGroup::getInstance ());
|
||||
explicit ParallelFor (ThreadGroup& pool);
|
||||
|
||||
/** Determine the number of threads in the group.
|
||||
|
||||
|
||||
Reference in new issue
Block a user