2
a thread safe ring buffer without dependencies
3
Copyright (C) 1999 Martin Vogt
5
This program is free software; you can redistribute it and/or modify
6
it under the terms of the GNU Library General Public License as published by
7
the Free Software Foundation.
9
For more information look at the file COPYRIGHT in this package
16
#ifndef _SIMPLERINGBUFFER_H
17
#define _SIMPLERINGBUFFER_H
19
#include "../util/abstract/abs_thread.h"
32
Note to parameter minLinBufSize in Constructor:
34
If the fillgrade is sufficient we can delivier at least
35
this amount of bytes with one "fill"
36
(If the fillgrade is not suffficient we can only deliever fillgrade)
37
This values adresses the problem that a ring buffer cannot
38
deliever linear memory the whole time(eg. if you read near the
41
If the requested Buffersize by the device is smaller than
42
this number you can be sure that you get exactly
43
your preferred buffersize. not more not less.(but
44
only if the fillgrade allows this)
50
class SimpleRingBuffer {
55
SimpleRingBuffer(int ringBufferSize, int minLinBufferSize);
56
virtual ~SimpleRingBuffer();
58
// Writer thread can call these:
60
int getWriteArea(char* &ptr,int &size);
61
void forwardWritePtr(int bytes);
62
int waitForSpace(int minSpace);
63
void exitWaitForSpace();
64
void setCanWaitForSpace(int lCanWaitForSpace);
67
// Reader thread these:
69
void forwardReadPtr(int bytes);
70
int getReadArea(char* &ptr,int &size);
71
int waitForData(int minData);
72
void exitWaitForData();
73
void setCanWaitForData(int lCanWaitForData);
74
int getCanWaitForData();
78
void forwardLockPtr(int bytes);
83
int getFillgrade(); // return how much buffer between reader/writer
84
void emptyBuffer(); // frees the space between them
92
// make sure that no one calls getReadArea/getWriteArea
93
void resizeBuffer(int changeSize);
95
void updateCanWrite();
117
abs_thread_mutex_t mut;
118
abs_thread_cond_t dataCond;
119
abs_thread_cond_t spaceCond;
130
// statistic purpose:
134
int lCanWaitForSpace;