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