aboutsummaryrefslogtreecommitdiff
path: root/src/Fifo.cpp
diff options
context:
space:
mode:
authorN.N <matju@users.sourceforge.net>2009-12-14 19:55:54 +0000
committerIOhannes m zmölnig <zmoelnig@iem.at>2015-10-14 15:04:53 +0200
commitc235f09fc5ef83827ac53375015f469cd7e13eec (patch)
tree4639e88e27e105709a2bbd6352cec17808fdc5c9 /src/Fifo.cpp
parent40194041a1efbf98c45185098e3795150a0128a4 (diff)
import version 0.36
svn path=/trunk/externals/august/readanysf~/; revision=12836
Diffstat (limited to 'src/Fifo.cpp')
-rw-r--r--src/Fifo.cpp152
1 files changed, 0 insertions, 152 deletions
diff --git a/src/Fifo.cpp b/src/Fifo.cpp
deleted file mode 100644
index c5f0853..0000000
--- a/src/Fifo.cpp
+++ /dev/null
@@ -1,152 +0,0 @@
-#include <stdio.h>
-#include "Fifo.h"
-
-Fifo::Fifo ()
-{
- astate = 0; // not allocated
- buffer = NULL;
- totsize = 0;
- datasize = 0;
- start = 0;
- pthread_mutex_init (&mut, 0);
-}
-
-Fifo::Fifo (unsigned int size)
-{
- buffer = new char[size];
- if (buffer != NULL)
- {
- astate = 1;
- totsize = size;
- datasize = 0;
- start = 0;
- }
- else
- {
- astate = 0;
- totsize = 0;
- datasize = 0;
- start = 0;
- }
- pthread_mutex_init (&mut, 0);
-}
-
-Fifo::~Fifo ()
-{
- pthread_mutex_lock (&mut);
- if (astate)
- delete buffer;
- pthread_mutex_unlock (&mut);
-}
-
-void
-Fifo::Flush ()
-{
- pthread_mutex_lock (&mut);
- astate = 1;
- //totsize = size;
- datasize = 0;
- start = 0;
- pthread_mutex_unlock (&mut);
- //for (int x =0; x < sizeof(buffer); x++) {
- // buffer[x] = 0;
- //}
-}
-
-int
-Fifo::ReAlloc (unsigned int size)
-{
- pthread_mutex_lock (&mut);
- if (astate)
- delete buffer;
- buffer = new char[size];
- if (buffer != NULL)
- {
- astate = 1;
- totsize = size;
- datasize = 0;
- start = 0;
- pthread_mutex_unlock (&mut);
- }
- else
- {
- astate = 0;
- totsize = 0;
- datasize = 0;
- start = 0;
- pthread_mutex_unlock (&mut);
- return -1;
- }
- return 0;
-}
-
-void *
-Fifo::Read (void *buf, unsigned int &len)
-{
- pthread_mutex_lock (&mut);
- if (len > datasize)
- len = datasize;
- unsigned int rest;
- if (len > (totsize - start))
- rest = len - (totsize - start);
- else
- rest = 0;
- unsigned int first = len - rest;
- memcpy (buf, buffer + start, first);
- memcpy ((char *) buf + first, buffer, rest);
- datasize -= len;
- start += len;
- if (start >= totsize)
- start = rest;
- //if (datasize == 0) printf("in fifo READ, data is zero\n");
- pthread_mutex_unlock (&mut);
- return buf;
-}
-
-int
-Fifo::Write (void *buf, unsigned int len)
-{
- pthread_mutex_lock (&mut);
- unsigned int end;
- end = start + datasize;
- if (end > totsize)
- end = end - totsize;
- if (len > (totsize - datasize))
- {
- pthread_mutex_unlock (&mut);
- return -1;
- }
- unsigned int rest;
- if ((len + end) > totsize)
- rest = (len + end) - totsize;
- else
- rest = 0;
- unsigned int first = len - rest;
- memcpy (buffer + end, buf, first);
- memcpy (buffer, (char *) buf + first, rest);
-
- datasize += len;
- //if (datasize == 0) printf("in fifo WRITE, data is zero\n");
- pthread_mutex_unlock (&mut);
- return len;
-}
-
-unsigned int
-Fifo::FreeSpace (void)
-{ // do we need locks here?
- int x;
- pthread_mutex_lock (&mut);
- x = totsize - datasize;
- pthread_mutex_unlock (&mut);
- return x;
-}
-
-unsigned int
-Fifo::UsedSpace (void)
-{
- int x;
- pthread_mutex_lock (&mut);
- x = datasize;
- pthread_mutex_unlock (&mut);
- return x;
-}