sipxportlib  Version 3.3
OsReadLock.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 _OsReadLock_h_
13 #define _OsReadLock_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 multiple simultaneous readers within a critical section
30 // This class uses OsRWMutex objects for synchronization.
31 // The constructor for the class automatically blocks until the OsRWMutex
32 // is acquired for reading. Similarly, the destructor automatically releases
33 // the lock. The easiest way to use this object as a guard is to create the
34 // object as a variable on the stack just before the section that needs to
35 // support multiple simultaneous readers. When the OsReadLock object goes out
36 // of scope, the reader lock will be automatically released.
37 // An example of this form of use is shown below.
38 // <p>
39 // <font face="courier">
40 // &nbsp;&nbsp; someMethod() <br>
41 // &nbsp;&nbsp; { <br>
42 // &nbsp;&nbsp;&nbsp;&nbsp;&nbsp; OsReadLock lock(myRWMutex); <br>
43 // <br>
44 // &nbsp;&nbsp;&nbsp;&nbsp;&nbsp; < section allowing multiple
45 // simultaneous readers > <br>
46 // &nbsp;&nbsp; } </font>
47 
49 {
50 /* //////////////////////////// PUBLIC //////////////////////////////////// */
51 public:
52 
53 /* ============================ CREATORS ================================== */
54 
55  OsReadLock(OsRWMutex& rRWMutex)
56  : mrRWMutex(rRWMutex) { rRWMutex.acquireRead(); };
57  //:Constructor
58 
59  virtual
60  ~OsReadLock() { mrRWMutex.releaseRead(); };
61  //:Destructor
62 
63 /* ============================ MANIPULATORS ============================== */
64 
65 /* ============================ ACCESSORS ================================= */
66 
67 /* ============================ INQUIRY =================================== */
68 
69 /* //////////////////////////// PROTECTED ///////////////////////////////// */
70 protected:
71 
72 /* //////////////////////////// PRIVATE /////////////////////////////////// */
73 private:
74  OsRWMutex& mrRWMutex;
75 
76  OsReadLock();
77  //:Default constructor (not implemented for this class)
78 
79  OsReadLock(const OsReadLock& rOsReadLock);
80  //:Copy constructor (not implemented for this class)
81 
82  OsReadLock& operator=(const OsReadLock& rhs);
83  //:Assignment operator (not implemented for this class)
84 
85 };
86 
87 /* ============================ INLINE METHODS ============================ */
88 
89 #endif // _OsReadLock_h_
Definition: OsReadLock.h:48
OsReadLock(OsRWMutex &rRWMutex)
Definition: OsReadLock.h:55
virtual ~OsReadLock()
Definition: OsReadLock.h:60