summaryrefslogtreecommitdiffstats
path: root/raul/SRSWQueue.hpp
diff options
context:
space:
mode:
authorDavid Robillard <d@drobilla.net>2013-01-11 03:35:17 +0000
committerDavid Robillard <d@drobilla.net>2013-01-11 03:35:17 +0000
commitf8aa3ee7621758b35ba52a5b17972fa4144710ae (patch)
tree2bf934c558b5c97f858be03101fa1544ecf6835d /raul/SRSWQueue.hpp
parent77d36f84343baa0864e742834be15c0296dc4389 (diff)
downloadraul-f8aa3ee7621758b35ba52a5b17972fa4144710ae.tar.gz
raul-f8aa3ee7621758b35ba52a5b17972fa4144710ae.tar.bz2
raul-f8aa3ee7621758b35ba52a5b17972fa4144710ae.zip
Use C++11 atomics.
git-svn-id: http://svn.drobilla.net/lad/trunk/raul@4916 a436a847-0d15-0410-975c-d299462d15a1
Diffstat (limited to 'raul/SRSWQueue.hpp')
-rw-r--r--raul/SRSWQueue.hpp18
1 files changed, 9 insertions, 9 deletions
diff --git a/raul/SRSWQueue.hpp b/raul/SRSWQueue.hpp
index 409497b..b9554a6 100644
--- a/raul/SRSWQueue.hpp
+++ b/raul/SRSWQueue.hpp
@@ -17,9 +17,9 @@
#ifndef RAUL_SRSW_QUEUE_HPP
#define RAUL_SRSW_QUEUE_HPP
+#include <atomic>
#include <cassert>
-#include "raul/AtomicInt.hpp"
#include "raul/Noncopyable.hpp"
namespace Raul {
@@ -60,9 +60,9 @@ public:
inline void pop();
private:
- AtomicInt _front; ///< Index to front of queue (circular)
- AtomicInt _back; ///< Index to back of queue (one past last element) (circular)
- const size_t _size; ///< Size of @ref _objects (you can store _size-1 objects)
+ std::atomic<size_t> _front; ///< Index to front of queue (circular)
+ std::atomic<size_t> _back; ///< Index to back of queue (one past last element) (circular)
+ const size_t _size; ///< Size of @ref _objects (you can store _size-1 objects)
T* const _objects; ///< Fixed array containing queued elements
};
@@ -88,7 +88,7 @@ template <typename T>
inline bool
SRSWQueue<T>::empty() const
{
- return (_back.get() == _front.get());
+ return (_back.load() == _front.load());
}
/** Return whether or not the queue is full.
@@ -97,7 +97,7 @@ template <typename T>
inline bool
SRSWQueue<T>::full() const
{
- return (((_front.get() - _back.get() + _size) % _size) == 1);
+ return (((_front.load() - _back.load() + _size) % _size) == 1);
}
/** Return the element at the front of the queue without removing it
@@ -106,7 +106,7 @@ template <typename T>
inline T&
SRSWQueue<T>::front() const
{
- return _objects[_front.get()];
+ return _objects[_front.load()];
}
/** Push an item onto the back of the SRSWQueue - realtime-safe, not thread-safe.
@@ -121,7 +121,7 @@ SRSWQueue<T>::push(const T& elem)
if (full()) {
return false;
} else {
- unsigned back = _back.get();
+ unsigned back = _back.load();
_objects[back] = elem;
_back = (back + 1) % _size;
return true;
@@ -141,7 +141,7 @@ SRSWQueue<T>::pop()
assert(!empty());
assert(_size > 0);
- _front = (_front.get() + 1) % (_size);
+ _front = (_front.load() + 1) % (_size);
}
} // namespace Raul