summaryrefslogtreecommitdiffstats
path: root/k9vamps/k9fifo.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'k9vamps/k9fifo.cpp')
-rw-r--r--k9vamps/k9fifo.cpp54
1 files changed, 54 insertions, 0 deletions
diff --git a/k9vamps/k9fifo.cpp b/k9vamps/k9fifo.cpp
new file mode 100644
index 0000000..7c32de7
--- /dev/null
+++ b/k9vamps/k9fifo.cpp
@@ -0,0 +1,54 @@
+//
+// C++ Implementation: k9fifo
+//
+// Description:
+//
+//
+// Author: Jean-Michel PETIT <k9copy@free.fr>, (C) 2007
+//
+// Copyright: See COPYING file that comes with this distribution
+//
+//
+#include "k9fifo.h"
+#include "ac.h"
+
+uint32_t k9fifo::count() {
+ return m_count;
+}
+
+void k9fifo::enqueue (uchar *_buffer, uint32_t _size) {
+ mutex.lock();
+ if (_size+queue > INPUT_SIZE) {
+ uint32_t s1,s2;
+ s1=INPUT_SIZE-queue;
+ tc_memcpy(array+queue,_buffer,s1);
+ s2=_size-s1;
+ tc_memcpy(array,_buffer+s1,s2);
+ } else
+ tc_memcpy(array+queue,_buffer,_size);
+ queue=(queue+_size) %INPUT_SIZE;
+ m_count+=_size;
+ mutex.unlock();
+}
+
+void k9fifo::dequeue(uchar *_buffer,uint32_t _size) {
+ mutex.lock();
+ if ( _size+head >INPUT_SIZE) {
+ uint32_t s1,s2;
+ s1=INPUT_SIZE - head;
+ tc_memcpy(_buffer,array+head,s1);
+ s2=_size-s1;
+ tc_memcpy(_buffer+s1,array,s2);
+ } else
+ tc_memcpy(_buffer,array+head,_size);
+ head =(head+_size)%INPUT_SIZE;
+ m_count -=_size;
+ mutex.unlock();
+}
+
+void k9fifo::clear() {
+ mutex.lock();
+ head=queue;
+ m_count=0;
+ mutex.unlock();
+}