summaryrefslogtreecommitdiffstats
path: root/raul/RingBuffer.hpp
diff options
context:
space:
mode:
authorDavid Robillard <d@drobilla.net>2009-05-13 16:04:14 +0000
committerDavid Robillard <d@drobilla.net>2009-05-13 16:04:14 +0000
commitc0d0364c030688aa8bfe4ad8dcaa2cffed8c0d04 (patch)
treec559879d17437adfb1aae4fb5fb40bbe6ac2f983 /raul/RingBuffer.hpp
parentf60b59b49df6bc298755d49e97bc329b6d6030a1 (diff)
downloadraul-c0d0364c030688aa8bfe4ad8dcaa2cffed8c0d04.tar.gz
raul-c0d0364c030688aa8bfe4ad8dcaa2cffed8c0d04.tar.bz2
raul-c0d0364c030688aa8bfe4ad8dcaa2cffed8c0d04.zip
Strip trailing whitespace.
git-svn-id: http://svn.drobilla.net/lad/trunk/raul@1999 a436a847-0d15-0410-975c-d299462d15a1
Diffstat (limited to 'raul/RingBuffer.hpp')
-rw-r--r--raul/RingBuffer.hpp38
1 files changed, 19 insertions, 19 deletions
diff --git a/raul/RingBuffer.hpp b/raul/RingBuffer.hpp
index 6f7dcb3..3cab1ca 100644
--- a/raul/RingBuffer.hpp
+++ b/raul/RingBuffer.hpp
@@ -1,15 +1,15 @@
/* This file is part of Raul.
* Copyright (C) 2007-2008 Dave Robillard <http://drobilla.net>
- *
+ *
* Raul 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 2 of the License, or (at your option) any later
* version.
- *
+ *
* Raul 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 details.
- *
+ *
* You should have received a copy of the GNU General Public License along
* with this program; if not, write to the Free Software Foundation, Inc.,
* 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
@@ -44,7 +44,7 @@ public:
assert(read_space() == 0);
assert(write_space() == size - 1);
}
-
+
virtual ~RingBuffer() {
delete[] _buf;
}
@@ -60,7 +60,7 @@ public:
size_t write_space() const {
const size_t w = g_atomic_int_get(&_write_ptr);
const size_t r = g_atomic_int_get(&_read_ptr);
-
+
if (w > r) {
return ((r - w + _size) % _size) - 1;
} else if (w < r) {
@@ -69,11 +69,11 @@ public:
return _size - 1;
}
}
-
+
size_t read_space() const {
const size_t w = g_atomic_int_get(&_write_ptr);
const size_t r = g_atomic_int_get(&_read_ptr);
-
+
if (w > r) {
return w - r;
} else {
@@ -90,13 +90,13 @@ public:
bool full_read(size_t size, T* dst);
bool skip(size_t size);
-
+
void write(size_t size, const T* src);
protected:
mutable int _write_ptr;
mutable int _read_ptr;
-
+
size_t _size; ///< Size (capacity) in bytes
T* _buf; ///< size, event, size, event...
};
@@ -105,7 +105,7 @@ protected:
/** Peek at the ringbuffer (read w/o advancing read pointer).
*
* Note that a full read may not be done if the data wraps around.
- * Caller must check return value and call again if necessary, or use the
+ * Caller must check return value and call again if necessary, or use the
* full_peek method which does this automatically.
*/
template<typename T>
@@ -117,7 +117,7 @@ RingBuffer<T>::peek(size_t size, T* dst)
const size_t read_size = (priv_read_ptr + size < _size)
? size
: _size - priv_read_ptr;
-
+
memcpy(dst, &_buf[priv_read_ptr], read_size);
return read_size;
@@ -133,7 +133,7 @@ RingBuffer<T>::full_peek(size_t size, T* dst)
}
const size_t read_size = peek(size, dst);
-
+
if (read_size < size) {
peek(size - read_size, dst + read_size);
}
@@ -145,7 +145,7 @@ RingBuffer<T>::full_peek(size_t size, T* dst)
/** Read from the ringbuffer.
*
* Note that a full read may not be done if the data wraps around.
- * Caller must check return value and call again if necessary, or use the
+ * Caller must check return value and call again if necessary, or use the
* full_read method which does this automatically.
*/
template<typename T>
@@ -157,9 +157,9 @@ RingBuffer<T>::read(size_t size, T* dst)
const size_t read_size = (priv_read_ptr + size < _size)
? size
: _size - priv_read_ptr;
-
+
memcpy(dst, &_buf[priv_read_ptr], read_size);
-
+
g_atomic_int_set(&_read_ptr, (priv_read_ptr + read_size) % _size);
return read_size;
@@ -175,7 +175,7 @@ RingBuffer<T>::full_read(size_t size, T* dst)
}
const size_t read_size = read(size, dst);
-
+
if (read_size < size) {
read(size - read_size, dst + read_size);
}
@@ -192,7 +192,7 @@ RingBuffer<T>::skip(size_t size)
std::cerr << "WARNING: Attempt to skip past end of MIDI ring buffer" << std::endl;
return false;
}
-
+
const size_t priv_read_ptr = g_atomic_int_get(&_read_ptr);
g_atomic_int_set(&_read_ptr, (priv_read_ptr + size) % _size);
@@ -205,7 +205,7 @@ inline void
RingBuffer<T>::write(size_t size, const T* src)
{
const size_t priv_write_ptr = g_atomic_int_get(&_write_ptr);
-
+
if (priv_write_ptr + size <= _size) {
memcpy(&_buf[priv_write_ptr], src, size);
g_atomic_int_set(&_write_ptr, (priv_write_ptr + size) % _size);
@@ -219,7 +219,7 @@ RingBuffer<T>::write(size_t size, const T* src)
}
}
-
+
} // namespace Raul
#endif // RAUL_RING_BUFFER_HPP