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