summaryrefslogtreecommitdiffstats
path: root/k9vamps/k9fifo.cpp
blob: 7c32de722424d2b9dce0ed8ee17f949f53549368 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
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();
}