1
0
Fork 0
flightgear/3rdparty/cppunit/include/cppunit/SynchronizedObject.h
Edward d'Auvergne f4ee276472 TestSuite: Addition of a stripped down version of CppUnit 1.14.0.
This is the version maintained by the freedesktop.org organisation and is
documented at https://www.freedesktop.org/wiki/Software/cppunit/.  All
unnecessary files have been stripped out.
2018-03-23 17:26:05 +01:00

86 lines
1.9 KiB
C++

#ifndef CPPUNIT_SYNCHRONIZEDOBJECT_H
#define CPPUNIT_SYNCHRONIZEDOBJECT_H
#include <cppunit/Portability.h>
CPPUNIT_NS_BEGIN
/*! \brief Base class for synchronized object.
*
* Synchronized object are object which members are used concurrently by mutiple
* threads.
*
* This class define the class SynchronizationObject which must be subclassed
* to implement an actual lock.
*
* Each instance of this class holds a pointer on a lock object.
*
* See src/msvc6/MfcSynchronizedObject.h for an example.
*/
class CPPUNIT_API SynchronizedObject
{
public:
/*! \brief Abstract synchronization object (mutex)
*/
class SynchronizationObject
{
public:
SynchronizationObject() {}
virtual ~SynchronizationObject() {}
virtual void lock() {}
virtual void unlock() {}
};
/*! Constructs a SynchronizedObject object.
*/
SynchronizedObject( SynchronizationObject *syncObject =0 );
/// Destructor.
virtual ~SynchronizedObject();
protected:
/*! \brief Locks a synchronization object in the current scope.
*/
class ExclusiveZone
{
SynchronizationObject *m_syncObject;
public:
ExclusiveZone( SynchronizationObject *syncObject )
: m_syncObject( syncObject )
{
m_syncObject->lock();
}
~ExclusiveZone()
{
m_syncObject->unlock ();
}
private:
/// Prevents the use of the copy constructor.
ExclusiveZone( const ExclusiveZone& );
/// Prevents the use of the copy operator.
ExclusiveZone& operator=( const ExclusiveZone& );
};
virtual void setSynchronizationObject( SynchronizationObject *syncObject );
protected:
SynchronizationObject *m_syncObject;
private:
/// Prevents the use of the copy constructor.
SynchronizedObject( const SynchronizedObject &copy );
/// Prevents the use of the copy operator.
void operator =( const SynchronizedObject &copy );
};
CPPUNIT_NS_END
#endif // CPPUNIT_SYNCHRONIZEDOBJECT_H