Cocoa Port:

- Clean up some #include stuff in ringbuffer.cpp/.h
- Add/fix some comments in ringbuffer.cpp/.h
- Add accessor for _bufferFillSize
This commit is contained in:
rogerman 2012-07-09 22:34:25 +00:00
parent b209420a38
commit 17d3c59485
2 changed files with 12 additions and 4 deletions

View File

@ -17,6 +17,9 @@
#include "ringbuffer.h"
#include <string.h>
#include <libkern/OSAtomic.h>
RingBuffer::RingBuffer(size_t numberElements, size_t newBufferElementSize)
{
@ -124,7 +127,7 @@ size_t RingBuffer::write(const void *__restrict__ srcBuffer, size_t requestedNum
hiBufferAvailable = inputDataSize - inputDataWritePos;
loBufferAvailable = inputDataReadPos;
// Subtract a sample's worth of bytes
// Subtract one element's worth of bytes
if (loBufferAvailable > 0)
{
loBufferAvailable -= 1;
@ -173,6 +176,11 @@ size_t RingBuffer::write(const void *__restrict__ srcBuffer, size_t requestedNum
return requestedNumberBytes;
}
size_t RingBuffer::getBufferFillSize()
{
return (size_t)this->_bufferFillSize;
}
size_t RingBuffer::getAvailableElements()
{
return ((this->_bufferSize - this->_bufferFillSize) / this->_elementSize) - 1;

View File

@ -19,8 +19,7 @@
#define _RINGBUFFER_
#include <stdlib.h>
#include <string.h>
#include <libkern/OSAtomic.h>
#include <stdint.h>
class RingBuffer
@ -31,7 +30,7 @@ private:
size_t _bufferSize;
size_t _numElements;
size_t _elementSize;
int32_t _bufferFillSize;
int32_t _bufferFillSize; // need to use int32_t for OSAtomicAdd32Barrier()
size_t _readPosition;
size_t _writePosition;
@ -42,6 +41,7 @@ public:
void clear();
size_t read(void *__restrict__ destBuffer, size_t requestedNumberBytes);
size_t write(const void *__restrict__ srcBuffer, size_t requestedNumberBytes);
size_t getBufferFillSize();
size_t getAvailableElements();
size_t getElementSize();
};