sipxportlib  Version 3.3
OsRWMutexLinux.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 _OsRWMutexLinux_h_
13 #define _OsRWMutexLinux_h_
14 
15 // SYSTEM INCLUDES
16 #include <pthread.h>
17 #include <assert.h>
18 
19 // APPLICATION INCLUDES
20 #include "os/OsRWMutex.h"
21 
22 // DEFINES
23 // MACROS
24 // EXTERNAL FUNCTIONS
25 // EXTERNAL VARIABLES
26 // CONSTANTS
27 // STRUCTS
28 // TYPEDEFS
29 #ifdef ANDROID // [
30 // Bionic's pthreads implementation does not provide support for RW-locks.
31 // As a first attempt we simply replaced RW-locks with usual mutexes.
32 // I think this way is good way to go, because RW-locks for ARM-based device
33 // is an overkill. But if we discover any problems with this solution, we can
34 // switch to our own RW-locks implementation in sipXportLib/src/shared/OsRWMutexShared.cpp.
35  typedef pthread_mutex_t pthread_rwlock_t;
36 # define pthread_rwlock_init pthread_mutex_init
37 # define pthread_rwlock_destroy pthread_mutex_destroy
38 # define pthread_rwlock_rdlock pthread_mutex_lock
39 # define pthread_rwlock_wrlock pthread_mutex_lock
40 # define pthread_rwlock_tryrdlock pthread_mutex_trylock
41 # define pthread_rwlock_trywrlock pthread_mutex_trylock
42 # define pthread_rwlock_unlock pthread_mutex_unlock
43 #endif // ANDROID ]
44 
45 // FORWARD DECLARATIONS
46 
47 //:Mutual exclusion semaphore handling multiple readers and writers
48 // Two kinds of concurrent tasks, called "readers" and "writers", share a
49 // single resource. The readers can use the resource simultaneously, but each
50 // writer must have exclusive access to it. When a writer is ready to use the
51 // resource, it should be enabled to do so as soon as possible.
53 {
54 /* //////////////////////////// PUBLIC //////////////////////////////////// */
55 public:
56 
58  {
59  Q_FIFO = 0x0, // queue blocked tasks on a first-in, first-out basis
60  Q_PRIORITY = 0x1 // queue blocked tasks based on their priority
61  };
62 
63 /* ============================ CREATORS ================================== */
64 
66  OsRWMutexLinux(const int queueOptions);
67 
70 
71 /* ============================ MANIPULATORS ============================== */
72 
74  //:Block (if necessary) until the task acquires the resource for reading
75  // Multiple simultaneous readers are allowed.
76 
78  //:Block (if necessary) until the task acquires the resource for writing
79  // Only one writer at a time is allowed (and no readers).
80 
82  //:Conditionally acquire the resource for reading (i.e., don't block)
83  // Multiple simultaneous readers are allowed.
84  // Return OS_BUSY if the resource is held for writing by some other task
85 
87  //:Conditionally acquire the resource for writing (i.e., don't block).
88  // Only one writer at a time is allowed (and no readers).
89  // Return OS_BUSY if the resource is held for writing by some other task
90  // or if there are running readers.
91 
93  //:Release the resource for reading
94 
96  //:Release the resource for writing
97 
98 /* ============================ ACCESSORS ================================= */
99 
100 /* ============================ INQUIRY =================================== */
101 
102 /* //////////////////////////// PROTECTED ///////////////////////////////// */
103 protected:
104 
105 /* //////////////////////////// PRIVATE /////////////////////////////////// */
106 private:
107 
108  pthread_rwlock_t mLockImp;
109 
111  OsRWMutexLinux(const OsRWMutexLinux& rhs);
112 
114  OsRWMutexLinux& operator=(const OsRWMutexLinux& rhs);
115 
116 };
117 
118 /* ============================ INLINE METHODS ============================ */
119 
120 #endif // _OsRWMutexLinux_h_
OsRWMutexLinux(const int queueOptions)
Default constructor.
Definition: OsRWMutexLinux.cpp:31
OsStatus tryAcquireRead()
Definition: OsRWMutexLinux.cpp:57
OsStatus acquireWrite()
Definition: OsRWMutexLinux.cpp:52
Definition: OsRWMutexLinux.h:52
OsStatus
Definition: OsStatus.h:27
Definition: OsRWMutexLinux.h:60
OsStatus releaseWrite()
Definition: OsRWMutexLinux.cpp:72
~OsRWMutexLinux()
Destructor.
Definition: OsRWMutexLinux.cpp:38
OsStatus releaseRead()
Definition: OsRWMutexLinux.cpp:67
OsStatus tryAcquireWrite()
Definition: OsRWMutexLinux.cpp:62
QueueOptions
Definition: OsRWMutexLinux.h:57
Definition: OsRWMutexLinux.h:59
OsStatus acquireRead()
Definition: OsRWMutexLinux.cpp:47