mirror of
https://github.com/XRPLF/rippled.git
synced 2025-11-21 11:35:53 +00:00
Remove unused and broken classes
This commit is contained in:
@@ -287,10 +287,7 @@
|
|||||||
<ClInclude Include="..\..\modules\beast_core\thread\beast_InterruptibleThread.h" />
|
<ClInclude Include="..\..\modules\beast_core\thread\beast_InterruptibleThread.h" />
|
||||||
<ClInclude Include="..\..\modules\beast_core\thread\beast_Listeners.h" />
|
<ClInclude Include="..\..\modules\beast_core\thread\beast_Listeners.h" />
|
||||||
<ClInclude Include="..\..\modules\beast_core\thread\beast_ManualCallQueue.h" />
|
<ClInclude Include="..\..\modules\beast_core\thread\beast_ManualCallQueue.h" />
|
||||||
<ClInclude Include="..\..\modules\beast_core\thread\beast_ParallelFor.h" />
|
|
||||||
<ClInclude Include="..\..\modules\beast_core\thread\beast_Semaphore.h" />
|
<ClInclude Include="..\..\modules\beast_core\thread\beast_Semaphore.h" />
|
||||||
<ClInclude Include="..\..\modules\beast_core\thread\beast_SerialFor.h" />
|
|
||||||
<ClInclude Include="..\..\modules\beast_core\thread\beast_ThreadGroup.h" />
|
|
||||||
<ClInclude Include="..\..\modules\beast_core\thread\beast_ThreadWithCallQueue.h" />
|
<ClInclude Include="..\..\modules\beast_core\thread\beast_ThreadWithCallQueue.h" />
|
||||||
<ClInclude Include="..\..\modules\beast_core\thread\beast_Workers.h" />
|
<ClInclude Include="..\..\modules\beast_core\thread\beast_Workers.h" />
|
||||||
<ClInclude Include="..\..\modules\beast_core\thread\detail\ScopedLock.h" />
|
<ClInclude Include="..\..\modules\beast_core\thread\detail\ScopedLock.h" />
|
||||||
@@ -1102,24 +1099,12 @@
|
|||||||
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">true</ExcludedFromBuild>
|
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">true</ExcludedFromBuild>
|
||||||
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Release|x64'">true</ExcludedFromBuild>
|
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Release|x64'">true</ExcludedFromBuild>
|
||||||
</ClCompile>
|
</ClCompile>
|
||||||
<ClCompile Include="..\..\modules\beast_core\thread\beast_ParallelFor.cpp">
|
|
||||||
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">true</ExcludedFromBuild>
|
|
||||||
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">true</ExcludedFromBuild>
|
|
||||||
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">true</ExcludedFromBuild>
|
|
||||||
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Release|x64'">true</ExcludedFromBuild>
|
|
||||||
</ClCompile>
|
|
||||||
<ClCompile Include="..\..\modules\beast_core\thread\beast_Semaphore.cpp">
|
<ClCompile Include="..\..\modules\beast_core\thread\beast_Semaphore.cpp">
|
||||||
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">true</ExcludedFromBuild>
|
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">true</ExcludedFromBuild>
|
||||||
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">true</ExcludedFromBuild>
|
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">true</ExcludedFromBuild>
|
||||||
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">true</ExcludedFromBuild>
|
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">true</ExcludedFromBuild>
|
||||||
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Release|x64'">true</ExcludedFromBuild>
|
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Release|x64'">true</ExcludedFromBuild>
|
||||||
</ClCompile>
|
</ClCompile>
|
||||||
<ClCompile Include="..\..\modules\beast_core\thread\beast_ThreadGroup.cpp">
|
|
||||||
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">true</ExcludedFromBuild>
|
|
||||||
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">true</ExcludedFromBuild>
|
|
||||||
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">true</ExcludedFromBuild>
|
|
||||||
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Release|x64'">true</ExcludedFromBuild>
|
|
||||||
</ClCompile>
|
|
||||||
<ClCompile Include="..\..\modules\beast_core\thread\beast_ThreadWithCallQueue.cpp">
|
<ClCompile Include="..\..\modules\beast_core\thread\beast_ThreadWithCallQueue.cpp">
|
||||||
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">true</ExcludedFromBuild>
|
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">true</ExcludedFromBuild>
|
||||||
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">true</ExcludedFromBuild>
|
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">true</ExcludedFromBuild>
|
||||||
|
|||||||
@@ -710,18 +710,9 @@
|
|||||||
<ClInclude Include="..\..\modules\beast_core\thread\beast_ManualCallQueue.h">
|
<ClInclude Include="..\..\modules\beast_core\thread\beast_ManualCallQueue.h">
|
||||||
<Filter>beast_core\thread</Filter>
|
<Filter>beast_core\thread</Filter>
|
||||||
</ClInclude>
|
</ClInclude>
|
||||||
<ClInclude Include="..\..\modules\beast_core\thread\beast_ParallelFor.h">
|
|
||||||
<Filter>beast_core\thread</Filter>
|
|
||||||
</ClInclude>
|
|
||||||
<ClInclude Include="..\..\modules\beast_core\thread\beast_Semaphore.h">
|
<ClInclude Include="..\..\modules\beast_core\thread\beast_Semaphore.h">
|
||||||
<Filter>beast_core\thread</Filter>
|
<Filter>beast_core\thread</Filter>
|
||||||
</ClInclude>
|
</ClInclude>
|
||||||
<ClInclude Include="..\..\modules\beast_core\thread\beast_SerialFor.h">
|
|
||||||
<Filter>beast_core\thread</Filter>
|
|
||||||
</ClInclude>
|
|
||||||
<ClInclude Include="..\..\modules\beast_core\thread\beast_ThreadGroup.h">
|
|
||||||
<Filter>beast_core\thread</Filter>
|
|
||||||
</ClInclude>
|
|
||||||
<ClInclude Include="..\..\modules\beast_core\thread\beast_ThreadWithCallQueue.h">
|
<ClInclude Include="..\..\modules\beast_core\thread\beast_ThreadWithCallQueue.h">
|
||||||
<Filter>beast_core\thread</Filter>
|
<Filter>beast_core\thread</Filter>
|
||||||
</ClInclude>
|
</ClInclude>
|
||||||
@@ -1390,15 +1381,9 @@
|
|||||||
<ClCompile Include="..\..\modules\beast_core\thread\beast_ManualCallQueue.cpp">
|
<ClCompile Include="..\..\modules\beast_core\thread\beast_ManualCallQueue.cpp">
|
||||||
<Filter>beast_core\thread</Filter>
|
<Filter>beast_core\thread</Filter>
|
||||||
</ClCompile>
|
</ClCompile>
|
||||||
<ClCompile Include="..\..\modules\beast_core\thread\beast_ParallelFor.cpp">
|
|
||||||
<Filter>beast_core\thread</Filter>
|
|
||||||
</ClCompile>
|
|
||||||
<ClCompile Include="..\..\modules\beast_core\thread\beast_Semaphore.cpp">
|
<ClCompile Include="..\..\modules\beast_core\thread\beast_Semaphore.cpp">
|
||||||
<Filter>beast_core\thread</Filter>
|
<Filter>beast_core\thread</Filter>
|
||||||
</ClCompile>
|
</ClCompile>
|
||||||
<ClCompile Include="..\..\modules\beast_core\thread\beast_ThreadGroup.cpp">
|
|
||||||
<Filter>beast_core\thread</Filter>
|
|
||||||
</ClCompile>
|
|
||||||
<ClCompile Include="..\..\modules\beast_core\thread\beast_ThreadWithCallQueue.cpp">
|
<ClCompile Include="..\..\modules\beast_core\thread\beast_ThreadWithCallQueue.cpp">
|
||||||
<Filter>beast_core\thread</Filter>
|
<Filter>beast_core\thread</Filter>
|
||||||
</ClCompile>
|
</ClCompile>
|
||||||
|
|||||||
@@ -220,8 +220,6 @@ namespace beast
|
|||||||
#include "thread/beast_CallQueue.cpp"
|
#include "thread/beast_CallQueue.cpp"
|
||||||
#include "thread/beast_Listeners.cpp"
|
#include "thread/beast_Listeners.cpp"
|
||||||
#include "thread/beast_ManualCallQueue.cpp"
|
#include "thread/beast_ManualCallQueue.cpp"
|
||||||
#include "thread/beast_ParallelFor.cpp"
|
|
||||||
#include "thread/beast_ThreadGroup.cpp"
|
|
||||||
#include "thread/beast_ThreadWithCallQueue.cpp"
|
#include "thread/beast_ThreadWithCallQueue.cpp"
|
||||||
#include "thread/beast_Workers.cpp"
|
#include "thread/beast_Workers.cpp"
|
||||||
|
|
||||||
|
|||||||
@@ -418,13 +418,10 @@ extern BEAST_API void BEAST_CALLTYPE logAssertion (char const* file, int line) n
|
|||||||
#include "memory/beast_GlobalFifoFreeStore.h"
|
#include "memory/beast_GlobalFifoFreeStore.h"
|
||||||
|
|
||||||
#include "thread/beast_Semaphore.h"
|
#include "thread/beast_Semaphore.h"
|
||||||
#include "thread/beast_SerialFor.h"
|
|
||||||
#include "thread/beast_InterruptibleThread.h"
|
#include "thread/beast_InterruptibleThread.h"
|
||||||
#include "thread/beast_ThreadGroup.h"
|
|
||||||
#include "thread/beast_CallQueue.h"
|
#include "thread/beast_CallQueue.h"
|
||||||
#include "thread/beast_Listeners.h"
|
#include "thread/beast_Listeners.h"
|
||||||
#include "thread/beast_ManualCallQueue.h"
|
#include "thread/beast_ManualCallQueue.h"
|
||||||
#include "thread/beast_ParallelFor.h"
|
|
||||||
#include "thread/beast_ThreadWithCallQueue.h"
|
#include "thread/beast_ThreadWithCallQueue.h"
|
||||||
#include "thread/beast_Workers.h"
|
#include "thread/beast_Workers.h"
|
||||||
|
|
||||||
|
|||||||
@@ -1,111 +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.
|
|
||||||
*/
|
|
||||||
//==============================================================================
|
|
||||||
|
|
||||||
class OncePerSecond::TimerSingleton
|
|
||||||
: public SharedSingleton <OncePerSecond::TimerSingleton>
|
|
||||||
, private InterruptibleThread::EntryPoint
|
|
||||||
{
|
|
||||||
public:
|
|
||||||
TimerSingleton ()
|
|
||||||
: SharedSingleton <OncePerSecond::TimerSingleton> (
|
|
||||||
SingletonLifetime::persistAfterCreation)
|
|
||||||
, m_thread ("Once Per Second")
|
|
||||||
{
|
|
||||||
m_thread.start (this);
|
|
||||||
}
|
|
||||||
|
|
||||||
~TimerSingleton ()
|
|
||||||
{
|
|
||||||
m_thread.join ();
|
|
||||||
|
|
||||||
bassert (m_list.empty ());
|
|
||||||
}
|
|
||||||
|
|
||||||
void threadRun ()
|
|
||||||
{
|
|
||||||
for (;;)
|
|
||||||
{
|
|
||||||
bool const interrupted = m_thread.wait (1000);
|
|
||||||
|
|
||||||
if (interrupted)
|
|
||||||
break;
|
|
||||||
|
|
||||||
notify ();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void notify ()
|
|
||||||
{
|
|
||||||
CriticalSection::ScopedLockType lock (m_mutex);
|
|
||||||
|
|
||||||
for (List <Elem>::iterator iter = m_list.begin (); iter != m_list.end ();)
|
|
||||||
{
|
|
||||||
OncePerSecond* object = iter->object;
|
|
||||||
++iter;
|
|
||||||
object->doOncePerSecond ();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public:
|
|
||||||
void insert (Elem* elem)
|
|
||||||
{
|
|
||||||
CriticalSection::ScopedLockType lock (m_mutex);
|
|
||||||
|
|
||||||
m_list.push_back (*elem);
|
|
||||||
}
|
|
||||||
|
|
||||||
void remove (Elem* elem)
|
|
||||||
{
|
|
||||||
CriticalSection::ScopedLockType lock (m_mutex);
|
|
||||||
|
|
||||||
m_list.erase (m_list.iterator_to (*elem));
|
|
||||||
}
|
|
||||||
|
|
||||||
static TimerSingleton* createInstance ()
|
|
||||||
{
|
|
||||||
return new TimerSingleton;
|
|
||||||
}
|
|
||||||
|
|
||||||
private:
|
|
||||||
InterruptibleThread m_thread;
|
|
||||||
CriticalSection m_mutex;
|
|
||||||
List <Elem> m_list;
|
|
||||||
};
|
|
||||||
|
|
||||||
//------------------------------------------------------------------------------
|
|
||||||
|
|
||||||
OncePerSecond::OncePerSecond ()
|
|
||||||
{
|
|
||||||
m_elem.instance = TimerSingleton::getInstance ();
|
|
||||||
m_elem.object = this;
|
|
||||||
}
|
|
||||||
|
|
||||||
OncePerSecond::~OncePerSecond ()
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
void OncePerSecond::startOncePerSecond ()
|
|
||||||
{
|
|
||||||
m_elem.instance->insert (&m_elem);
|
|
||||||
}
|
|
||||||
|
|
||||||
void OncePerSecond::endOncePerSecond ()
|
|
||||||
{
|
|
||||||
m_elem.instance->remove (&m_elem);
|
|
||||||
}
|
|
||||||
@@ -1,62 +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_ONCEPERSECOND_H_INCLUDED
|
|
||||||
#define BEAST_ONCEPERSECOND_H_INCLUDED
|
|
||||||
|
|
||||||
/*============================================================================*/
|
|
||||||
/**
|
|
||||||
Provides a once per second notification.
|
|
||||||
|
|
||||||
Derive your class from OncePerSecond and override doOncePerSecond(). Then,
|
|
||||||
call startOncePerSecond() to begin receiving the notifications. No clean-up
|
|
||||||
or other actions are required.
|
|
||||||
|
|
||||||
@ingroup beast_core
|
|
||||||
*/
|
|
||||||
class BEAST_API OncePerSecond : public Uncopyable
|
|
||||||
{
|
|
||||||
public:
|
|
||||||
OncePerSecond ();
|
|
||||||
virtual ~OncePerSecond ();
|
|
||||||
|
|
||||||
/** Begin receiving notifications. */
|
|
||||||
void startOncePerSecond ();
|
|
||||||
|
|
||||||
/** Stop receiving notifications. */
|
|
||||||
void endOncePerSecond ();
|
|
||||||
|
|
||||||
protected:
|
|
||||||
/** Called once per second. */
|
|
||||||
virtual void doOncePerSecond () = 0;
|
|
||||||
|
|
||||||
private:
|
|
||||||
class TimerSingleton;
|
|
||||||
typedef SharedPtr <TimerSingleton> TimerPtr;
|
|
||||||
|
|
||||||
struct Elem : List <Elem>::Node
|
|
||||||
{
|
|
||||||
TimerPtr instance;
|
|
||||||
OncePerSecond* object;
|
|
||||||
};
|
|
||||||
|
|
||||||
Elem m_elem;
|
|
||||||
};
|
|
||||||
|
|
||||||
#endif
|
|
||||||
@@ -1,63 +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.
|
|
||||||
*/
|
|
||||||
//==============================================================================
|
|
||||||
|
|
||||||
ParallelFor::ParallelFor (ThreadGroup& pool)
|
|
||||||
: m_pool (pool)
|
|
||||||
, m_finishedEvent (false) // auto-reset
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
int ParallelFor::getNumberOfThreads () const
|
|
||||||
{
|
|
||||||
return m_pool.getNumberOfThreads ();
|
|
||||||
}
|
|
||||||
|
|
||||||
void ParallelFor::doLoop (int numberOfIterations, Iteration& iteration)
|
|
||||||
{
|
|
||||||
if (numberOfIterations > 1)
|
|
||||||
{
|
|
||||||
int const numberOfThreads = m_pool.getNumberOfThreads ();
|
|
||||||
|
|
||||||
// The largest number of pool threads we need is one less than the number
|
|
||||||
// of iterations, because we also run the loop body on the caller's thread.
|
|
||||||
//
|
|
||||||
int const maxThreads = numberOfIterations - 1;
|
|
||||||
|
|
||||||
// Calculate the number of parallel instances as the smaller of the number
|
|
||||||
// of threads available (including the caller's) and the number of iterations.
|
|
||||||
//
|
|
||||||
int const numberOfParallelInstances = std::min (
|
|
||||||
numberOfThreads + 1, numberOfIterations);
|
|
||||||
|
|
||||||
LoopState* loopState (new (m_pool.getAllocator ()) LoopState (
|
|
||||||
iteration, m_finishedEvent, numberOfIterations, numberOfParallelInstances));
|
|
||||||
|
|
||||||
m_pool.call (maxThreads, &LoopState::forLoopBody, loopState);
|
|
||||||
|
|
||||||
// Also use the caller's thread to run the loop body.
|
|
||||||
loopState->forLoopBody ();
|
|
||||||
|
|
||||||
m_finishedEvent.wait ();
|
|
||||||
}
|
|
||||||
else if (numberOfIterations == 1)
|
|
||||||
{
|
|
||||||
// Just one iteration, so do it.
|
|
||||||
iteration (0);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,250 +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_PARALLELFOR_H_INCLUDED
|
|
||||||
#define BEAST_PARALLELFOR_H_INCLUDED
|
|
||||||
|
|
||||||
/*============================================================================*/
|
|
||||||
/**
|
|
||||||
Parallel for loop.
|
|
||||||
|
|
||||||
This uses a ThreadGroup to iterate through a for loop in parallel. The
|
|
||||||
following two pieces of code perform identical operations:
|
|
||||||
|
|
||||||
@code
|
|
||||||
|
|
||||||
extern void function (int loopIndex);
|
|
||||||
|
|
||||||
// Serial computation
|
|
||||||
//
|
|
||||||
for (int i = 0; i < numberOfIterations; ++i)
|
|
||||||
function (i);
|
|
||||||
|
|
||||||
// Parallel computation
|
|
||||||
//
|
|
||||||
ParallelFor().loop (numberOfIterations, &function);
|
|
||||||
|
|
||||||
@endcode
|
|
||||||
|
|
||||||
`function` is a caller provided functor. Convenience functions are provided
|
|
||||||
for automatic binding to member or non member functions with up to 8
|
|
||||||
arguments (not including the loop index).
|
|
||||||
|
|
||||||
@note The last argument to function () is always the loop index.
|
|
||||||
|
|
||||||
@see ThreadGroup
|
|
||||||
|
|
||||||
@ingroup beast_concurrent
|
|
||||||
*/
|
|
||||||
class BEAST_API ParallelFor : public Uncopyable
|
|
||||||
{
|
|
||||||
public:
|
|
||||||
/** Create a parallel for loop.
|
|
||||||
|
|
||||||
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.
|
|
||||||
*/
|
|
||||||
explicit ParallelFor (ThreadGroup& pool);
|
|
||||||
|
|
||||||
/** Determine the number of threads in the group.
|
|
||||||
|
|
||||||
@return The number of threads in the group.
|
|
||||||
*/
|
|
||||||
int getNumberOfThreads () const;
|
|
||||||
|
|
||||||
/** Execute parallel for loop.
|
|
||||||
|
|
||||||
Functor is called once for each value in the range
|
|
||||||
[0, numberOfIterations), using the ThreadGroup.
|
|
||||||
|
|
||||||
@param numberOfIterations The number of times to loop.
|
|
||||||
|
|
||||||
@param f The functor to call for each loop index.
|
|
||||||
*/
|
|
||||||
/** @{ */
|
|
||||||
template <class Functor>
|
|
||||||
void loopf (int numberOfIterations, Functor const& f)
|
|
||||||
{
|
|
||||||
IterationType <Functor> iteration (f);
|
|
||||||
|
|
||||||
doLoop (numberOfIterations, iteration);
|
|
||||||
}
|
|
||||||
|
|
||||||
#if BEAST_VARIADIC_MAX >= 1
|
|
||||||
template <class Fn>
|
|
||||||
void loop (int n, Fn f)
|
|
||||||
{ loopf (n, functional::bind (f, placeholders::_1)); }
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#if BEAST_VARIADIC_MAX >= 2
|
|
||||||
template <class Fn, class T1>
|
|
||||||
void loop (int n, Fn f, T1 t1)
|
|
||||||
{ loopf (n, functional::bind (f, t1, placeholders::_1)); }
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#if BEAST_VARIADIC_MAX >= 3
|
|
||||||
template <class Fn, class T1, class T2>
|
|
||||||
void loop (int n, Fn f, T1 t1, T2 t2)
|
|
||||||
{ loopf (n, functional::bind (f, t1, t2, placeholders::_1)); }
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#if BEAST_VARIADIC_MAX >= 4
|
|
||||||
template <class Fn, class T1, class T2, class T3>
|
|
||||||
void loop (int n, Fn f, T1 t1, T2 t2, T3 t3)
|
|
||||||
{ loopf (n, functional::bind (f, t1, t2, t3, placeholders::_1)); }
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#if BEAST_VARIADIC_MAX >= 5
|
|
||||||
template <class Fn, class T1, class T2, class T3, class T4>
|
|
||||||
void loop (int n, Fn f, T1 t1, T2 t2, T3 t3, T4 t4)
|
|
||||||
{ loopf (n, functional::bind (f, t1, t2, t3, t4, placeholders::_1)); }
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#if BEAST_VARIADIC_MAX >= 6
|
|
||||||
template <class Fn, class T1, class T2, class T3, class T4, class T5>
|
|
||||||
void loop (int n, Fn f, T1 t1, T2 t2, T3 t3, T4 t4, T5 t5)
|
|
||||||
{ loopf (n, functional::bind (f, t1, t2, t3, t4, t5, placeholders::_1)); }
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#if BEAST_VARIADIC_MAX >= 7
|
|
||||||
template <class Fn, class T1, class T2, class T3, class T4, class T5, class T6>
|
|
||||||
void loop (int n, Fn f, T1 t1, T2 t2, T3 t3, T4 t4, T5 t5, T6 t6)
|
|
||||||
{ loopf (n, functional::bind (f, t1, t2, t3, t4, t5, t6, placeholders::_1)); }
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#if BEAST_VARIADIC_MAX >= 8
|
|
||||||
template <class Fn, class T1, class T2, class T3, class T4, class T5, class T6, class T7>
|
|
||||||
void loop (int n, Fn f, T1 t1, T2 t2, T3 t3, T4 t4, T5 t5, T6 t6, T7 t7)
|
|
||||||
{ loopf (n, functional::bind (f, t1, t2, t3, t4, t5, t6, t7, placeholders::_1)); }
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#if BEAST_VARIADIC_MAX >= 9
|
|
||||||
template <class Fn, class T1, class T2, class T3, class T4, class T5, class T6, class T7, class T8>
|
|
||||||
void loop (int n, Fn f, T1 t1, T2 t2, T3 t3, T4 t4, T5 t5, T6 t6, T7 t7, T8 t8)
|
|
||||||
{ loopf (n, functional::bind (f, t1, t2, t3, t4, t5, t6, t7, t8, placeholders::_1)); }
|
|
||||||
#endif
|
|
||||||
/** @} */
|
|
||||||
|
|
||||||
private:
|
|
||||||
class Iteration
|
|
||||||
{
|
|
||||||
public:
|
|
||||||
virtual ~Iteration () { }
|
|
||||||
virtual void operator () (int loopIndex) = 0;
|
|
||||||
};
|
|
||||||
|
|
||||||
template <class Functor>
|
|
||||||
class IterationType : public Iteration, public Uncopyable
|
|
||||||
{
|
|
||||||
public:
|
|
||||||
explicit IterationType (Functor const& f) : m_f (f)
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
void operator () (int loopIndex)
|
|
||||||
{
|
|
||||||
m_f (loopIndex);
|
|
||||||
}
|
|
||||||
|
|
||||||
private:
|
|
||||||
Functor m_f;
|
|
||||||
};
|
|
||||||
|
|
||||||
private:
|
|
||||||
class LoopState
|
|
||||||
: public AllocatedBy <ThreadGroup::AllocatorType>
|
|
||||||
, public Uncopyable
|
|
||||||
{
|
|
||||||
private:
|
|
||||||
Iteration& m_iteration;
|
|
||||||
WaitableEvent& m_finishedEvent;
|
|
||||||
int const m_numberOfIterations;
|
|
||||||
Atomic <int> m_loopIndex;
|
|
||||||
Atomic <int> m_iterationsRemaining;
|
|
||||||
Atomic <int> m_numberOfParallelInstances;
|
|
||||||
|
|
||||||
public:
|
|
||||||
LoopState (Iteration& iteration,
|
|
||||||
WaitableEvent& finishedEvent,
|
|
||||||
int numberOfIterations,
|
|
||||||
int numberOfParallelInstances)
|
|
||||||
: m_iteration (iteration)
|
|
||||||
, m_finishedEvent (finishedEvent)
|
|
||||||
, m_numberOfIterations (numberOfIterations)
|
|
||||||
, m_loopIndex (-1)
|
|
||||||
, m_iterationsRemaining (numberOfIterations)
|
|
||||||
, m_numberOfParallelInstances (numberOfParallelInstances)
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
~LoopState ()
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
void forLoopBody ()
|
|
||||||
{
|
|
||||||
for (;;)
|
|
||||||
{
|
|
||||||
// Request a loop index to process.
|
|
||||||
int const loopIndex = ++m_loopIndex;
|
|
||||||
|
|
||||||
// Is it in range?
|
|
||||||
if (loopIndex < m_numberOfIterations)
|
|
||||||
{
|
|
||||||
// Yes, so process it.
|
|
||||||
m_iteration (loopIndex);
|
|
||||||
|
|
||||||
// Was this the last work item to complete?
|
|
||||||
if (--m_iterationsRemaining == 0)
|
|
||||||
{
|
|
||||||
// Yes, signal.
|
|
||||||
m_finishedEvent.signal ();
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
// Out of range, all work is complete or assigned.
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
release ();
|
|
||||||
}
|
|
||||||
|
|
||||||
void release ()
|
|
||||||
{
|
|
||||||
if (--m_numberOfParallelInstances == 0)
|
|
||||||
delete this;
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
private:
|
|
||||||
void doLoop (int numberOfIterations, Iteration& iteration);
|
|
||||||
|
|
||||||
private:
|
|
||||||
ThreadGroup& m_pool;
|
|
||||||
WaitableEvent m_finishedEvent;
|
|
||||||
Atomic <int> m_currentIndex;
|
|
||||||
Atomic <int> m_numberOfInstances;
|
|
||||||
};
|
|
||||||
|
|
||||||
#endif
|
|
||||||
@@ -1,71 +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_SERIALFOR_H_INCLUDED
|
|
||||||
#define BEAST_SERIALFOR_H_INCLUDED
|
|
||||||
|
|
||||||
/*============================================================================*/
|
|
||||||
|
|
||||||
/** Serial for loop.
|
|
||||||
|
|
||||||
Iterates a for loop sequentially. This is a drop in replacement for
|
|
||||||
ParallelFor.
|
|
||||||
|
|
||||||
@see ParallelFor
|
|
||||||
|
|
||||||
@ingroup beast_core
|
|
||||||
*/
|
|
||||||
class BEAST_API SerialFor : public Uncopyable
|
|
||||||
{
|
|
||||||
public:
|
|
||||||
/** Create a serial for loop.
|
|
||||||
*/
|
|
||||||
inline SerialFor ()
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
/** Determine the number of threads used to process loops.
|
|
||||||
|
|
||||||
@return Always 1.
|
|
||||||
*/
|
|
||||||
inline int getNumberOfThreads () const
|
|
||||||
{
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
template <class F>
|
|
||||||
inline void operator () (int numberOfIterations)
|
|
||||||
{
|
|
||||||
F f;
|
|
||||||
|
|
||||||
for (int i = 0; i < numberOfIterations; ++i)
|
|
||||||
f (i);
|
|
||||||
}
|
|
||||||
|
|
||||||
template <class F, class T1>
|
|
||||||
inline void operator () (int numberOfIterations, T1 t1)
|
|
||||||
{
|
|
||||||
F f (t1);
|
|
||||||
|
|
||||||
for (int i = 0; i < numberOfIterations; ++i)
|
|
||||||
f (i);
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
#endif
|
|
||||||
@@ -1,105 +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.
|
|
||||||
*/
|
|
||||||
//==============================================================================
|
|
||||||
|
|
||||||
void ThreadGroup::QuitType::operator () (Worker* worker)
|
|
||||||
{
|
|
||||||
worker->setShouldExit ();
|
|
||||||
}
|
|
||||||
|
|
||||||
//==============================================================================
|
|
||||||
|
|
||||||
ThreadGroup::Worker::Worker (String name, ThreadGroup& group)
|
|
||||||
: Thread (name)
|
|
||||||
, m_group (group)
|
|
||||||
, m_shouldExit (false)
|
|
||||||
{
|
|
||||||
startThread ();
|
|
||||||
}
|
|
||||||
|
|
||||||
ThreadGroup::Worker::~Worker ()
|
|
||||||
{
|
|
||||||
// Make sure the thread is stopped.
|
|
||||||
stopThread (-1);
|
|
||||||
}
|
|
||||||
|
|
||||||
void ThreadGroup::Worker::setShouldExit ()
|
|
||||||
{
|
|
||||||
m_shouldExit = true;
|
|
||||||
}
|
|
||||||
|
|
||||||
void ThreadGroup::Worker::run ()
|
|
||||||
{
|
|
||||||
do
|
|
||||||
{
|
|
||||||
m_group.m_semaphore.wait ();
|
|
||||||
|
|
||||||
Work* work = m_group.m_queue.pop_front ();
|
|
||||||
|
|
||||||
bassert (work != nullptr);
|
|
||||||
|
|
||||||
work->operator () (this);
|
|
||||||
|
|
||||||
delete work;
|
|
||||||
}
|
|
||||||
while (!m_shouldExit);
|
|
||||||
}
|
|
||||||
|
|
||||||
//==============================================================================
|
|
||||||
|
|
||||||
ThreadGroup::ThreadGroup (int numberOfThreads)
|
|
||||||
: m_numberOfThreads (numberOfThreads)
|
|
||||||
, m_semaphore (0)
|
|
||||||
{
|
|
||||||
for (int i = 0; i++ < numberOfThreads; )
|
|
||||||
{
|
|
||||||
String s;
|
|
||||||
s << "ThreadGroup (" << i << ")";
|
|
||||||
|
|
||||||
m_threads.push_front (new Worker (s, *this));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
ThreadGroup::~ThreadGroup ()
|
|
||||||
{
|
|
||||||
// Put one quit item in the queue for each worker to stop.
|
|
||||||
for (int i = 0; i < m_numberOfThreads; ++i)
|
|
||||||
{
|
|
||||||
m_queue.push_front (new (getAllocator ()) QuitType);
|
|
||||||
|
|
||||||
m_semaphore.signal ();
|
|
||||||
}
|
|
||||||
|
|
||||||
for (;;)
|
|
||||||
{
|
|
||||||
Worker* worker = m_threads.pop_front ();
|
|
||||||
|
|
||||||
if (worker != nullptr)
|
|
||||||
delete worker;
|
|
||||||
else
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
// There must not be pending work!
|
|
||||||
bassert (m_queue.pop_front () == nullptr);
|
|
||||||
}
|
|
||||||
|
|
||||||
int ThreadGroup::getNumberOfThreads () const
|
|
||||||
{
|
|
||||||
return m_numberOfThreads;
|
|
||||||
}
|
|
||||||
@@ -1,215 +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_THREADGROUP_H_INCLUDED
|
|
||||||
#define BEAST_THREADGROUP_H_INCLUDED
|
|
||||||
|
|
||||||
/*============================================================================*/
|
|
||||||
/**
|
|
||||||
@ingroup beast_concurrent
|
|
||||||
|
|
||||||
@brief A group of threads for parallelizing tasks.
|
|
||||||
|
|
||||||
@see ParallelFor
|
|
||||||
*/
|
|
||||||
class BEAST_API ThreadGroup
|
|
||||||
{
|
|
||||||
public:
|
|
||||||
typedef FifoFreeStoreType AllocatorType;
|
|
||||||
|
|
||||||
/** Creates the specified number of threads.
|
|
||||||
|
|
||||||
@param numberOfThreads The number of threads in the group. This must be
|
|
||||||
greater than zero. If this parameter is omitted,
|
|
||||||
one thread is created per available CPU.
|
|
||||||
*/
|
|
||||||
explicit ThreadGroup (int numberOfThreads = SystemStats::getNumCpus ());
|
|
||||||
|
|
||||||
~ThreadGroup ();
|
|
||||||
|
|
||||||
/** Allocator access.
|
|
||||||
*/
|
|
||||||
inline AllocatorType& getAllocator ()
|
|
||||||
{
|
|
||||||
return m_allocator;
|
|
||||||
}
|
|
||||||
|
|
||||||
/** Determine the number of threads in the group.
|
|
||||||
|
|
||||||
@return The number of threads in the group.
|
|
||||||
*/
|
|
||||||
int getNumberOfThreads () const;
|
|
||||||
|
|
||||||
/** Calls a functor on multiple threads.
|
|
||||||
|
|
||||||
The specified functor is executed on some or all available threads at once.
|
|
||||||
A call is always guaranteed to execute.
|
|
||||||
|
|
||||||
@param maxThreads The maximum number of threads to use, or -1 for all.
|
|
||||||
|
|
||||||
@param f The functor to call for each thread.
|
|
||||||
*/
|
|
||||||
/** @{ */
|
|
||||||
template <class Functor>
|
|
||||||
void callf (int maxThreads, Functor f)
|
|
||||||
{
|
|
||||||
bassert (maxThreads > 0 || maxThreads == -1);
|
|
||||||
|
|
||||||
int numberOfThreads = getNumberOfThreads ();
|
|
||||||
|
|
||||||
if (maxThreads != -1 && maxThreads < numberOfThreads)
|
|
||||||
numberOfThreads = maxThreads;
|
|
||||||
|
|
||||||
while (numberOfThreads--)
|
|
||||||
{
|
|
||||||
m_queue.push_front (new (getAllocator ()) WorkType <Functor> (f));
|
|
||||||
m_semaphore.signal ();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
#if BEAST_VARIADIC_MAX >= 1
|
|
||||||
template <class Fn>
|
|
||||||
void call (int maxThreads, Fn f)
|
|
||||||
{ callf (maxThreads, functional::bind (f)); }
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#if BEAST_VARIADIC_MAX >= 2
|
|
||||||
template <class Fn, class T1>
|
|
||||||
void call (int maxThreads, Fn f, T1 t1)
|
|
||||||
{ callf (maxThreads, functional::bind (f, t1)); }
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#if BEAST_VARIADIC_MAX >= 3
|
|
||||||
template <class Fn, class T1, class T2>
|
|
||||||
void call (int maxThreads, Fn f, T1 t1, T2 t2)
|
|
||||||
{ callf (maxThreads, functional::bind (f, t1, t2)); }
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#if BEAST_VARIADIC_MAX >= 4
|
|
||||||
template <class Fn, class T1, class T2, class T3>
|
|
||||||
void call (int maxThreads, Fn f, T1 t1, T2 t2, T3 t3)
|
|
||||||
{ callf (maxThreads, functional::bind (f, t1, t2, t3)); }
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#if BEAST_VARIADIC_MAX >= 5
|
|
||||||
template <class Fn, class T1, class T2, class T3, class T4>
|
|
||||||
void call (int maxThreads, Fn f, T1 t1, T2 t2, T3 t3, T4 t4)
|
|
||||||
{ callf (maxThreads, functional::bind (f, t1, t2, t3, t4)); }
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#if BEAST_VARIADIC_MAX >= 6
|
|
||||||
template <class Fn, class T1, class T2, class T3, class T4, class T5>
|
|
||||||
void call (int maxThreads, Fn f, T1 t1, T2 t2, T3 t3, T4 t4, T5 t5)
|
|
||||||
{ callf (maxThreads, functional::bind (f, t1, t2, t3, t4, t5)); }
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#if BEAST_VARIADIC_MAX >= 7
|
|
||||||
template <class Fn, class T1, class T2, class T3, class T4, class T5, class T6>
|
|
||||||
void call (int maxThreads, Fn f, T1 t1, T2 t2, T3 t3, T4 t4, T5 t5, T6 t6)
|
|
||||||
{ callf (maxThreads, functional::bind (f, t1, t2, t3, t4, t5, t6)); }
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#if BEAST_VARIADIC_MAX >= 8
|
|
||||||
template <class Fn, class T1, class T2, class T3, class T4, class T5, class T6, class T7>
|
|
||||||
void call (int maxThreads, Fn f, T1 t1, T2 t2, T3 t3, T4 t4, T5 t5, T6 t6, T7 t7)
|
|
||||||
{ callf (maxThreads, functional::bind (f, t1, t2, t3, t4, t5, t6, t7)); }
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#if BEAST_VARIADIC_MAX >= 9
|
|
||||||
template <class Fn, class T1, class T2, class T3, class T4, class T5, class T6, class T7, class T8>
|
|
||||||
void call (int maxThreads, Fn f, T1 t1, T2 t2, T3 t3, T4 t4, T5 t5, T6 t6, T7 t7, T8 t8)
|
|
||||||
{ callf (maxThreads, functional::bind (f, t1, t2, t3, t4, t5, t6, t7, t8)); }
|
|
||||||
#endif
|
|
||||||
/** @} */
|
|
||||||
|
|
||||||
private:
|
|
||||||
void stopThreads (int numberOfThreadsToStop);
|
|
||||||
|
|
||||||
//============================================================================
|
|
||||||
private:
|
|
||||||
/** A thread in the group.
|
|
||||||
*/
|
|
||||||
class Worker
|
|
||||||
: public LockFreeStack <Worker>::Node
|
|
||||||
, public Thread
|
|
||||||
, LeakChecked <Worker>
|
|
||||||
{
|
|
||||||
public:
|
|
||||||
Worker (String name, ThreadGroup& group);
|
|
||||||
~Worker ();
|
|
||||||
|
|
||||||
void setShouldExit ();
|
|
||||||
|
|
||||||
private:
|
|
||||||
void run ();
|
|
||||||
|
|
||||||
private:
|
|
||||||
ThreadGroup& m_group;
|
|
||||||
bool m_shouldExit;
|
|
||||||
};
|
|
||||||
|
|
||||||
//============================================================================
|
|
||||||
private:
|
|
||||||
/** Abstract work item.
|
|
||||||
*/
|
|
||||||
class Work : public LockFreeStack <Work>::Node
|
|
||||||
, public AllocatedBy <AllocatorType>
|
|
||||||
{
|
|
||||||
public:
|
|
||||||
virtual ~Work () { }
|
|
||||||
|
|
||||||
/* The worker is passed in so we can make it quit later.
|
|
||||||
*/
|
|
||||||
virtual void operator () (Worker* worker) = 0;
|
|
||||||
};
|
|
||||||
|
|
||||||
template <class Functor>
|
|
||||||
class WorkType : public Work, LeakChecked <WorkType <Functor> >
|
|
||||||
{
|
|
||||||
public:
|
|
||||||
explicit WorkType (Functor const& f) : m_f (f) { }
|
|
||||||
~WorkType () { }
|
|
||||||
void operator () (Worker*)
|
|
||||||
{
|
|
||||||
m_f ();
|
|
||||||
}
|
|
||||||
|
|
||||||
private:
|
|
||||||
Functor m_f;
|
|
||||||
};
|
|
||||||
|
|
||||||
/** Used to make a Worker stop
|
|
||||||
*/
|
|
||||||
class QuitType
|
|
||||||
: public Work
|
|
||||||
, LeakChecked <QuitType>
|
|
||||||
{
|
|
||||||
public:
|
|
||||||
void operator () (Worker* worker);
|
|
||||||
};
|
|
||||||
|
|
||||||
private:
|
|
||||||
int const m_numberOfThreads;
|
|
||||||
Semaphore m_semaphore;
|
|
||||||
AllocatorType m_allocator;
|
|
||||||
LockFreeStack <Work> m_queue;
|
|
||||||
LockFreeStack <Worker> m_threads;
|
|
||||||
};
|
|
||||||
|
|
||||||
#endif
|
|
||||||
@@ -436,13 +436,14 @@ public:
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
// VFALCO TODO Is it really necessary to init the dbs in parallel?
|
|
||||||
void initSqliteDbs ()
|
void initSqliteDbs ()
|
||||||
{
|
{
|
||||||
int const count = 4;
|
// VFALCO NOTE DBs are no longer initialized in parallel, since we
|
||||||
|
// dont want unowned threads and because ParallelFor
|
||||||
ThreadGroup threadGroup (count);
|
// is broken.
|
||||||
ParallelFor (threadGroup).loop (count, &ApplicationImp::initSqliteDb, this);
|
//
|
||||||
|
for (int i = 0; i < 4; ++i)
|
||||||
|
initSqliteDb (i);
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifdef SIGINT
|
#ifdef SIGINT
|
||||||
|
|||||||
Reference in New Issue
Block a user