sipxportlib  Version 3.3
OsWriteLock.h
Go to the documentation of this file.
1 //
2 // Copyright (C) 2004-2006 SIPfoundry Inc.
3 // Licensed by SIPfoundry under the LGPL license.
4 //
5 // Copyright (C) 2004-2006 Pingtel Corp. All rights reserved.
6 // Licensed to SIPfoundry under a Contributor Agreement.
7 //
8 // $$
10 
11 
12 #ifndef _OsWriteLock_h_
13 #define _OsWriteLock_h_
14 
15 // SYSTEM INCLUDES
16 
17 // APPLICATION INCLUDES
18 #include "OsRWMutex.h"
19 
20 // DEFINES
21 // MACROS
22 // EXTERNAL FUNCTIONS
23 // EXTERNAL VARIABLES
24 // CONSTANTS
25 // STRUCTS
26 // TYPEDEFS
27 // FORWARD DECLARATIONS
28 
29 //:Lock class allowing exclusive access for a writer within a critical section
30 // This class uses OsRWMutex objects for synchronization. The constructor
31 // for the class automatically blocks until the OsRWMutex is acquired
32 // for writing. Similarly, the destructor automatically releases the lock.
33 // <p>
34 // The easiest way to use this object as a guard is to create the
35 // object as a variable on the stack just before the section that needs to
36 // lock the resource for writing. When the OsWriteLock object goes out of
37 // scope, the writer lock will be automatically released.
38 // An example of this form of use is shown below.
39 // <p>
40 // <font face="courier">
41 // &nbsp;&nbsp; someMethod() <br>
42 // &nbsp;&nbsp; { <br>
43 // &nbsp;&nbsp;&nbsp;&nbsp;&nbsp; OsWriteLock lock(myRWMutex); <br>
44 // <br>
45 // &nbsp;&nbsp;&nbsp;&nbsp;&nbsp; < section that needs to be
46 // locked for writing > <br>
47 // &nbsp;&nbsp; } </font>
48 
50 {
51 /* //////////////////////////// PUBLIC //////////////////////////////////// */
52 public:
53 
54 /* ============================ CREATORS ================================== */
55 
56  OsWriteLock(OsRWMutex& rRWMutex)
57  : mrRWMutex(rRWMutex) { rRWMutex.acquireWrite(); };
58  //:Constructor
59 
60  virtual
61  ~OsWriteLock() { mrRWMutex.releaseWrite(); };
62  //:Destructor
63 
64 /* ============================ MANIPULATORS ============================== */
65 
66 /* ============================ ACCESSORS ================================= */
67 
68 /* ============================ INQUIRY =================================== */
69 
70 /* //////////////////////////// PROTECTED ///////////////////////////////// */
71 protected:
72 
73 /* //////////////////////////// PRIVATE /////////////////////////////////// */
74 private:
75  OsRWMutex& mrRWMutex;
76 
77  OsWriteLock();
78  //:Default constructor (not implemented for this class)
79 
80  OsWriteLock(const OsWriteLock& rOsWriteLock);
81  //:Copy constructor (not implemented for this class)
82 
83  OsWriteLock& operator=(const OsWriteLock& rhs);
84  //:Assignment operator (not implemented for this class)
85 
86 };
87 
88 /* ============================ INLINE METHODS ============================ */
89 
90 #endif // _OsWriteLock_h_
OsWriteLock(OsRWMutex &rRWMutex)
Definition: OsWriteLock.h:56
virtual ~OsWriteLock()
Definition: OsWriteLock.h:61
Definition: OsWriteLock.h:49