kradio4  r778
ringbuffer.h
Go to the documentation of this file.
1 /***************************************************************************
2  ringbuffer.h - description
3  -------------------
4  begin : Sun March 21 2004
5  copyright : (C) 2004 by Martin Witte
6  email : emw-kradio@nocabal.de
7  ***************************************************************************/
8 
9 /***************************************************************************
10  * *
11  * This program is free software; you can redistribute it and/or modify *
12  * it under the terms of the GNU General Public License as published by *
13  * the Free Software Foundation; either version 2 of the License, or *
14  * (at your option) any later version. *
15  * *
16  ***************************************************************************/
17 
18 #ifndef _KRADIO_RING_BUFFER_H
19 #define _KRADIO_RING_BUFFER_H
20 
21 #ifdef HAVE_CONFIG_H
22 #include <config.h>
23 #endif
24 
25 #include <sys/types.h>
26 #include <kdemacros.h>
27 #include <QtCore/QSemaphore>
28 
29 class KDE_EXPORT RingBuffer
30 {
31 public:
32  RingBuffer(size_t size, bool synchronized = false);
33  ~RingBuffer();
34 
35  bool resize(size_t new_size);
36 
37  size_t addData (const char *src, size_t size);
38  size_t takeData(char *dst, size_t size, bool lock = true);
39 
40  char *getFreeSpace(size_t &size);
41  size_t removeFreeSpace(size_t size);
42 
43  char *getData(size_t &size);
44  size_t removeData(size_t size);
45 
46  size_t getSize() const;
47  size_t getFillSize() const;
48  size_t getFreeSize() const;
49 
50  void clear();
51 
52  void lockTransaction() const;
53  void unlockTransaction() const;
54 
55 protected:
56  void lock() const;
57  void unlock() const;
58 
59  char *m_Buffer;
60  size_t m_Start;
61  size_t m_Size,
62  m_FillSize;
63 
65  mutable QSemaphore m_synchronizer;
66  mutable QSemaphore m_transactionSynchronizer;
67 };
68 
69 #endif
QSemaphore m_transactionSynchronizer
Definition: ringbuffer.h:66
bool m_synchronized
Definition: ringbuffer.h:64
size_t m_Start
Definition: ringbuffer.h:60
char * m_Buffer
Definition: ringbuffer.h:59
size_t m_Size
Definition: ringbuffer.h:61
QSemaphore m_synchronizer
Definition: ringbuffer.h:65