2 * Copyright (C) 2009-2010 MaNGOS <http://getmangos.com/>
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; either version 2 of the License, or
7 * (at your option) any later version.
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, write to the Free Software
16 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
22 #include <ace/Guard_T.h>
23 #include <ace/Thread_Mutex.h>
30 template <class T
, class LockType
, typename StorageType
=std::deque
<T
> >
33 //! Lock access to the queue.
36 //! Storage backing the queue.
39 //! Cancellation flag.
40 /*volatile*/ bool _canceled
;
44 //! Create a LockedQueue.
50 //! Destroy a LockedQueue.
51 virtual ~LockedQueue()
55 //! Adds an item to the queue.
56 void add(const T
& item
)
60 //ASSERT(!this->_canceled);
61 // throw Cancellation_Exception();
63 _queue
.push_back(item
);
68 //! Gets the next result in the queue, if any.
71 ACE_Guard
<LockType
> g(this->_lock
);
76 //ASSERT (!_queue.empty() || !this->_canceled);
77 // throw Cancellation_Exception();
79 result
= _queue
.front();
85 //! Peeks at the top of the queue. Remember to unlock after use.
90 T
& result
= _queue
.front();
95 //! Cancels the queue.
105 //! Checks if the queue is cancelled.
108 ACE_Guard
<LockType
> g(this->_lock
);
113 //! Locks the queue for access.
116 this->_lock
.acquire();
119 //! Unlocks the queue.
122 this->_lock
.release();