GraphChi
0.1
Main Page
Namespaces
Classes
Files
File List
File Members
All
Classes
Namespaces
Files
Functions
Variables
Typedefs
Enumerations
Macros
src
util
synchronized_queue.hpp
1
#ifndef SYNCHRONIZED_QUEUE_HPP
2
#define SYNCHRONIZED_QUEUE_HPP
3
4
#include <queue>
5
#include "
pthread_tools.hpp
"
6
7
// From graphlab
8
9
namespace
graphchi {
10
11
12
template
<
typename
T>
13
class
synchronized_queue
{
14
15
public
:
16
synchronized_queue
() { };
17
~
synchronized_queue
() { };
18
19
void
push(
const
T &item) {
20
_queuelock.lock();
21
_queue.push(item);
22
_queuelock.unlock();
23
}
24
25
bool
safepop(T * ret) {
26
_queuelock.lock();
27
if
(_queue.size() == 0) {
28
_queuelock.unlock();
29
30
return
false
;
31
}
32
*ret = _queue.front();
33
_queue.pop();
34
_queuelock.unlock();
35
return
true
;
36
}
37
38
T pop() {
39
_queuelock.lock();
40
T t = _queue.front();
41
_queue.pop();
42
_queuelock.unlock();
43
return
t;
44
}
45
46
size_t
size()
const
{
47
return
_queue.size();
48
}
49
private
:
50
std::queue<T> _queue;
51
spinlock
_queuelock;
52
};
53
54
}
55
#endif
56
57
Generated on Thu Jul 5 2012 00:11:18 for GraphChi by
1.8.1.1