-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathQueue.cpp
52 lines (44 loc) · 900 Bytes
/
Queue.cpp
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
/*
* Queue.cpp
*
* Created on: Feb 20, 2015
* Author: rmin
*/
#include "Queue.h"
template<typename T>
Queue<T>::Queue() {
// TODO Auto-generated constructor stub
}
template<typename T>
Queue<T>::~Queue() {
// TODO Auto-generated destructor stub
}
template<typename T>
T Queue<T>::pop() {
this->mutex_.lock();
T value;
if (!this->queue_.empty()) {
value = this->queue_.front(); // undefined behavior if queue_ is empty
// may segfault, may throw, etc.
this->queue_.pop();
}
this->mutex_.unlock();
return value;
}
template<typename T>
void Queue<T>::push(T value) {
this->mutex_.lock();
this->queue_.push(value);
this->mutex_.unlock();
}
template<typename T>
bool Queue<T>::empty() {
this->mutex_.lock();
bool check = this->queue_.empty();
this->mutex_.unlock();
return check;
}
template<typename T>
int Queue<T>::getSize() {
return queue_.size();
}