samplebrain/brain/src/spiralcore/ring_buffer.h

47 lines
1.4 KiB
C
Raw Normal View History

2016-06-06 11:46:36 -03:00
// copyright (C) 2004 david griffiths <dave@pawfal.org>
//
// 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 2 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, write to the free software
// foundation, inc., 59 temple place - suite 330, boston, MA 02111-1307, USA.
// ringbuffer for processing commands between asycronous threads, either may be
// realtime and non blocking, so all code should be realtime capable
#ifndef RING_BUFFER
#define RING_BUFFER
class ring_buffer
{
public:
ring_buffer(unsigned int size);
~ring_buffer();
2016-06-06 11:46:36 -03:00
//bool lock();
//bool unlock();
bool write(char *src, unsigned int size);
bool read(char *dest, unsigned int size);
void dump();
2016-06-06 11:46:36 -03:00
private:
unsigned int write_space();
unsigned int read_space();
2016-06-06 11:46:36 -03:00
unsigned int m_read_pos;
unsigned int m_write_pos;
unsigned int m_size;
unsigned int m_size_mask;
char *m_buffer;
2016-06-06 11:46:36 -03:00
};
#endif