-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathQueue.h
More file actions
82 lines (67 loc) · 1.55 KB
/
Queue.h
File metadata and controls
82 lines (67 loc) · 1.55 KB
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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
/**
* Queue
* A thread safe queue.
*
* Wrapper around the std::deque with mutexes to ensure that only
* one thread can modify the container (deque) at the time.
*/
#ifndef Project4_Queue_h
#define Project4_Queue_h
#include <pthread.h>
#include <deque>
#include <Customer.h>
#include <unistd.h>
using namespace std;
class Queue {
public:
/**
* Function: Constructor
* Description: Initializes the mutex
*/
Queue();
virtual ~Queue();
/**
* Function: pop()
* Description: Pops and returns pointer to first element in the queue.
* IF the queue is empty, returns null ptr.
*
* @threadsafe
*/
Customer * pop();
/**
* Function: enqueue()
* Description: Enqueues a customer to the queue.
* @param *customer: A ptr to the customer to be added.
*
* @threadsafe
*/
void enqueue(Customer *customer);
/**
* Function: empty()
* Description: Checks if the queue is empty.
*
* @return bool true if queue is empty.
* @threadsafe
*/
bool empty();
/**
* Function: size()
* Description: Checks the size of the queue.
*
* @return int Size of the queue
* @threadsafe
**/
int size();
/**
* Function: printQueue()
* Description: Prints the contents of the queue.
* Used for *testing* purposes only.
*
* @threadsafe
*/
void printQueue();
private:
std::deque<Customer *> container; //contains customers
pthread_mutex_t mutex;
};
#endif /* BLOCKINGQUEUE_H_ */