3686 |
22 Aug 17 |
peter |
// $Id$ |
3686 |
22 Aug 17 |
peter |
2 |
|
3686 |
22 Aug 17 |
peter |
3 |
/* |
3686 |
22 Aug 17 |
peter |
Copyright (C) 2017 Peter Johansson |
3686 |
22 Aug 17 |
peter |
5 |
|
3686 |
22 Aug 17 |
peter |
This file is part of the yat library, http://dev.thep.lu.se/yat |
3686 |
22 Aug 17 |
peter |
7 |
|
3686 |
22 Aug 17 |
peter |
The yat library is free software; you can redistribute it and/or |
3686 |
22 Aug 17 |
peter |
modify it under the terms of the GNU General Public License as |
3686 |
22 Aug 17 |
peter |
published by the Free Software Foundation; either version 3 of the |
3686 |
22 Aug 17 |
peter |
License, or (at your option) any later version. |
3686 |
22 Aug 17 |
peter |
12 |
|
3686 |
22 Aug 17 |
peter |
The yat library is distributed in the hope that it will be useful, |
3686 |
22 Aug 17 |
peter |
but WITHOUT ANY WARRANTY; without even the implied warranty of |
3686 |
22 Aug 17 |
peter |
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
3686 |
22 Aug 17 |
peter |
General Public License for more details. |
3686 |
22 Aug 17 |
peter |
17 |
|
3686 |
22 Aug 17 |
peter |
You should have received a copy of the GNU General Public License |
3686 |
22 Aug 17 |
peter |
along with yat. If not, see <http://www.gnu.org/licenses/>. |
3686 |
22 Aug 17 |
peter |
20 |
*/ |
3686 |
22 Aug 17 |
peter |
21 |
|
3686 |
22 Aug 17 |
peter |
22 |
#include <config.h> |
3686 |
22 Aug 17 |
peter |
23 |
|
3686 |
22 Aug 17 |
peter |
24 |
#include "Suite.h" |
3686 |
22 Aug 17 |
peter |
25 |
|
3686 |
22 Aug 17 |
peter |
26 |
#include "yat/utility/Scheduler.h" |
3686 |
22 Aug 17 |
peter |
27 |
|
3686 |
22 Aug 17 |
peter |
28 |
#include <boost/make_shared.hpp> |
3686 |
22 Aug 17 |
peter |
29 |
#include <boost/shared_ptr.hpp> |
3686 |
22 Aug 17 |
peter |
30 |
|
3686 |
22 Aug 17 |
peter |
31 |
#include <cstdlib> |
3686 |
22 Aug 17 |
peter |
32 |
#include <exception> |
3686 |
22 Aug 17 |
peter |
33 |
#include <iostream> |
3686 |
22 Aug 17 |
peter |
34 |
#include <set> |
3686 |
22 Aug 17 |
peter |
35 |
#include <unistd.h> |
3686 |
22 Aug 17 |
peter |
36 |
|
3686 |
22 Aug 17 |
peter |
37 |
using namespace theplu::yat; |
3686 |
22 Aug 17 |
peter |
38 |
using namespace theplu::yat::utility; |
3686 |
22 Aug 17 |
peter |
39 |
|
3686 |
22 Aug 17 |
peter |
40 |
class Sleeper : public Scheduler::Job |
3686 |
22 Aug 17 |
peter |
41 |
{ |
3686 |
22 Aug 17 |
peter |
42 |
public: |
3686 |
22 Aug 17 |
peter |
43 |
Sleeper(int t) : time_(t), done_(false) {} |
3686 |
22 Aug 17 |
peter |
44 |
void operator()(void) |
3686 |
22 Aug 17 |
peter |
45 |
{ |
3686 |
22 Aug 17 |
peter |
46 |
sleep(time_); |
3686 |
22 Aug 17 |
peter |
47 |
std::cout << "Have slept for " << time_ << " seconds" << std::endl; |
3686 |
22 Aug 17 |
peter |
48 |
done_ = true; |
3686 |
22 Aug 17 |
peter |
49 |
} |
3686 |
22 Aug 17 |
peter |
50 |
|
3686 |
22 Aug 17 |
peter |
51 |
bool done(void) const |
3686 |
22 Aug 17 |
peter |
52 |
{ |
3686 |
22 Aug 17 |
peter |
53 |
return done_; |
3686 |
22 Aug 17 |
peter |
54 |
} |
3686 |
22 Aug 17 |
peter |
55 |
|
3686 |
22 Aug 17 |
peter |
56 |
private: |
3686 |
22 Aug 17 |
peter |
57 |
int time_; |
3686 |
22 Aug 17 |
peter |
58 |
bool done_; |
3686 |
22 Aug 17 |
peter |
59 |
}; |
3686 |
22 Aug 17 |
peter |
60 |
|
3686 |
22 Aug 17 |
peter |
61 |
|
3686 |
22 Aug 17 |
peter |
62 |
int main(int argc, char* argv[]) |
3686 |
22 Aug 17 |
peter |
63 |
{ |
3686 |
22 Aug 17 |
peter |
64 |
test::Suite suite(argc, argv); |
3686 |
22 Aug 17 |
peter |
65 |
|
3686 |
22 Aug 17 |
peter |
66 |
try { |
3686 |
22 Aug 17 |
peter |
67 |
Scheduler scheduler(2); |
3686 |
22 Aug 17 |
peter |
68 |
boost::shared_ptr<Sleeper> postprocess(new Sleeper(3)); |
3686 |
22 Aug 17 |
peter |
69 |
for (int i=2; i<4; ++i) { |
3686 |
22 Aug 17 |
peter |
70 |
boost::shared_ptr<Sleeper> sleeper(new Sleeper(1)); |
3686 |
22 Aug 17 |
peter |
71 |
scheduler.add_dependency(postprocess, sleeper); |
3686 |
22 Aug 17 |
peter |
72 |
scheduler.submit(sleeper); |
3686 |
22 Aug 17 |
peter |
73 |
} |
3686 |
22 Aug 17 |
peter |
74 |
scheduler.wait(); |
3686 |
22 Aug 17 |
peter |
75 |
if (postprocess->done()) { |
3686 |
22 Aug 17 |
peter |
76 |
suite.err() << "error: postprocess done but never submitted\n"; |
3686 |
22 Aug 17 |
peter |
77 |
suite.add(false); |
3686 |
22 Aug 17 |
peter |
78 |
} |
3686 |
22 Aug 17 |
peter |
79 |
} |
3686 |
22 Aug 17 |
peter |
80 |
catch (std::exception& e) { |
3686 |
22 Aug 17 |
peter |
81 |
suite.err() << "error: " << e.what() << "\n"; |
3686 |
22 Aug 17 |
peter |
82 |
suite.add(false); |
3686 |
22 Aug 17 |
peter |
83 |
} |
3686 |
22 Aug 17 |
peter |
84 |
|
3686 |
22 Aug 17 |
peter |
85 |
return suite.return_value(); |
3686 |
22 Aug 17 |
peter |
86 |
} |