summaryrefslogtreecommitdiffstats
blob: 0f7d094aa5372e3f19c87fccde08b504752a3178 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
#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 (); 
    }
  };

  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