1 chip 1.1 //%/////////////////////////////////////////////////////////////////////////////
2 //
3 // Copyright (c) 2000, 2001, 2002 BMC Software, Hewlett-Packard Company, IBM,
4 // The Open Group, Tivoli Systems
5 //
6 // Permission is hereby granted, free of charge, to any person obtaining a copy
7 // of this software and associated documentation files (the "Software"), to
8 // deal in the Software without restriction, including without limitation the
9 // rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
10 // sell copies of the Software, and to permit persons to whom the Software is
11 // furnished to do so, subject to the following conditions:
12 //
13 // THE ABOVE COPYRIGHT NOTICE AND THIS PERMISSION NOTICE SHALL BE INCLUDED IN
14 // ALL COPIES OR SUBSTANTIAL PORTIONS OF THE SOFTWARE. THE SOFTWARE IS PROVIDED
15 // "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT
16 // LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
17 // PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
18 // HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
19 // ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
21 //
22 chip 1.1 //==============================================================================
23 //
24 // Author: Chip Vincent (cvincent@us.ibm.com)
25 //
26 // Modified By:
27 //
28 //%/////////////////////////////////////////////////////////////////////////////
29
30 #ifndef Pegasus_SafeQueue_h
31 #define Pegasus_SafeQueue_h
32
33 #include <Pegasus/Common/Config.h>
34 #include <Pegasus/Common/Queue.h>
35
36 #include <Pegasus/ProviderManager/MutexLock.h>
37
38 #include <Pegasus/Server/Linkage.h>
39
40 PEGASUS_NAMESPACE_BEGIN
41
42 template<class T>
43 chip 1.1 class PEGASUS_SERVER_LINKAGE SafeQueue
44 {
45 public:
46 SafeQueue(void);
47 virtual ~SafeQueue(void);
48
49 void enqueue(const T & O);
50 T dequeue(void);
51
52 T & front(void);
53 const T & front(void) const;
54
55 T & back(void);
56 const T & back(void) const;
57
58 Uint32 size(void) const;
59
60 protected:
61 mutable Mutex _mutex;
62 Queue<T> _queue;
63
64 chip 1.1 };
65
66 template<class T>
67 SafeQueue<T>::SafeQueue(void)
68 {
69 }
70
71 template<class T>
72 SafeQueue<T>::~SafeQueue(void)
73 {
74 }
75
76 template<class T>
77 void SafeQueue<T>::enqueue(const T & O)
78 {
79 MutexLock lock(_mutex);
80
81 _queue.enqueue(O);
82 }
83
84 template<class T>
85 chip 1.1 T SafeQueue<T>::dequeue(void)
86 {
87 MutexLock lock(_mutex);
88
89 T O = _queue.front();
90
91 _queue.dequeue();
92
93 return(O);
94 }
95
96 template<class T>
97 T & SafeQueue<T>::front(void)
98 {
99 MutexLock lock(_mutex);
100
101 return(_queue.front());
102 }
103
104 template<class T>
105 const T & SafeQueue<T>::front(void) const
106 chip 1.1 {
107 MutexLock lock(_mutex);
108
109 return(_queue.front());
110 }
111
112 template<class T>
113 T & SafeQueue<T>::back(void)
114 {
115 MutexLock lock(_mutex);
116
117 return(_queue.back());
118 }
119
120 template<class T>
121 const T & SafeQueue<T>::back(void) const
122 {
123 MutexLock lock(_mutex);
124
125 return(_queue.back());
126 }
127 chip 1.1
128 template<class T>
129 Uint32 SafeQueue<T>::size(void) const
130 {
131 //MutexLock lock(_mutex);
132
133 return(_queue.size());
134 }
135
136 PEGASUS_NAMESPACE_END
137
138 #endif
|