Move ServiceQueue, ThreadLocalValue, SpinLock

This commit is contained in:
Vinnie Falco
2013-10-04 11:33:32 -07:00
parent 184cf74daa
commit 70f6c41ff7
12 changed files with 82 additions and 32 deletions

View File

@@ -154,10 +154,13 @@
<ClInclude Include="..\..\beast\Thread.h" />
<ClInclude Include="..\..\beast\thread\LockGuard.h" />
<ClInclude Include="..\..\beast\thread\RecursiveMutex.h" />
<ClInclude Include="..\..\beast\thread\ServiceQueue.h" />
<ClInclude Include="..\..\beast\thread\SharedData.h" />
<ClInclude Include="..\..\beast\thread\SharedLockGuard.h" />
<ClInclude Include="..\..\beast\thread\SharedMutexAdapter.h" />
<ClInclude Include="..\..\beast\Chrono.h" />
<ClInclude Include="..\..\beast\thread\SpinLock.h" />
<ClInclude Include="..\..\beast\thread\ThreadLocalValue.h" />
<ClInclude Include="..\..\beast\thread\TryLockGuard.h" />
<ClInclude Include="..\..\beast\thread\UnlockGuard.h" />
<ClInclude Include="..\..\beast\thread\WaitableEvent.h" />
@@ -329,9 +332,7 @@
<ClInclude Include="..\..\modules\beast_core\threads\ScopedReadLock.h" />
<ClInclude Include="..\..\modules\beast_core\threads\ScopedWriteLock.h" />
<ClInclude Include="..\..\modules\beast_core\threads\SpinDelay.h" />
<ClInclude Include="..\..\modules\beast_core\threads\SpinLock.h" />
<ClInclude Include="..\..\modules\beast_core\threads\Thread.h" />
<ClInclude Include="..\..\modules\beast_core\threads\ThreadLocalValue.h" />
<ClInclude Include="..\..\modules\beast_core\threads\ThreadPool.h" />
<ClInclude Include="..\..\modules\beast_core\threads\TimeSliceThread.h" />
<ClInclude Include="..\..\modules\beast_core\thread\DeadlineTimer.h" />
@@ -511,6 +512,12 @@
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">true</ExcludedFromBuild>
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Release|x64'">true</ExcludedFromBuild>
</ClCompile>
<ClCompile Include="..\..\beast\thread\impl\ServiceQueue.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="..\..\beast\thread\impl\WaitableEvent.cpp">
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">true</ExcludedFromBuild>
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">true</ExcludedFromBuild>

View File

@@ -497,15 +497,9 @@
<ClInclude Include="..\..\modules\beast_core\threads\ScopedWriteLock.h">
<Filter>beast_core\threads</Filter>
</ClInclude>
<ClInclude Include="..\..\modules\beast_core\threads\SpinLock.h">
<Filter>beast_core\threads</Filter>
</ClInclude>
<ClInclude Include="..\..\modules\beast_core\threads\Thread.h">
<Filter>beast_core\threads</Filter>
</ClInclude>
<ClInclude Include="..\..\modules\beast_core\threads\ThreadLocalValue.h">
<Filter>beast_core\threads</Filter>
</ClInclude>
<ClInclude Include="..\..\modules\beast_core\threads\ThreadPool.h">
<Filter>beast_core\threads</Filter>
</ClInclude>
@@ -1239,6 +1233,15 @@
<ClInclude Include="..\..\beast\thread\WaitableEvent.h">
<Filter>beast\thread</Filter>
</ClInclude>
<ClInclude Include="..\..\beast\thread\ServiceQueue.h">
<Filter>beast\thread</Filter>
</ClInclude>
<ClInclude Include="..\..\beast\thread\ThreadLocalValue.h">
<Filter>beast\thread</Filter>
</ClInclude>
<ClInclude Include="..\..\beast\thread\SpinLock.h">
<Filter>beast\thread</Filter>
</ClInclude>
</ItemGroup>
<ItemGroup>
<ClCompile Include="..\..\modules\beast_core\containers\AbstractFifo.cpp">
@@ -1790,6 +1793,9 @@
<ClCompile Include="..\..\beast\thread\impl\WaitableEvent.cpp">
<Filter>beast\thread\impl</Filter>
</ClCompile>
<ClCompile Include="..\..\beast\thread\impl\ServiceQueue.cpp">
<Filter>beast\thread\impl</Filter>
</ClCompile>
</ItemGroup>
<ItemGroup>
<Text Include="..\..\TODO.txt">

View File

@@ -26,6 +26,9 @@
#include "thread/SharedLockGuard.h"
#include "thread/SharedMutexAdapter.h"
#include "thread/SharedData.h"
#include "thread/ServiceQueue.h"
#include "thread/SpinLock.h"
#include "thread/ThreadLocalValue.h"
#include "thread/WaitableEvent.h"
#endif

View File

