-
Notifications
You must be signed in to change notification settings - Fork 0
/
checkpoint.cpp
61 lines (56 loc) · 1.06 KB
/
checkpoint.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
53
54
55
56
57
58
59
60
#include "checkpoint.h"
using namespace std;
int checkpoint::pass(checkp_get get, checkp_set set, std::string name)
{
lock();
if (get() == 0) {
thread_wait *tw = new thread_wait(this, get, name);
tws.push_back(tw);
tw->wait();
delete tw;
return pass(get, set, name);
}
int ret = set();
thread_wait *tw = process_thread_waits();
if (tw)
tw->wake();
unlock();
return ret;
}
int checkpoint::try_pass(checkp_get get, checkp_set set)
{
lock();
if (get() == 0) {
unlock();
return -1;
}
int ret = set();
thread_wait *tw = process_thread_waits();
if (tw)
tw->wake();
unlock();
return ret;
}
thread_wait *checkpoint::process_thread_waits()
{
for(list<thread_wait *>::iterator it=tws.begin(); it != tws.end();) {
thread_wait *tw = *it;
if (tw->get() != 0) {
it = tws.erase(it);
return tw;
} else
it++;
}
return 0;
}
string checkpoint::print()
{
stringstream os;
lock();
os << "Checkpoint state:\n";
for (std::list<thread_wait *>::const_iterator it=tws.begin(); it!=tws.end(); it++) {
os << *(*it);
}
unlock();
return os.str();
}