Initial release
This commit is contained in:
@@ -0,0 +1,104 @@
|
||||
//------------------------------------------------------------------------
|
||||
// Project : SDK Base
|
||||
// Version : 1.0
|
||||
//
|
||||
// Category : Helpers
|
||||
// Filename : base/thread/include/fcondition.h
|
||||
// Created by : Steinberg, 1995
|
||||
// Description : the threads and locks and signals...
|
||||
//
|
||||
//-----------------------------------------------------------------------------
|
||||
// This file is part of a Steinberg SDK. It is subject to the license terms
|
||||
// in the LICENSE file found in the top-level directory of this distribution
|
||||
// and at www.steinberg.net/sdklicenses.
|
||||
// No part of the SDK, including this file, may be copied, modified, propagated,
|
||||
// or distributed except according to the terms contained in the LICENSE file.
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
//----------------------------------------------------------------------------------
|
||||
/** @file base/thread/include/fcondition.h
|
||||
signal. */
|
||||
/** @defgroup baseThread Thread Handling */
|
||||
//----------------------------------------------------------------------------------
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "pluginterfaces/base/ftypes.h"
|
||||
|
||||
#if SMTG_PTHREADS
|
||||
#include <pthread.h>
|
||||
#endif
|
||||
|
||||
//------------------------------------------------------------------------
|
||||
namespace Steinberg {
|
||||
namespace Base {
|
||||
namespace Thread {
|
||||
|
||||
//------------------------------------------------------------------------
|
||||
/** FCondition - wraps the signal and wait calls in win32
|
||||
@ingroup baseThread */
|
||||
//------------------------------------------------------------------------
|
||||
class FCondition
|
||||
{
|
||||
public:
|
||||
//------------------------------------------------------------------------
|
||||
|
||||
/** Condition constructor.
|
||||
* @param name name of condition
|
||||
*/
|
||||
FCondition (const char8* name = nullptr /* "FCondition" */ );
|
||||
|
||||
/** Condition destructor.
|
||||
*/
|
||||
~FCondition ();
|
||||
|
||||
/** Signals one thread.
|
||||
*/
|
||||
void signal ();
|
||||
|
||||
/** Signals all threads.
|
||||
*/
|
||||
void signalAll ();
|
||||
|
||||
/** Waits for condition.
|
||||
*/
|
||||
void wait ();
|
||||
|
||||
/** Waits for condition with timeout
|
||||
* @param timeout time out in milliseconds
|
||||
* @return false if timed out
|
||||
*/
|
||||
bool waitTimeout (int32 timeout = -1);
|
||||
|
||||
/** Resets condition.
|
||||
*/
|
||||
void reset ();
|
||||
|
||||
#if SMTG_OS_WINDOWS
|
||||
/** Gets condition handle.
|
||||
* @return handle
|
||||
*/
|
||||
void* getHandle () { return event; }
|
||||
#endif
|
||||
|
||||
//------------------------------------------------------------------------
|
||||
private:
|
||||
#if SMTG_PTHREADS
|
||||
pthread_mutex_t mutex; ///< Mutex object
|
||||
pthread_cond_t cond; ///< Condition object
|
||||
int32 state; ///< Use to hold the state of the signal
|
||||
int32 waiters; ///< Number of waiters
|
||||
|
||||
#if DEVELOPMENT
|
||||
int32 waits; ///< Waits count
|
||||
int32 signalCount; ///< Signals count
|
||||
#endif
|
||||
#elif SMTG_OS_WINDOWS
|
||||
void* event; ///< Event handle
|
||||
#endif
|
||||
};
|
||||
|
||||
//------------------------------------------------------------------------
|
||||
} // namespace Thread
|
||||
} // namespace Base
|
||||
} // namespace Steinberg
|
||||
+165
@@ -0,0 +1,165 @@
|
||||
//------------------------------------------------------------------------
|
||||
// Project : SDK Base
|
||||
// Version : 1.0
|
||||
//
|
||||
// Category : Helpers
|
||||
// Filename : base/thread/include/flock.h
|
||||
// Created by : Steinberg, 1995
|
||||
// Description : locks
|
||||
//
|
||||
//-----------------------------------------------------------------------------
|
||||
// This file is part of a Steinberg SDK. It is subject to the license terms
|
||||
// in the LICENSE file found in the top-level directory of this distribution
|
||||
// and at www.steinberg.net/sdklicenses.
|
||||
// No part of the SDK, including this file, may be copied, modified, propagated,
|
||||
// or distributed except according to the terms contained in the LICENSE file.
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
//----------------------------------------------------------------------------------
|
||||
/** @file base/thread/include/flock.h
|
||||
Locks. */
|
||||
/** @defgroup baseLocks Locks */
|
||||
//----------------------------------------------------------------------------------
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "base/source/fobject.h"
|
||||
#include "pluginterfaces/base/ftypes.h"
|
||||
|
||||
#if SMTG_PTHREADS
|
||||
#include <pthread.h>
|
||||
|
||||
#elif SMTG_OS_WINDOWS
|
||||
struct CRITSECT // CRITICAL_SECTION
|
||||
{
|
||||
void* DebugInfo; // PRTL_CRITICAL_SECTION_DEBUG DebugInfo;
|
||||
Steinberg::int32 LockCount; // LONG LockCount;
|
||||
Steinberg::int32 RecursionCount; // LONG RecursionCount;
|
||||
void* OwningThread; // HANDLE OwningThread
|
||||
void* LockSemaphore; // HANDLE LockSemaphore
|
||||
Steinberg::int32 SpinCount; // ULONG_PTR SpinCount
|
||||
};
|
||||
#endif
|
||||
|
||||
namespace Steinberg {
|
||||
namespace Base {
|
||||
namespace Thread {
|
||||
|
||||
//------------------------------------------------------------------------
|
||||
/** Lock interface declaration.
|
||||
@ingroup baseLocks */
|
||||
//------------------------------------------------------------------------
|
||||
struct ILock
|
||||
{
|
||||
//------------------------------------------------------------------------
|
||||
virtual ~ILock () {}
|
||||
|
||||
/** Enables lock. */
|
||||
virtual void lock () = 0;
|
||||
|
||||
/** Disables lock. */
|
||||
virtual void unlock () = 0;
|
||||
|
||||
/** Tries to disable lock. */
|
||||
virtual bool trylock () = 0;
|
||||
//------------------------------------------------------------------------
|
||||
};
|
||||
|
||||
//------------------------------------------------------------------------
|
||||
/** FLock declaration.
|
||||
@ingroup baseLocks */
|
||||
//------------------------------------------------------------------------
|
||||
class FLock : public ILock
|
||||
{
|
||||
public:
|
||||
//------------------------------------------------------------------------
|
||||
|
||||
/** Lock constructor.
|
||||
* @param name lock name
|
||||
*/
|
||||
FLock (const char8* name = "FLock");
|
||||
|
||||
/** Lock destructor. */
|
||||
~FLock () SMTG_OVERRIDE;
|
||||
|
||||
//-- ILock -----------------------------------------------------------
|
||||
void lock () SMTG_OVERRIDE;
|
||||
void unlock () SMTG_OVERRIDE;
|
||||
bool trylock () SMTG_OVERRIDE;
|
||||
|
||||
//------------------------------------------------------------------------
|
||||
protected:
|
||||
#if SMTG_PTHREADS
|
||||
pthread_mutex_t mutex; ///< Mutex object
|
||||
|
||||
#elif SMTG_OS_WINDOWS
|
||||
CRITSECT section; ///< Critical section object
|
||||
#endif
|
||||
};
|
||||
|
||||
//------------------------------------------------------------------------
|
||||
/** FLockObj declaration. Reference counted lock
|
||||
@ingroup baseLocks */
|
||||
//------------------------------------------------------------------------
|
||||
class FLockObject : public FObject, public FLock
|
||||
{
|
||||
public:
|
||||
OBJ_METHODS (FLockObject, FObject)
|
||||
};
|
||||
|
||||
//------------------------------------------------------------------------
|
||||
/** FGuard - automatic object for locks.
|
||||
@ingroup baseLocks */
|
||||
//------------------------------------------------------------------------
|
||||
class FGuard
|
||||
{
|
||||
public:
|
||||
//------------------------------------------------------------------------
|
||||
|
||||
/** FGuard constructor.
|
||||
* @param _lock guard this lock
|
||||
*/
|
||||
FGuard (ILock& _lock) : lock (_lock) { lock.lock (); }
|
||||
|
||||
/** FGuard destructor. */
|
||||
~FGuard () { lock.unlock (); }
|
||||
|
||||
//------------------------------------------------------------------------
|
||||
private:
|
||||
ILock& lock; ///< guarded lock
|
||||
};
|
||||
|
||||
//------------------------------------------------------------------------
|
||||
/** Conditional Guard - Locks only if valid lock is passed.
|
||||
@ingroup baseLocks */
|
||||
//------------------------------------------------------------------------
|
||||
class FConditionalGuard
|
||||
{
|
||||
public:
|
||||
//------------------------------------------------------------------------
|
||||
|
||||
/** FConditionGuard constructor.
|
||||
* @param _lock guard this lock
|
||||
*/
|
||||
FConditionalGuard (FLock* _lock) : lock (_lock)
|
||||
{
|
||||
if (lock)
|
||||
lock->lock ();
|
||||
}
|
||||
|
||||
/** FConditionGuard destructor. */
|
||||
~FConditionalGuard ()
|
||||
{
|
||||
if (lock)
|
||||
lock->unlock ();
|
||||
}
|
||||
|
||||
//------------------------------------------------------------------------
|
||||
private:
|
||||
FLock* lock; ///< guarded lock
|
||||
};
|
||||
|
||||
//------------------------------------------------------------------------
|
||||
} // namespace Thread
|
||||
} // namespace Base
|
||||
} // namespace Steinberg
|
||||
Reference in New Issue
Block a user