-
Notifications
You must be signed in to change notification settings - Fork 5
/
Pipe.h
61 lines (45 loc) · 1.5 KB
/
Pipe.h
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
#ifndef PIPE_H
#define PIPE_H
#include <pthread.h>
#include "Record.h"
class Pipe {
private:
// these are used for data storage in the pipeline
Record *buffered;
int firstSlot;
int lastSlot;
int totSpace;
int done;
// mutex for the pipe
pthread_mutex_t pipeMutex;
// condition variables that the producer and consumer wait on
pthread_cond_t producerVar;
pthread_cond_t consumerVar;
Pipe(const Pipe &);
Pipe operator=(const Pipe &);
public:
// this sets up the pipeline; the parameter is the number of
// records to buffer
Pipe (int bufferSize);
virtual ~Pipe();
// This inserts a record into the pipeline; note that if the
// buffer size is exceeded, then the insertion may block
// Note that the parameter is consumed; after insertion, it can
// no longer be used and will be zero'ed out
// again, incorrect, the reference is invalid and is a NULL pointer.
void Insert (Record *insertMe);
// This removes a record from the pipeline and puts it into the
// argument. Note that whatever was in the parameter before the
// call will be lost. This may block if there are no records in
// the pipeline to be removed. The return value is a 1 on success
// and a zero if there are no more records in the pipeline
int Remove (Record *removeMe);
// shut down the pipepine; used by the *producer* to signal that
// there is no more data that is going to be added into the pipe
void ShutDown ();
bool Done()
{
return (1 == done);
}
};
#endif