-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathbuffer.cpp
More file actions
64 lines (54 loc) · 831 Bytes
/
buffer.cpp
File metadata and controls
64 lines (54 loc) · 831 Bytes
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
55
56
57
58
59
60
61
62
63
64
#include "buffer.h"
buffer::buffer()
{
pthread_mutex_init(&mutex, NULL);
}
buffer::~buffer()
{
}
void buffer::lock()
{
pthread_mutex_lock(&mutex);
}
void buffer::unlock()
{
pthread_mutex_unlock(&mutex);
}
void buffer::add(char c) {data.push(c);}
void buffer::add(const char *s)
{
for(const char *p = s; *p; p++)
data.push(*p);
}
void buffer::lockedAdd(char c)
{
lock();
add(c);
unlock();
}
void buffer::lockedAdd(const char *s)
{
lock();
add(s);
unlock();
}
int buffer::lockedSize()
{
lock();
int retval = data.size();
unlock();
return retval;
}
unsigned char buffer::get()
{
unsigned char c = data.front();
data.pop();
return c;
}
unsigned char buffer::lockedGet()
{
lock();
unsigned char retval = get();
unlock();
return retval;
}