-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathwork-queue.cpp
More file actions
39 lines (33 loc) · 766 Bytes
/
work-queue.cpp
File metadata and controls
39 lines (33 loc) · 766 Bytes
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
#include "work-queue.h"
#include "iostream"
#include <string>
using namespace std;
string StampedString::to_string() const{
return (string) time_string(timestamp)+","+message;
}
bool StampedString::set_from_string(string s) {
size_t i = s.find(",");
if(i != 24) {
return false;
}
string time_string = s.substr(0,i);
timestamp = time_from_string(time_string);
message = s.substr(i+1);
return true;
}
void test_work_queue() {
WorkQueue<string> q;
string t = "hello";
q.push(t);
string s;
if(q.try_pop(s, 500)){
cout << "got " << s << " from queue" << endl;
}
bool ok = q.try_pop(s,500);
if(ok) {
cout << "failed, should have timed out" << endl;
}
else{
cout << "passed, timed out as expected" << endl;
}
}