diff options
author | Ben Boeckel <MathStuf@gmail.com> | 2009-03-05 19:01:42 -0500 |
---|---|---|
committer | Ben Boeckel <MathStuf@gmail.com> | 2009-03-05 19:01:42 -0500 |
commit | cd57f0ed31eafb184589ce62b5f855994002d650 (patch) | |
tree | 15ea4cf480dd7a3be967b430045e24bb3ce18082 /sigencore | |
parent | 450814b0562b417fbd5db0db606decd0c3fcc977 (diff) | |
download | sigen-cd57f0ed31eafb184589ce62b5f855994002d650.tar.gz sigen-cd57f0ed31eafb184589ce62b5f855994002d650.tar.xz sigen-cd57f0ed31eafb184589ce62b5f855994002d650.zip |
Fix up ActionQueue
Diffstat (limited to 'sigencore')
-rw-r--r-- | sigencore/plugins/arenas/CMakeLists.txt | 1 | ||||
-rw-r--r-- | sigencore/plugins/arenas/atb/ActionQueue.cpp | 49 | ||||
-rw-r--r-- | sigencore/plugins/arenas/atb/ActionQueue.h | 54 |
3 files changed, 62 insertions, 42 deletions
diff --git a/sigencore/plugins/arenas/CMakeLists.txt b/sigencore/plugins/arenas/CMakeLists.txt index 6d43944e..cdb3048e 100644 --- a/sigencore/plugins/arenas/CMakeLists.txt +++ b/sigencore/plugins/arenas/CMakeLists.txt @@ -2,6 +2,7 @@ project(sigenarenas) set(sigenarenas_SRCS SigenArenas.cpp + atb/ActionQueue.cpp standard/TurnArena.cpp ) diff --git a/sigencore/plugins/arenas/atb/ActionQueue.cpp b/sigencore/plugins/arenas/atb/ActionQueue.cpp new file mode 100644 index 00000000..a2eceffa --- /dev/null +++ b/sigencore/plugins/arenas/atb/ActionQueue.cpp @@ -0,0 +1,49 @@ +/* +* Copyright 2008-2009 Ben Boeckel <MathStuf@gmail.com> +* +* This program is free software: you can redistribute it and/or modify +* it under the terms of the GNU General Public License as published by +* the Free Software Foundation, either version 3 of the License, or +* (at your option) any later version. +* +* This program is distributed in the hope that it will be useful, +* but WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +* GNU General Public License for more details. +* +* You should have received a copy of the GNU General Public License along +* with this program. If not, see <http://www.gnu.org/licenses/>. +*/ + +// Header include +#include "ActionQueue.h" + +// Qt includes +#include <QtCore/QReadLocker> +#include <QtCore/QWriteLocker> + +using namespace Sigencore; + +TeamMember::RequestedAction ActionQueue::dequeue() +{ + QWriteLocker locker(&m_mutex); + return m_queue.dequeue(); +} + +void ActionQueue::enqueue(const TeamMember::RequestedAction& action) +{ + QWriteLocker locker(&m_mutex); + m_queue.enqueue(action); +} + +TeamMember::RequestedAction& ActionQueue::head() +{ + QReadLocker locker(&m_mutex); + return m_queue.head(); +} + +bool ActionQueue::isEmpty() +{ + QReadLocker locker(&m_mutex); + return m_queue.isEmpty(); +} diff --git a/sigencore/plugins/arenas/atb/ActionQueue.h b/sigencore/plugins/arenas/atb/ActionQueue.h index fc3a8232..1741795a 100644 --- a/sigencore/plugins/arenas/atb/ActionQueue.h +++ b/sigencore/plugins/arenas/atb/ActionQueue.h @@ -1,5 +1,5 @@ /* - * Copyright 2008 Ben Boeckel <MathStuf@gmail.com> + * Copyright 2008-2009 Ben Boeckel <MathStuf@gmail.com> * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -15,57 +15,27 @@ * with this program. If not, see <http://www.gnu.org/licenses/>. */ -#ifndef SIGBATTLE_ACTIONQUEUE -#define SIGBATTLE_ACTIONQUEUE +#ifndef SIGENARENAS_ACTIONQUEUE +#define SIGENARENAS_ACTIONQUEUE -// Sigbattle includes -#include "Global.h" -#include "TeamMember.h" +// Sigencore includes +#include <sigencore/TeamMember.h> // Qt includes -#include <QtCore/QMutex> -#include <QtCore/QMutexLocker> #include <QtCore/QQueue> +#include <QtCore/QReadWriteLock> -namespace Sigbattle -{ -class SIGBATTLE_EXPORT ActionQueue +class ActionQueue { public: - TeamMember::RequestedAction dequeue(); - void enqueue(const TeamMember::RequestedAction& action); - TeamMember::RequestedAction& head(); + Sigencore::TeamMember::RequestedAction dequeue(); + void enqueue(const Sigencore::TeamMember::RequestedAction& action); + Sigencore::TeamMember::RequestedAction& head(); bool isEmpty(); private: - QQueue<TeamMember::RequestedAction> m_queue; - QMutex m_mutex; + QQueue<Sigencore::TeamMember::RequestedAction> m_queue; + mutable QReadWriteLock m_mutex; }; -inline TeamMember::RequestedAction ActionQueue::dequeue() -{ - QMutexLocker locker(&m_mutex); - return m_queue.dequeue(); -} - -inline void ActionQueue::enqueue(const TeamMember::RequestedAction& action) -{ - QMutexLocker locker(&m_mutex); - m_queue.enqueue(action); -} - -inline TeamMember::RequestedAction& ActionQueue::head() -{ - QMutexLocker locker(&m_mutex); - return m_queue.head(); -} - -inline bool ActionQueue::isEmpty() -{ - QMutexLocker locker(&m_mutex); - return m_queue.isEmpty(); -} - -} - #endif |