@@ -17,8 +17,14 @@
*/
//==============================================================================
#ifndef BEAST_SERVICEQUEUE_H_INCLUDED
#define BEAST_SERVICEQUEUE_H_INCLUDED
#ifndef BEAST_THREAD_SERVICEQUEUE_H_INCLUDED
#define BEAST_THREAD_SERVICEQUEUE_H_INCLUDED
#include "../intrusive/List.h"
#include "../intrusive/LockFreeStack.h"
#include "SharedData.h"
#include "ThreadLocalValue.h"
#include "WaitableEvent.h"
namespace beast {

View File

@@ -21,8 +21,14 @@
*/
//==============================================================================
#ifndef BEAST_SPINLOCK_H_INCLUDED
#define BEAST_SPINLOCK_H_INCLUDED
#ifndef BEAST_THREAD_SPINLOCK_H_INCLUDED
#define BEAST_THREAD_SPINLOCK_H_INCLUDED
#include "../Atomic.h"
#include "LockGuard.h"
#include "UnlockGuard.h"
namespace beast {
//==============================================================================
/**
@@ -40,6 +46,12 @@
class BEAST_API SpinLock : public Uncopyable
{
public:
/** Provides the type of scoped lock to use for locking a SpinLock. */
typedef LockGuard <SpinLock> ScopedLockType;
/** Provides the type of scoped unlocker to use with a SpinLock. */
typedef UnlockGuard <SpinLock> ScopedUnlockType;
inline SpinLock() noexcept {}
inline ~SpinLock() noexcept {}
@@ -57,27 +69,29 @@ public:
/** Attempts to acquire the lock, returning true if this was successful. */
inline bool tryEnter() const noexcept
{
return lock.compareAndSetBool (1, 0);
return m_lock.compareAndSetBool (1, 0);
}
/** Releases the lock. */
inline void exit() const noexcept
{
bassert (lock.value == 1); // Agh! Releasing a lock that isn't currently held!
lock = 0;
bassert (m_lock.value == 1); // Agh! Releasing a lock that isn't currently held!
m_lock = 0;
}
//==============================================================================
/** Provides the type of scoped lock to use for locking a SpinLock. */
typedef GenericScopedLock <SpinLock> ScopedLockType;
/** Provides the type of scoped unlocker to use with a SpinLock. */
typedef GenericScopedUnlock <SpinLock> ScopedUnlockType;
void lock () const
{ enter(); }
void unlock () const
{ exit(); }
bool try_lock () const
{ return tryEnter(); }
private:
//==============================================================================
mutable Atomic<int> lock;
mutable Atomic<int> m_lock;
};
}
#endif
#endif // BEAST_SPINLOCK_H_INCLUDED

View File

@@ -20,4 +20,5 @@
#include "BeastConfig.h"
#include "impl/RecursiveMutex.cpp"
#include "impl/ServiceQueue.cpp"
#include "impl/WaitableEvent.cpp"

View File

@@ -21,8 +21,12 @@
*/
//==============================================================================
#ifndef BEAST_THREADLOCALVALUE_H_INCLUDED
#define BEAST_THREADLOCALVALUE_H_INCLUDED
#ifndef BEAST_THREAD_THREADLOCALVALUE_H_INCLUDED
#define BEAST_THREAD_THREADLOCALVALUE_H_INCLUDED
#include "../Config.h"
namespace beast {
// (NB: on win32, native thread-locals aren't possible in a dynamically loaded DLL in XP).
#if ! ((BEAST_MSVC && (BEAST_64BIT || ! defined (BeastPlugin_PluginCode))) \
@@ -186,5 +190,6 @@ private:
#endif
};
}
#endif // BEAST_THREADLOCALVALUE_H_INCLUDED
#endif

View File

@@ -28,6 +28,11 @@
#include "../StaticAssert.h"
#include <Windows.h>
#undef check
#undef direct
#undef max
#undef min
#undef TYPE_BOOL
namespace beast {

View File

@@ -17,6 +17,10 @@
*/
//==============================================================================
#include "../ServiceQueue.h"
#include "../../../modules/beast_core/beast_core.h" // for UnitTest
namespace beast {
namespace detail {

View File

@@ -26,6 +26,11 @@
#if BEAST_WINDOWS
#include <Windows.h>
#undef check
#undef direct
#undef max
#undef min
#undef TYPE_BOOL
namespace beast {

View File

@@ -274,8 +274,6 @@ namespace beast
}
#include "thread/ServiceQueue.cpp"
// Has to be outside the beast namespace
extern "C" {
void beast_reportFatalError (char const* message, char const* fileName, int lineNumber)

View File

@@ -149,8 +149,6 @@ class FileOutputStream;
#include "memory/CacheLine.h"
#include "threads/ReadWriteMutex.h"
#include "threads/Thread.h"
#include "threads/SpinLock.h"
#include "threads/ThreadLocalValue.h"
#include "thread/MutexTraits.h"
#include "thread/TrackedMutex.h"
#include "diagnostic/FatalError.h"
@@ -245,8 +243,6 @@ class FileOutputStream;
}
#include "thread/ServiceQueue.h"
#if BEAST_MSVC
#pragma warning (pop)
#endif