annotate UnitTestsSources/MultiThreading.cpp @ 768:476febedc516 lua-scripting

improvements
author Sebastien Jodogne <s.jodogne@gmail.com>
date Wed, 23 Apr 2014 17:23:18 +0200
parents fc97f762834c
children a64ca424e0e2
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
723
0da078f3affc multithreading tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1 #include "gtest/gtest.h"
765
fc97f762834c scheduler
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 760
diff changeset
2 #include <glog/logging.h>
723
0da078f3affc multithreading tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3
0da078f3affc multithreading tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
4 #include "../Core/OrthancException.h"
0da078f3affc multithreading tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
5 #include "../Core/Toolbox.h"
0da078f3affc multithreading tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
6 #include "../Core/MultiThreading/ArrayFilledByThreads.h"
760
b2a62f22fbe8 lock abstraction
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 723
diff changeset
7 #include "../Core/MultiThreading/Locker.h"
b2a62f22fbe8 lock abstraction
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 723
diff changeset
8 #include "../Core/MultiThreading/Mutex.h"
b2a62f22fbe8 lock abstraction
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 723
diff changeset
9 #include "../Core/MultiThreading/ReaderWriterLock.h"
723
0da078f3affc multithreading tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
10 #include "../Core/MultiThreading/ThreadedCommandProcessor.h"
0da078f3affc multithreading tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
11
0da078f3affc multithreading tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
12 using namespace Orthanc;
0da078f3affc multithreading tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
13
0da078f3affc multithreading tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
14 namespace
0da078f3affc multithreading tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
15 {
0da078f3affc multithreading tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
16 class DynamicInteger : public ICommand
0da078f3affc multithreading tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
17 {
0da078f3affc multithreading tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
18 private:
0da078f3affc multithreading tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
19 int value_;
0da078f3affc multithreading tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
20 std::set<int>& target_;
0da078f3affc multithreading tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
21
0da078f3affc multithreading tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
22 public:
0da078f3affc multithreading tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
23 DynamicInteger(int value, std::set<int>& target) :
0da078f3affc multithreading tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
24 value_(value), target_(target)
0da078f3affc multithreading tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
25 {
0da078f3affc multithreading tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
26 }
0da078f3affc multithreading tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
27
0da078f3affc multithreading tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
28 int GetValue() const
0da078f3affc multithreading tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
29 {
0da078f3affc multithreading tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
30 return value_;
0da078f3affc multithreading tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
31 }
0da078f3affc multithreading tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
32
0da078f3affc multithreading tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
33 virtual bool Execute()
0da078f3affc multithreading tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
34 {
0da078f3affc multithreading tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
35 static boost::mutex mutex;
0da078f3affc multithreading tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
36 boost::mutex::scoped_lock lock(mutex);
0da078f3affc multithreading tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
37 target_.insert(value_);
0da078f3affc multithreading tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
38 return true;
0da078f3affc multithreading tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
39 }
0da078f3affc multithreading tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
40 };
0da078f3affc multithreading tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
41
0da078f3affc multithreading tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
42 class MyFiller : public ArrayFilledByThreads::IFiller
0da078f3affc multithreading tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
43 {
0da078f3affc multithreading tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
44 private:
0da078f3affc multithreading tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
45 int size_;
0da078f3affc multithreading tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
46 unsigned int created_;
0da078f3affc multithreading tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
47 std::set<int> set_;
0da078f3affc multithreading tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
48
0da078f3affc multithreading tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
49 public:
0da078f3affc multithreading tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
50 MyFiller(int size) : size_(size), created_(0)
0da078f3affc multithreading tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
51 {
0da078f3affc multithreading tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
52 }
0da078f3affc multithreading tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
53
0da078f3affc multithreading tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
54 virtual size_t GetFillerSize()
0da078f3affc multithreading tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
55 {
0da078f3affc multithreading tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
56 return size_;
0da078f3affc multithreading tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
57 }
0da078f3affc multithreading tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
58
0da078f3affc multithreading tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
59 virtual IDynamicObject* GetFillerItem(size_t index)
0da078f3affc multithreading tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
60 {
0da078f3affc multithreading tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
61 static boost::mutex mutex;
0da078f3affc multithreading tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
62 boost::mutex::scoped_lock lock(mutex);
0da078f3affc multithreading tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
63 created_++;
0da078f3affc multithreading tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
64 return new DynamicInteger(index * 2, set_);
0da078f3affc multithreading tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
65 }
0da078f3affc multithreading tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
66
0da078f3affc multithreading tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
67 unsigned int GetCreatedCount() const
0da078f3affc multithreading tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
68 {
0da078f3affc multithreading tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
69 return created_;
0da078f3affc multithreading tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
70 }
0da078f3affc multithreading tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
71
0da078f3affc multithreading tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
72 std::set<int> GetSet()
0da078f3affc multithreading tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
73 {
0da078f3affc multithreading tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
74 return set_;
0da078f3affc multithreading tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
75 }
0da078f3affc multithreading tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
76 };
0da078f3affc multithreading tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
77 }
0da078f3affc multithreading tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
78
0da078f3affc multithreading tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
79
0da078f3affc multithreading tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
80
0da078f3affc multithreading tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
81
0da078f3affc multithreading tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
82 TEST(MultiThreading, SharedMessageQueueBasic)
0da078f3affc multithreading tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
83 {
0da078f3affc multithreading tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
84 std::set<int> s;
0da078f3affc multithreading tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
85
0da078f3affc multithreading tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
86 SharedMessageQueue q;
0da078f3affc multithreading tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
87 ASSERT_TRUE(q.WaitEmpty(0));
0da078f3affc multithreading tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
88 q.Enqueue(new DynamicInteger(10, s));
0da078f3affc multithreading tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
89 ASSERT_FALSE(q.WaitEmpty(1));
0da078f3affc multithreading tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
90 q.Enqueue(new DynamicInteger(20, s));
0da078f3affc multithreading tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
91 q.Enqueue(new DynamicInteger(30, s));
0da078f3affc multithreading tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
92 q.Enqueue(new DynamicInteger(40, s));
0da078f3affc multithreading tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
93
0da078f3affc multithreading tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
94 std::auto_ptr<DynamicInteger> i;
0da078f3affc multithreading tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
95 i.reset(dynamic_cast<DynamicInteger*>(q.Dequeue(1))); ASSERT_EQ(10, i->GetValue());
0da078f3affc multithreading tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
96 i.reset(dynamic_cast<DynamicInteger*>(q.Dequeue(1))); ASSERT_EQ(20, i->GetValue());
0da078f3affc multithreading tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
97 i.reset(dynamic_cast<DynamicInteger*>(q.Dequeue(1))); ASSERT_EQ(30, i->GetValue());
0da078f3affc multithreading tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
98 ASSERT_FALSE(q.WaitEmpty(1));
0da078f3affc multithreading tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
99 i.reset(dynamic_cast<DynamicInteger*>(q.Dequeue(1))); ASSERT_EQ(40, i->GetValue());
0da078f3affc multithreading tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
100 ASSERT_TRUE(q.WaitEmpty(0));
0da078f3affc multithreading tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
101 ASSERT_EQ(NULL, q.Dequeue(1));
0da078f3affc multithreading tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
102 }
0da078f3affc multithreading tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
103
0da078f3affc multithreading tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
104
0da078f3affc multithreading tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
105 TEST(MultiThreading, SharedMessageQueueClean)
0da078f3affc multithreading tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
106 {
0da078f3affc multithreading tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
107 std::set<int> s;
0da078f3affc multithreading tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
108
0da078f3affc multithreading tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
109 try
0da078f3affc multithreading tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
110 {
0da078f3affc multithreading tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
111 SharedMessageQueue q;
0da078f3affc multithreading tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
112 q.Enqueue(new DynamicInteger(10, s));
0da078f3affc multithreading tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
113 q.Enqueue(new DynamicInteger(20, s));
0da078f3affc multithreading tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
114 throw OrthancException("Nope");
0da078f3affc multithreading tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
115 }
0da078f3affc multithreading tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
116 catch (OrthancException&)
0da078f3affc multithreading tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
117 {
0da078f3affc multithreading tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
118 }
0da078f3affc multithreading tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
119 }
0da078f3affc multithreading tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
120
0da078f3affc multithreading tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
121
0da078f3affc multithreading tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
122 TEST(MultiThreading, ArrayFilledByThreadEmpty)
0da078f3affc multithreading tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
123 {
0da078f3affc multithreading tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
124 MyFiller f(0);
0da078f3affc multithreading tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
125 ArrayFilledByThreads a(f);
0da078f3affc multithreading tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
126 a.SetThreadCount(1);
0da078f3affc multithreading tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
127 ASSERT_EQ(0, a.GetSize());
0da078f3affc multithreading tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
128 }
0da078f3affc multithreading tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
129
0da078f3affc multithreading tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
130
0da078f3affc multithreading tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
131 TEST(MultiThreading, ArrayFilledByThread1)
0da078f3affc multithreading tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
132 {
0da078f3affc multithreading tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
133 MyFiller f(100);
0da078f3affc multithreading tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
134 ArrayFilledByThreads a(f);
0da078f3affc multithreading tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
135 a.SetThreadCount(1);
0da078f3affc multithreading tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
136 ASSERT_EQ(100, a.GetSize());
0da078f3affc multithreading tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
137 for (size_t i = 0; i < a.GetSize(); i++)
0da078f3affc multithreading tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
138 {
0da078f3affc multithreading tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
139 ASSERT_EQ(2 * i, dynamic_cast<DynamicInteger&>(a.GetItem(i)).GetValue());
0da078f3affc multithreading tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
140 }
0da078f3affc multithreading tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
141 }
0da078f3affc multithreading tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
142
0da078f3affc multithreading tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
143
0da078f3affc multithreading tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
144 TEST(MultiThreading, ArrayFilledByThread4)
0da078f3affc multithreading tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
145 {
0da078f3affc multithreading tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
146 MyFiller f(100);
0da078f3affc multithreading tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
147 ArrayFilledByThreads a(f);
0da078f3affc multithreading tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
148 a.SetThreadCount(4);
0da078f3affc multithreading tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
149 ASSERT_EQ(100, a.GetSize());
0da078f3affc multithreading tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
150 for (size_t i = 0; i < a.GetSize(); i++)
0da078f3affc multithreading tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
151 {
0da078f3affc multithreading tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
152 ASSERT_EQ(2 * i, dynamic_cast<DynamicInteger&>(a.GetItem(i)).GetValue());
0da078f3affc multithreading tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
153 }
0da078f3affc multithreading tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
154
0da078f3affc multithreading tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
155 ASSERT_EQ(100u, f.GetCreatedCount());
0da078f3affc multithreading tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
156
0da078f3affc multithreading tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
157 a.Invalidate();
0da078f3affc multithreading tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
158
0da078f3affc multithreading tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
159 ASSERT_EQ(100, a.GetSize());
0da078f3affc multithreading tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
160 ASSERT_EQ(200u, f.GetCreatedCount());
0da078f3affc multithreading tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
161 ASSERT_EQ(4u, a.GetThreadCount());
0da078f3affc multithreading tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
162 ASSERT_TRUE(f.GetSet().empty());
0da078f3affc multithreading tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
163
0da078f3affc multithreading tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
164 for (size_t i = 0; i < a.GetSize(); i++)
0da078f3affc multithreading tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
165 {
0da078f3affc multithreading tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
166 ASSERT_EQ(2 * i, dynamic_cast<DynamicInteger&>(a.GetItem(i)).GetValue());
0da078f3affc multithreading tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
167 }
0da078f3affc multithreading tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
168 }
0da078f3affc multithreading tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
169
0da078f3affc multithreading tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
170
0da078f3affc multithreading tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
171 TEST(MultiThreading, CommandProcessor)
0da078f3affc multithreading tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
172 {
0da078f3affc multithreading tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
173 ThreadedCommandProcessor p(4);
0da078f3affc multithreading tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
174
0da078f3affc multithreading tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
175 std::set<int> s;
0da078f3affc multithreading tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
176
0da078f3affc multithreading tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
177 for (size_t i = 0; i < 100; i++)
0da078f3affc multithreading tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
178 {
0da078f3affc multithreading tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
179 p.Post(new DynamicInteger(i * 2, s));
0da078f3affc multithreading tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
180 }
0da078f3affc multithreading tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
181
0da078f3affc multithreading tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
182 p.Join();
0da078f3affc multithreading tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
183
0da078f3affc multithreading tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
184 for (size_t i = 0; i < 200; i++)
0da078f3affc multithreading tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
185 {
0da078f3affc multithreading tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
186 if (i % 2)
0da078f3affc multithreading tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
187 ASSERT_TRUE(s.find(i) == s.end());
0da078f3affc multithreading tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
188 else
0da078f3affc multithreading tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
189 ASSERT_TRUE(s.find(i) != s.end());
0da078f3affc multithreading tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
190 }
0da078f3affc multithreading tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
191 }
760
b2a62f22fbe8 lock abstraction
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 723
diff changeset
192
b2a62f22fbe8 lock abstraction
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 723
diff changeset
193
b2a62f22fbe8 lock abstraction
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 723
diff changeset
194 TEST(MultiThreading, Mutex)
b2a62f22fbe8 lock abstraction
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 723
diff changeset
195 {
b2a62f22fbe8 lock abstraction
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 723
diff changeset
196 Mutex mutex;
b2a62f22fbe8 lock abstraction
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 723
diff changeset
197 Locker locker(mutex);
b2a62f22fbe8 lock abstraction
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 723
diff changeset
198 }
b2a62f22fbe8 lock abstraction
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 723
diff changeset
199
b2a62f22fbe8 lock abstraction
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 723
diff changeset
200
b2a62f22fbe8 lock abstraction
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 723
diff changeset
201 TEST(MultiThreading, ReaderWriterLock)
b2a62f22fbe8 lock abstraction
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 723
diff changeset
202 {
b2a62f22fbe8 lock abstraction
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 723
diff changeset
203 ReaderWriterLock lock;
b2a62f22fbe8 lock abstraction
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 723
diff changeset
204
b2a62f22fbe8 lock abstraction
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 723
diff changeset
205 {
b2a62f22fbe8 lock abstraction
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 723
diff changeset
206 Locker locker1(lock.ForReader());
b2a62f22fbe8 lock abstraction
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 723
diff changeset
207 Locker locker2(lock.ForReader());
b2a62f22fbe8 lock abstraction
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 723
diff changeset
208 }
b2a62f22fbe8 lock abstraction
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 723
diff changeset
209
b2a62f22fbe8 lock abstraction
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 723
diff changeset
210 {
b2a62f22fbe8 lock abstraction
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 723
diff changeset
211 Locker locker3(lock.ForWriter());
b2a62f22fbe8 lock abstraction
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 723
diff changeset
212 }
b2a62f22fbe8 lock abstraction
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 723
diff changeset
213 }
765
fc97f762834c scheduler
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 760
diff changeset
214
fc97f762834c scheduler
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 760
diff changeset
215
fc97f762834c scheduler
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 760
diff changeset
216
fc97f762834c scheduler
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 760
diff changeset
217
fc97f762834c scheduler
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 760
diff changeset
218
fc97f762834c scheduler
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 760
diff changeset
219
fc97f762834c scheduler
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 760
diff changeset
220
fc97f762834c scheduler
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 760
diff changeset
221 #include "../Core/ICommand.h"
fc97f762834c scheduler
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 760
diff changeset
222 #include "../Core/Toolbox.h"
fc97f762834c scheduler
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 760
diff changeset
223 #include "../Core/Uuid.h"
fc97f762834c scheduler
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 760
diff changeset
224 #include "../Core/MultiThreading/SharedMessageQueue.h"
fc97f762834c scheduler
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 760
diff changeset
225 #include <boost/lexical_cast.hpp>
fc97f762834c scheduler
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 760
diff changeset
226
fc97f762834c scheduler
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 760
diff changeset
227
fc97f762834c scheduler
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 760
diff changeset
228 namespace Orthanc
fc97f762834c scheduler
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 760
diff changeset
229 {
fc97f762834c scheduler
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 760
diff changeset
230 typedef std::list<std::string> ListOfStrings;
fc97f762834c scheduler
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 760
diff changeset
231
fc97f762834c scheduler
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 760
diff changeset
232 class IServerFilter
fc97f762834c scheduler
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 760
diff changeset
233 {
fc97f762834c scheduler
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 760
diff changeset
234 public:
fc97f762834c scheduler
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 760
diff changeset
235 virtual ~IServerFilter()
fc97f762834c scheduler
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 760
diff changeset
236 {
fc97f762834c scheduler
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 760
diff changeset
237 }
fc97f762834c scheduler
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 760
diff changeset
238
fc97f762834c scheduler
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 760
diff changeset
239 virtual bool Apply(ListOfStrings& outputs,
fc97f762834c scheduler
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 760
diff changeset
240 const ListOfStrings& inputs) = 0;
fc97f762834c scheduler
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 760
diff changeset
241 };
fc97f762834c scheduler
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 760
diff changeset
242
fc97f762834c scheduler
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 760
diff changeset
243
fc97f762834c scheduler
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 760
diff changeset
244 class Sink : public IServerFilter
fc97f762834c scheduler
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 760
diff changeset
245 {
fc97f762834c scheduler
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 760
diff changeset
246 private:
fc97f762834c scheduler
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 760
diff changeset
247 ListOfStrings& target_;
fc97f762834c scheduler
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 760
diff changeset
248
fc97f762834c scheduler
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 760
diff changeset
249 public:
fc97f762834c scheduler
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 760
diff changeset
250 Sink(ListOfStrings& target) : target_(target)
fc97f762834c scheduler
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 760
diff changeset
251 {
fc97f762834c scheduler
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 760
diff changeset
252 }
fc97f762834c scheduler
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 760
diff changeset
253
fc97f762834c scheduler
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 760
diff changeset
254 virtual bool Apply(ListOfStrings& outputs,
fc97f762834c scheduler
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 760
diff changeset
255 const ListOfStrings& inputs)
fc97f762834c scheduler
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 760
diff changeset
256 {
fc97f762834c scheduler
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 760
diff changeset
257 for (ListOfStrings::const_iterator
fc97f762834c scheduler
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 760
diff changeset
258 it = inputs.begin(); it != inputs.end(); it++)
fc97f762834c scheduler
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 760
diff changeset
259 {
fc97f762834c scheduler
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 760
diff changeset
260 target_.push_back(*it);
fc97f762834c scheduler
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 760
diff changeset
261 }
fc97f762834c scheduler
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 760
diff changeset
262
fc97f762834c scheduler
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 760
diff changeset
263 return true;
fc97f762834c scheduler
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 760
diff changeset
264 }
fc97f762834c scheduler
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 760
diff changeset
265 };
fc97f762834c scheduler
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 760
diff changeset
266
fc97f762834c scheduler
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 760
diff changeset
267
fc97f762834c scheduler
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 760
diff changeset
268
fc97f762834c scheduler
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 760
diff changeset
269 class IServerFilterListener
fc97f762834c scheduler
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 760
diff changeset
270 {
fc97f762834c scheduler
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 760
diff changeset
271 public:
fc97f762834c scheduler
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 760
diff changeset
272 virtual ~IServerFilterListener()
fc97f762834c scheduler
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 760
diff changeset
273 {
fc97f762834c scheduler
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 760
diff changeset
274 }
fc97f762834c scheduler
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 760
diff changeset
275
fc97f762834c scheduler
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 760
diff changeset
276 virtual void SignalSuccess(const std::string& jobId) = 0;
fc97f762834c scheduler
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 760
diff changeset
277
fc97f762834c scheduler
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 760
diff changeset
278 virtual void SignalFailure(const std::string& jobId) = 0;
fc97f762834c scheduler
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 760
diff changeset
279 };
fc97f762834c scheduler
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 760
diff changeset
280
fc97f762834c scheduler
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 760
diff changeset
281
fc97f762834c scheduler
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 760
diff changeset
282 class FilterWrapper : public IDynamicObject
fc97f762834c scheduler
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 760
diff changeset
283 {
768
476febedc516 improvements
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 765
diff changeset
284 friend class ServerScheduler;
476febedc516 improvements
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 765
diff changeset
285
765
fc97f762834c scheduler
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 760
diff changeset
286 private:
fc97f762834c scheduler
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 760
diff changeset
287 IServerFilter *filter_;
fc97f762834c scheduler
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 760
diff changeset
288 std::string jobId_;
fc97f762834c scheduler
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 760
diff changeset
289 ListOfStrings inputs_;
fc97f762834c scheduler
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 760
diff changeset
290 std::list<FilterWrapper*> next_;
fc97f762834c scheduler
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 760
diff changeset
291
768
476febedc516 improvements
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 765
diff changeset
292 bool Execute(IServerFilterListener& listener)
476febedc516 improvements
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 765
diff changeset
293 {
476febedc516 improvements
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 765
diff changeset
294 ListOfStrings outputs;
476febedc516 improvements
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 765
diff changeset
295 if (!filter_->Apply(outputs, inputs_))
476febedc516 improvements
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 765
diff changeset
296 {
476febedc516 improvements
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 765
diff changeset
297 listener.SignalFailure(jobId_);
476febedc516 improvements
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 765
diff changeset
298 return true;
476febedc516 improvements
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 765
diff changeset
299 }
476febedc516 improvements
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 765
diff changeset
300
476febedc516 improvements
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 765
diff changeset
301 for (std::list<FilterWrapper*>::iterator
476febedc516 improvements
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 765
diff changeset
302 it = next_.begin(); it != next_.end(); it++)
476febedc516 improvements
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 765
diff changeset
303 {
476febedc516 improvements
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 765
diff changeset
304 for (ListOfStrings::const_iterator
476febedc516 improvements
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 765
diff changeset
305 output = outputs.begin(); output != outputs.end(); output++)
476febedc516 improvements
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 765
diff changeset
306 {
476febedc516 improvements
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 765
diff changeset
307 (*it)->AddInput(*output);
476febedc516 improvements
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 765
diff changeset
308 }
476febedc516 improvements
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 765
diff changeset
309 }
476febedc516 improvements
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 765
diff changeset
310
476febedc516 improvements
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 765
diff changeset
311 listener.SignalSuccess(jobId_);
476febedc516 improvements
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 765
diff changeset
312 return true;
476febedc516 improvements
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 765
diff changeset
313 }
476febedc516 improvements
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 765
diff changeset
314
476febedc516 improvements
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 765
diff changeset
315
765
fc97f762834c scheduler
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 760
diff changeset
316 public:
fc97f762834c scheduler
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 760
diff changeset
317 FilterWrapper(IServerFilter *filter,
fc97f762834c scheduler
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 760
diff changeset
318 const std::string& jobId) :
fc97f762834c scheduler
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 760
diff changeset
319 filter_(filter),
fc97f762834c scheduler
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 760
diff changeset
320 jobId_(jobId)
fc97f762834c scheduler
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 760
diff changeset
321 {
fc97f762834c scheduler
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 760
diff changeset
322 if (filter_ == NULL)
fc97f762834c scheduler
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 760
diff changeset
323 {
fc97f762834c scheduler
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 760
diff changeset
324 throw OrthancException(ErrorCode_ParameterOutOfRange);
fc97f762834c scheduler
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 760
diff changeset
325 }
fc97f762834c scheduler
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 760
diff changeset
326 }
fc97f762834c scheduler
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 760
diff changeset
327
fc97f762834c scheduler
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 760
diff changeset
328 virtual ~FilterWrapper()
fc97f762834c scheduler
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 760
diff changeset
329 {
fc97f762834c scheduler
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 760
diff changeset
330 if (filter_ != NULL)
fc97f762834c scheduler
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 760
diff changeset
331 {
fc97f762834c scheduler
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 760
diff changeset
332 delete filter_;
fc97f762834c scheduler
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 760
diff changeset
333 }
fc97f762834c scheduler
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 760
diff changeset
334 }
fc97f762834c scheduler
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 760
diff changeset
335
fc97f762834c scheduler
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 760
diff changeset
336 const std::string& GetJobId() const
fc97f762834c scheduler
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 760
diff changeset
337 {
fc97f762834c scheduler
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 760
diff changeset
338 return jobId_;
fc97f762834c scheduler
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 760
diff changeset
339 }
fc97f762834c scheduler
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 760
diff changeset
340
fc97f762834c scheduler
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 760
diff changeset
341 void AddInput(const std::string& input)
fc97f762834c scheduler
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 760
diff changeset
342 {
fc97f762834c scheduler
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 760
diff changeset
343 inputs_.push_back(input);
fc97f762834c scheduler
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 760
diff changeset
344 }
fc97f762834c scheduler
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 760
diff changeset
345
fc97f762834c scheduler
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 760
diff changeset
346 void ConnectNext(FilterWrapper& filter)
fc97f762834c scheduler
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 760
diff changeset
347 {
fc97f762834c scheduler
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 760
diff changeset
348 next_.push_back(&filter);
fc97f762834c scheduler
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 760
diff changeset
349 }
fc97f762834c scheduler
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 760
diff changeset
350
fc97f762834c scheduler
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 760
diff changeset
351 const std::list<FilterWrapper*>& GetNextFilters() const
fc97f762834c scheduler
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 760
diff changeset
352 {
fc97f762834c scheduler
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 760
diff changeset
353 return next_;
fc97f762834c scheduler
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 760
diff changeset
354 }
fc97f762834c scheduler
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 760
diff changeset
355 };
fc97f762834c scheduler
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 760
diff changeset
356
fc97f762834c scheduler
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 760
diff changeset
357
fc97f762834c scheduler
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 760
diff changeset
358 class ServerJob
fc97f762834c scheduler
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 760
diff changeset
359 {
fc97f762834c scheduler
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 760
diff changeset
360 friend class ServerScheduler;
fc97f762834c scheduler
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 760
diff changeset
361
fc97f762834c scheduler
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 760
diff changeset
362 private:
fc97f762834c scheduler
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 760
diff changeset
363 std::list<FilterWrapper*> filters_;
fc97f762834c scheduler
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 760
diff changeset
364 std::string jobId_;
fc97f762834c scheduler
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 760
diff changeset
365 bool submitted_;
fc97f762834c scheduler
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 760
diff changeset
366 std::string description_;
fc97f762834c scheduler
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 760
diff changeset
367
fc97f762834c scheduler
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 760
diff changeset
368
fc97f762834c scheduler
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 760
diff changeset
369 void CheckOrdering()
fc97f762834c scheduler
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 760
diff changeset
370 {
fc97f762834c scheduler
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 760
diff changeset
371 std::map<FilterWrapper*, unsigned int> index;
fc97f762834c scheduler
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 760
diff changeset
372
fc97f762834c scheduler
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 760
diff changeset
373 unsigned int count = 0;
fc97f762834c scheduler
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 760
diff changeset
374 for (std::list<FilterWrapper*>::const_iterator
fc97f762834c scheduler
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 760
diff changeset
375 it = filters_.begin(); it != filters_.end(); it++)
fc97f762834c scheduler
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 760
diff changeset
376 {
fc97f762834c scheduler
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 760
diff changeset
377 index[*it] = count++;
fc97f762834c scheduler
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 760
diff changeset
378 }
fc97f762834c scheduler
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 760
diff changeset
379
fc97f762834c scheduler
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 760
diff changeset
380 for (std::list<FilterWrapper*>::const_iterator
fc97f762834c scheduler
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 760
diff changeset
381 it = filters_.begin(); it != filters_.end(); it++)
fc97f762834c scheduler
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 760
diff changeset
382 {
fc97f762834c scheduler
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 760
diff changeset
383 const std::list<FilterWrapper*>& nextFilters = (*it)->GetNextFilters();
fc97f762834c scheduler
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 760
diff changeset
384
fc97f762834c scheduler
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 760
diff changeset
385 for (std::list<FilterWrapper*>::const_iterator
fc97f762834c scheduler
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 760
diff changeset
386 next = nextFilters.begin(); next != nextFilters.end(); next++)
fc97f762834c scheduler
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 760
diff changeset
387 {
fc97f762834c scheduler
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 760
diff changeset
388 if (index.find(*next) == index.end() ||
fc97f762834c scheduler
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 760
diff changeset
389 index[*next] <= index[*it])
fc97f762834c scheduler
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 760
diff changeset
390 {
fc97f762834c scheduler
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 760
diff changeset
391 // You must reorder your calls to "ServerJob::AddFilter"
fc97f762834c scheduler
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 760
diff changeset
392 throw OrthancException("Bad ordering of filters in a job");
fc97f762834c scheduler
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 760
diff changeset
393 }
fc97f762834c scheduler
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 760
diff changeset
394 }
fc97f762834c scheduler
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 760
diff changeset
395 }
fc97f762834c scheduler
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 760
diff changeset
396 }
fc97f762834c scheduler
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 760
diff changeset
397
fc97f762834c scheduler
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 760
diff changeset
398
fc97f762834c scheduler
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 760
diff changeset
399 size_t Submit(SharedMessageQueue& target,
fc97f762834c scheduler
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 760
diff changeset
400 IServerFilterListener& listener)
fc97f762834c scheduler
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 760
diff changeset
401 {
fc97f762834c scheduler
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 760
diff changeset
402 if (submitted_)
fc97f762834c scheduler
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 760
diff changeset
403 {
fc97f762834c scheduler
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 760
diff changeset
404 // This job has already been submitted
fc97f762834c scheduler
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 760
diff changeset
405 throw OrthancException(ErrorCode_BadSequenceOfCalls);
fc97f762834c scheduler
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 760
diff changeset
406 }
fc97f762834c scheduler
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 760
diff changeset
407
fc97f762834c scheduler
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 760
diff changeset
408 CheckOrdering();
fc97f762834c scheduler
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 760
diff changeset
409
fc97f762834c scheduler
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 760
diff changeset
410 size_t size = filters_.size();
fc97f762834c scheduler
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 760
diff changeset
411
fc97f762834c scheduler
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 760
diff changeset
412 for (std::list<FilterWrapper*>::iterator
fc97f762834c scheduler
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 760
diff changeset
413 it = filters_.begin(); it != filters_.end(); it++)
fc97f762834c scheduler
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 760
diff changeset
414 {
fc97f762834c scheduler
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 760
diff changeset
415 target.Enqueue(*it);
fc97f762834c scheduler
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 760
diff changeset
416 }
fc97f762834c scheduler
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 760
diff changeset
417
fc97f762834c scheduler
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 760
diff changeset
418 filters_.clear();
fc97f762834c scheduler
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 760
diff changeset
419 submitted_ = true;
fc97f762834c scheduler
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 760
diff changeset
420
fc97f762834c scheduler
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 760
diff changeset
421 return size;
fc97f762834c scheduler
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 760
diff changeset
422 }
fc97f762834c scheduler
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 760
diff changeset
423
fc97f762834c scheduler
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 760
diff changeset
424 public:
fc97f762834c scheduler
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 760
diff changeset
425 ServerJob()
fc97f762834c scheduler
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 760
diff changeset
426 {
fc97f762834c scheduler
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 760
diff changeset
427 jobId_ = Toolbox::GenerateUuid();
fc97f762834c scheduler
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 760
diff changeset
428 submitted_ = false;
fc97f762834c scheduler
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 760
diff changeset
429 description_ = "no description";
fc97f762834c scheduler
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 760
diff changeset
430 }
fc97f762834c scheduler
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 760
diff changeset
431
fc97f762834c scheduler
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 760
diff changeset
432 ~ServerJob()
fc97f762834c scheduler
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 760
diff changeset
433 {
fc97f762834c scheduler
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 760
diff changeset
434 for (std::list<FilterWrapper*>::iterator
fc97f762834c scheduler
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 760
diff changeset
435 it = filters_.begin(); it != filters_.end(); it++)
fc97f762834c scheduler
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 760
diff changeset
436 {
fc97f762834c scheduler
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 760
diff changeset
437 delete *it;
fc97f762834c scheduler
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 760
diff changeset
438 }
fc97f762834c scheduler
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 760
diff changeset
439 }
fc97f762834c scheduler
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 760
diff changeset
440
fc97f762834c scheduler
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 760
diff changeset
441 const std::string& GetId() const
fc97f762834c scheduler
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 760
diff changeset
442 {
fc97f762834c scheduler
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 760
diff changeset
443 return jobId_;
fc97f762834c scheduler
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 760
diff changeset
444 }
fc97f762834c scheduler
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 760
diff changeset
445
fc97f762834c scheduler
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 760
diff changeset
446 void SetDescription(const char* description)
fc97f762834c scheduler
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 760
diff changeset
447 {
fc97f762834c scheduler
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 760
diff changeset
448 description_ = description;
fc97f762834c scheduler
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 760
diff changeset
449 }
fc97f762834c scheduler
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 760
diff changeset
450
fc97f762834c scheduler
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 760
diff changeset
451 const std::string& GetDescription() const
fc97f762834c scheduler
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 760
diff changeset
452 {
fc97f762834c scheduler
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 760
diff changeset
453 return description_;
fc97f762834c scheduler
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 760
diff changeset
454 }
fc97f762834c scheduler
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 760
diff changeset
455
fc97f762834c scheduler
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 760
diff changeset
456 FilterWrapper& AddFilter(IServerFilter* filter)
fc97f762834c scheduler
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 760
diff changeset
457 {
fc97f762834c scheduler
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 760
diff changeset
458 if (submitted_)
fc97f762834c scheduler
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 760
diff changeset
459 {
fc97f762834c scheduler
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 760
diff changeset
460 throw OrthancException(ErrorCode_BadSequenceOfCalls);
fc97f762834c scheduler
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 760
diff changeset
461 }
fc97f762834c scheduler
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 760
diff changeset
462
fc97f762834c scheduler
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 760
diff changeset
463 filters_.push_back(new FilterWrapper(filter, jobId_));
fc97f762834c scheduler
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 760
diff changeset
464
fc97f762834c scheduler
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 760
diff changeset
465 return *filters_.back();
fc97f762834c scheduler
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 760
diff changeset
466 }
fc97f762834c scheduler
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 760
diff changeset
467 };
fc97f762834c scheduler
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 760
diff changeset
468
fc97f762834c scheduler
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 760
diff changeset
469
fc97f762834c scheduler
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 760
diff changeset
470 class ServerScheduler : public IServerFilterListener
fc97f762834c scheduler
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 760
diff changeset
471 {
fc97f762834c scheduler
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 760
diff changeset
472 private:
fc97f762834c scheduler
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 760
diff changeset
473 struct JobInfo
fc97f762834c scheduler
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 760
diff changeset
474 {
fc97f762834c scheduler
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 760
diff changeset
475 bool watched_;
fc97f762834c scheduler
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 760
diff changeset
476 bool cancel_;
fc97f762834c scheduler
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 760
diff changeset
477 size_t size_;
fc97f762834c scheduler
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 760
diff changeset
478 size_t success_;
fc97f762834c scheduler
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 760
diff changeset
479 size_t failures_;
fc97f762834c scheduler
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 760
diff changeset
480 std::string description_;
fc97f762834c scheduler
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 760
diff changeset
481 };
fc97f762834c scheduler
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 760
diff changeset
482
768
476febedc516 improvements
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 765
diff changeset
483 enum JobStatus
476febedc516 improvements
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 765
diff changeset
484 {
476febedc516 improvements
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 765
diff changeset
485 JobStatus_Running = 1,
476febedc516 improvements
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 765
diff changeset
486 JobStatus_Success = 2,
476febedc516 improvements
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 765
diff changeset
487 JobStatus_Failure = 3
476febedc516 improvements
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 765
diff changeset
488 };
476febedc516 improvements
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 765
diff changeset
489
765
fc97f762834c scheduler
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 760
diff changeset
490 typedef std::map<std::string, JobInfo> Jobs;
fc97f762834c scheduler
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 760
diff changeset
491
fc97f762834c scheduler
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 760
diff changeset
492 boost::mutex mutex_;
fc97f762834c scheduler
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 760
diff changeset
493 boost::condition_variable jobFinished_;
fc97f762834c scheduler
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 760
diff changeset
494 Jobs jobs_;
fc97f762834c scheduler
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 760
diff changeset
495 SharedMessageQueue queue_;
fc97f762834c scheduler
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 760
diff changeset
496 bool finish_;
fc97f762834c scheduler
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 760
diff changeset
497 boost::thread worker_;
768
476febedc516 improvements
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 765
diff changeset
498 std::map<std::string, JobStatus> watchedJobStatus_;
765
fc97f762834c scheduler
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 760
diff changeset
499
fc97f762834c scheduler
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 760
diff changeset
500 JobInfo& GetJobInfo(const std::string& jobId)
fc97f762834c scheduler
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 760
diff changeset
501 {
fc97f762834c scheduler
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 760
diff changeset
502 Jobs::iterator info = jobs_.find(jobId);
fc97f762834c scheduler
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 760
diff changeset
503
fc97f762834c scheduler
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 760
diff changeset
504 if (info == jobs_.end())
fc97f762834c scheduler
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 760
diff changeset
505 {
fc97f762834c scheduler
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 760
diff changeset
506 throw OrthancException(ErrorCode_InternalError);
fc97f762834c scheduler
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 760
diff changeset
507 }
fc97f762834c scheduler
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 760
diff changeset
508
fc97f762834c scheduler
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 760
diff changeset
509 return info->second;
fc97f762834c scheduler
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 760
diff changeset
510 }
fc97f762834c scheduler
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 760
diff changeset
511
fc97f762834c scheduler
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 760
diff changeset
512 virtual void SignalSuccess(const std::string& jobId)
fc97f762834c scheduler
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 760
diff changeset
513 {
fc97f762834c scheduler
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 760
diff changeset
514 boost::mutex::scoped_lock lock(mutex_);
fc97f762834c scheduler
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 760
diff changeset
515
fc97f762834c scheduler
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 760
diff changeset
516 JobInfo& info = GetJobInfo(jobId);
fc97f762834c scheduler
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 760
diff changeset
517 info.success_++;
fc97f762834c scheduler
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 760
diff changeset
518
fc97f762834c scheduler
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 760
diff changeset
519 assert(info.failures_ == 0);
fc97f762834c scheduler
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 760
diff changeset
520
fc97f762834c scheduler
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 760
diff changeset
521 if (info.success_ >= info.size_)
fc97f762834c scheduler
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 760
diff changeset
522 {
fc97f762834c scheduler
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 760
diff changeset
523 if (info.watched_)
fc97f762834c scheduler
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 760
diff changeset
524 {
768
476febedc516 improvements
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 765
diff changeset
525 watchedJobStatus_[jobId] = JobStatus_Success;
765
fc97f762834c scheduler
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 760
diff changeset
526 jobFinished_.notify_all();
fc97f762834c scheduler
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 760
diff changeset
527 }
fc97f762834c scheduler
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 760
diff changeset
528
fc97f762834c scheduler
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 760
diff changeset
529 LOG(INFO) << "Job successfully finished (" << info.description_ << ")";
fc97f762834c scheduler
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 760
diff changeset
530 jobs_.erase(jobId);
fc97f762834c scheduler
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 760
diff changeset
531 }
fc97f762834c scheduler
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 760
diff changeset
532 }
fc97f762834c scheduler
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 760
diff changeset
533
fc97f762834c scheduler
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 760
diff changeset
534 virtual void SignalFailure(const std::string& jobId)
fc97f762834c scheduler
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 760
diff changeset
535 {
fc97f762834c scheduler
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 760
diff changeset
536 boost::mutex::scoped_lock lock(mutex_);
fc97f762834c scheduler
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 760
diff changeset
537
fc97f762834c scheduler
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 760
diff changeset
538 JobInfo& info = GetJobInfo(jobId);
fc97f762834c scheduler
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 760
diff changeset
539 info.failures_++;
fc97f762834c scheduler
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 760
diff changeset
540
fc97f762834c scheduler
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 760
diff changeset
541 if (info.success_ + info.failures_ >= info.size_)
fc97f762834c scheduler
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 760
diff changeset
542 {
fc97f762834c scheduler
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 760
diff changeset
543 if (info.watched_)
fc97f762834c scheduler
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 760
diff changeset
544 {
768
476febedc516 improvements
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 765
diff changeset
545 watchedJobStatus_[jobId] = JobStatus_Failure;
765
fc97f762834c scheduler
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 760
diff changeset
546 jobFinished_.notify_all();
fc97f762834c scheduler
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 760
diff changeset
547 }
fc97f762834c scheduler
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 760
diff changeset
548
fc97f762834c scheduler
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 760
diff changeset
549 LOG(ERROR) << "Job has failed (" << info.description_ << ")";
fc97f762834c scheduler
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 760
diff changeset
550 jobs_.erase(jobId);
fc97f762834c scheduler
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 760
diff changeset
551 }
fc97f762834c scheduler
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 760
diff changeset
552 }
fc97f762834c scheduler
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 760
diff changeset
553
fc97f762834c scheduler
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 760
diff changeset
554 static void Worker(ServerScheduler* that)
fc97f762834c scheduler
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 760
diff changeset
555 {
fc97f762834c scheduler
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 760
diff changeset
556 static const int32_t TIMEOUT = 100;
fc97f762834c scheduler
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 760
diff changeset
557
fc97f762834c scheduler
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 760
diff changeset
558 while (!that->finish_)
fc97f762834c scheduler
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 760
diff changeset
559 {
fc97f762834c scheduler
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 760
diff changeset
560 std::auto_ptr<IDynamicObject> object(that->queue_.Dequeue(TIMEOUT));
fc97f762834c scheduler
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 760
diff changeset
561 if (object.get() != NULL)
fc97f762834c scheduler
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 760
diff changeset
562 {
fc97f762834c scheduler
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 760
diff changeset
563 FilterWrapper& filter = dynamic_cast<FilterWrapper&>(*object);
fc97f762834c scheduler
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 760
diff changeset
564
fc97f762834c scheduler
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 760
diff changeset
565 // Skip the execution of this filter if its parent job has
fc97f762834c scheduler
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 760
diff changeset
566 // previously failed.
fc97f762834c scheduler
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 760
diff changeset
567 bool jobHasFailed;
fc97f762834c scheduler
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 760
diff changeset
568 {
fc97f762834c scheduler
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 760
diff changeset
569 boost::mutex::scoped_lock lock(that->mutex_);
fc97f762834c scheduler
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 760
diff changeset
570 JobInfo& info = that->GetJobInfo(filter.GetJobId());
fc97f762834c scheduler
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 760
diff changeset
571 jobHasFailed = (info.failures_ > 0 || info.cancel_);
fc97f762834c scheduler
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 760
diff changeset
572 }
fc97f762834c scheduler
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 760
diff changeset
573
fc97f762834c scheduler
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 760
diff changeset
574 if (jobHasFailed)
fc97f762834c scheduler
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 760
diff changeset
575 {
fc97f762834c scheduler
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 760
diff changeset
576 that->SignalFailure(filter.GetJobId());
fc97f762834c scheduler
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 760
diff changeset
577 }
fc97f762834c scheduler
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 760
diff changeset
578 else
fc97f762834c scheduler
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 760
diff changeset
579 {
768
476febedc516 improvements
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 765
diff changeset
580 filter.Execute(*that);
765
fc97f762834c scheduler
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 760
diff changeset
581 }
fc97f762834c scheduler
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 760
diff changeset
582 }
fc97f762834c scheduler
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 760
diff changeset
583 }
fc97f762834c scheduler
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 760
diff changeset
584 }
fc97f762834c scheduler
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 760
diff changeset
585
fc97f762834c scheduler
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 760
diff changeset
586 void SubmitInternal(ServerJob& job,
fc97f762834c scheduler
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 760
diff changeset
587 bool watched)
fc97f762834c scheduler
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 760
diff changeset
588 {
fc97f762834c scheduler
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 760
diff changeset
589 boost::mutex::scoped_lock lock(mutex_);
fc97f762834c scheduler
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 760
diff changeset
590
fc97f762834c scheduler
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 760
diff changeset
591 JobInfo info;
fc97f762834c scheduler
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 760
diff changeset
592 info.size_ = job.Submit(queue_, *this);
fc97f762834c scheduler
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 760
diff changeset
593 info.cancel_ = false;
fc97f762834c scheduler
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 760
diff changeset
594 info.success_ = 0;
fc97f762834c scheduler
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 760
diff changeset
595 info.failures_ = 0;
fc97f762834c scheduler
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 760
diff changeset
596 info.description_ = job.GetDescription();
fc97f762834c scheduler
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 760
diff changeset
597 info.watched_ = watched;
fc97f762834c scheduler
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 760
diff changeset
598
fc97f762834c scheduler
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 760
diff changeset
599 assert(info.size_ > 0);
fc97f762834c scheduler
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 760
diff changeset
600
fc97f762834c scheduler
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 760
diff changeset
601 if (watched)
fc97f762834c scheduler
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 760
diff changeset
602 {
768
476febedc516 improvements
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 765
diff changeset
603 watchedJobStatus_[job.GetId()] = JobStatus_Running;
765
fc97f762834c scheduler
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 760
diff changeset
604 }
fc97f762834c scheduler
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 760
diff changeset
605
fc97f762834c scheduler
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 760
diff changeset
606 jobs_[job.GetId()] = info;
fc97f762834c scheduler
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 760
diff changeset
607
fc97f762834c scheduler
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 760
diff changeset
608 LOG(INFO) << "New job submitted (" << job.description_ << ")";
fc97f762834c scheduler
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 760
diff changeset
609 }
fc97f762834c scheduler
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 760
diff changeset
610
fc97f762834c scheduler
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 760
diff changeset
611 public:
fc97f762834c scheduler
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 760
diff changeset
612 ServerScheduler()
fc97f762834c scheduler
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 760
diff changeset
613 {
fc97f762834c scheduler
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 760
diff changeset
614 finish_ = false;
fc97f762834c scheduler
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 760
diff changeset
615 worker_ = boost::thread(Worker, this);
fc97f762834c scheduler
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 760
diff changeset
616 }
fc97f762834c scheduler
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 760
diff changeset
617
fc97f762834c scheduler
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 760
diff changeset
618 ~ServerScheduler()
fc97f762834c scheduler
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 760
diff changeset
619 {
fc97f762834c scheduler
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 760
diff changeset
620 finish_ = true;
fc97f762834c scheduler
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 760
diff changeset
621 worker_.join();
fc97f762834c scheduler
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 760
diff changeset
622 }
fc97f762834c scheduler
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 760
diff changeset
623
fc97f762834c scheduler
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 760
diff changeset
624 void Submit(ServerJob& job)
fc97f762834c scheduler
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 760
diff changeset
625 {
fc97f762834c scheduler
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 760
diff changeset
626 if (job.filters_.empty())
fc97f762834c scheduler
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 760
diff changeset
627 {
fc97f762834c scheduler
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 760
diff changeset
628 return;
fc97f762834c scheduler
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 760
diff changeset
629 }
fc97f762834c scheduler
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 760
diff changeset
630
fc97f762834c scheduler
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 760
diff changeset
631 SubmitInternal(job, false);
fc97f762834c scheduler
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 760
diff changeset
632 }
fc97f762834c scheduler
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 760
diff changeset
633
fc97f762834c scheduler
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 760
diff changeset
634 bool SubmitAndWait(ListOfStrings& outputs,
fc97f762834c scheduler
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 760
diff changeset
635 ServerJob& job)
fc97f762834c scheduler
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 760
diff changeset
636 {
fc97f762834c scheduler
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 760
diff changeset
637 std::string jobId = job.GetId();
fc97f762834c scheduler
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 760
diff changeset
638
fc97f762834c scheduler
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 760
diff changeset
639 outputs.clear();
fc97f762834c scheduler
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 760
diff changeset
640
fc97f762834c scheduler
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 760
diff changeset
641 if (job.filters_.empty())
fc97f762834c scheduler
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 760
diff changeset
642 {
fc97f762834c scheduler
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 760
diff changeset
643 return true;
fc97f762834c scheduler
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 760
diff changeset
644 }
fc97f762834c scheduler
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 760
diff changeset
645
fc97f762834c scheduler
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 760
diff changeset
646 // Add a sink filter to collect all the results of the filters
fc97f762834c scheduler
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 760
diff changeset
647 // that have no next filter.
fc97f762834c scheduler
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 760
diff changeset
648 FilterWrapper& sink = job.AddFilter(new Sink(outputs));
fc97f762834c scheduler
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 760
diff changeset
649
fc97f762834c scheduler
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 760
diff changeset
650 for (std::list<FilterWrapper*>::iterator
fc97f762834c scheduler
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 760
diff changeset
651 it = job.filters_.begin(); it != job.filters_.end(); it++)
fc97f762834c scheduler
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 760
diff changeset
652 {
fc97f762834c scheduler
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 760
diff changeset
653 if ((*it) != &sink &&
fc97f762834c scheduler
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 760
diff changeset
654 (*it)->GetNextFilters().size() == 0)
fc97f762834c scheduler
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 760
diff changeset
655 {
fc97f762834c scheduler
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 760
diff changeset
656 (*it)->ConnectNext(sink);
fc97f762834c scheduler
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 760
diff changeset
657 }
fc97f762834c scheduler
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 760
diff changeset
658 }
fc97f762834c scheduler
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 760
diff changeset
659
fc97f762834c scheduler
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 760
diff changeset
660 // Submit the job
fc97f762834c scheduler
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 760
diff changeset
661 SubmitInternal(job, true);
fc97f762834c scheduler
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 760
diff changeset
662
fc97f762834c scheduler
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 760
diff changeset
663 // Wait for the job to complete (either success or failure)
768
476febedc516 improvements
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 765
diff changeset
664 JobStatus status;
765
fc97f762834c scheduler
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 760
diff changeset
665
fc97f762834c scheduler
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 760
diff changeset
666 {
fc97f762834c scheduler
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 760
diff changeset
667 boost::mutex::scoped_lock lock(mutex_);
768
476febedc516 improvements
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 765
diff changeset
668
476febedc516 improvements
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 765
diff changeset
669 assert(watchedJobStatus_.find(jobId) != watchedJobStatus_.end());
765
fc97f762834c scheduler
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 760
diff changeset
670
768
476febedc516 improvements
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 765
diff changeset
671 while (watchedJobStatus_[jobId] == JobStatus_Running)
765
fc97f762834c scheduler
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 760
diff changeset
672 {
fc97f762834c scheduler
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 760
diff changeset
673 jobFinished_.wait(lock);
fc97f762834c scheduler
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 760
diff changeset
674 }
fc97f762834c scheduler
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 760
diff changeset
675
fc97f762834c scheduler
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 760
diff changeset
676 status = watchedJobStatus_[jobId];
fc97f762834c scheduler
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 760
diff changeset
677 watchedJobStatus_.erase(jobId);
fc97f762834c scheduler
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 760
diff changeset
678 }
fc97f762834c scheduler
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 760
diff changeset
679
768
476febedc516 improvements
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 765
diff changeset
680 return (status == JobStatus_Success);
765
fc97f762834c scheduler
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 760
diff changeset
681 }
fc97f762834c scheduler
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 760
diff changeset
682
fc97f762834c scheduler
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 760
diff changeset
683
fc97f762834c scheduler
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 760
diff changeset
684 bool IsRunning(const std::string& jobId)
fc97f762834c scheduler
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 760
diff changeset
685 {
fc97f762834c scheduler
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 760
diff changeset
686 boost::mutex::scoped_lock lock(mutex_);
fc97f762834c scheduler
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 760
diff changeset
687 return jobs_.find(jobId) != jobs_.end();
fc97f762834c scheduler
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 760
diff changeset
688 }
fc97f762834c scheduler
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 760
diff changeset
689
fc97f762834c scheduler
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 760
diff changeset
690
fc97f762834c scheduler
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 760
diff changeset
691 void Cancel(const std::string& jobId)
fc97f762834c scheduler
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 760
diff changeset
692 {
fc97f762834c scheduler
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 760
diff changeset
693 boost::mutex::scoped_lock lock(mutex_);
fc97f762834c scheduler
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 760
diff changeset
694
fc97f762834c scheduler
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 760
diff changeset
695 Jobs::iterator job = jobs_.find(jobId);
fc97f762834c scheduler
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 760
diff changeset
696
fc97f762834c scheduler
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 760
diff changeset
697 if (job != jobs_.end())
fc97f762834c scheduler
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 760
diff changeset
698 {
fc97f762834c scheduler
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 760
diff changeset
699 job->second.cancel_ = true;
fc97f762834c scheduler
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 760
diff changeset
700 LOG(WARNING) << "Canceling a job (" << job->second.description_ << ")";
fc97f762834c scheduler
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 760
diff changeset
701 }
fc97f762834c scheduler
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 760
diff changeset
702 }
fc97f762834c scheduler
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 760
diff changeset
703
fc97f762834c scheduler
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 760
diff changeset
704
fc97f762834c scheduler
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 760
diff changeset
705 // Returns a number between 0 and 1
fc97f762834c scheduler
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 760
diff changeset
706 float GetProgress(const std::string& jobId)
fc97f762834c scheduler
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 760
diff changeset
707 {
fc97f762834c scheduler
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 760
diff changeset
708 boost::mutex::scoped_lock lock(mutex_);
fc97f762834c scheduler
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 760
diff changeset
709
fc97f762834c scheduler
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 760
diff changeset
710 Jobs::iterator job = jobs_.find(jobId);
fc97f762834c scheduler
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 760
diff changeset
711
fc97f762834c scheduler
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 760
diff changeset
712 if (job == jobs_.end() ||
fc97f762834c scheduler
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 760
diff changeset
713 job->second.size_ == 0 /* should never happen */)
fc97f762834c scheduler
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 760
diff changeset
714 {
fc97f762834c scheduler
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 760
diff changeset
715 // This job is not running
fc97f762834c scheduler
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 760
diff changeset
716 return 1;
fc97f762834c scheduler
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 760
diff changeset
717 }
fc97f762834c scheduler
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 760
diff changeset
718
768
476febedc516 improvements
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 765
diff changeset
719 if (job->second.failures_ != 0)
476febedc516 improvements
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 765
diff changeset
720 {
476febedc516 improvements
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 765
diff changeset
721 return 1;
476febedc516 improvements
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 765
diff changeset
722 }
476febedc516 improvements
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 765
diff changeset
723
476febedc516 improvements
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 765
diff changeset
724 if (job->second.size_ == 1)
476febedc516 improvements
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 765
diff changeset
725 {
476febedc516 improvements
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 765
diff changeset
726 return job->second.success_;
476febedc516 improvements
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 765
diff changeset
727 }
476febedc516 improvements
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 765
diff changeset
728
476febedc516 improvements
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 765
diff changeset
729 return (static_cast<float>(job->second.success_) /
476febedc516 improvements
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 765
diff changeset
730 static_cast<float>(job->second.size_ - 1));
765
fc97f762834c scheduler
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 760
diff changeset
731 }
fc97f762834c scheduler
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 760
diff changeset
732
fc97f762834c scheduler
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 760
diff changeset
733 bool IsRunning(const ServerJob& job)
fc97f762834c scheduler
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 760
diff changeset
734 {
fc97f762834c scheduler
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 760
diff changeset
735 return IsRunning(job.GetId());
fc97f762834c scheduler
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 760
diff changeset
736 }
fc97f762834c scheduler
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 760
diff changeset
737
fc97f762834c scheduler
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 760
diff changeset
738 void Cancel(const ServerJob& job)
fc97f762834c scheduler
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 760
diff changeset
739 {
fc97f762834c scheduler
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 760
diff changeset
740 Cancel(job.GetId());
fc97f762834c scheduler
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 760
diff changeset
741 }
fc97f762834c scheduler
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 760
diff changeset
742
fc97f762834c scheduler
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 760
diff changeset
743 float GetProgress(const ServerJob& job)
fc97f762834c scheduler
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 760
diff changeset
744 {
fc97f762834c scheduler
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 760
diff changeset
745 return GetProgress(job);
fc97f762834c scheduler
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 760
diff changeset
746 }
768
476febedc516 improvements
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 765
diff changeset
747
476febedc516 improvements
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 765
diff changeset
748 void GetListOfJobs(ListOfStrings& jobs)
476febedc516 improvements
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 765
diff changeset
749 {
476febedc516 improvements
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 765
diff changeset
750 boost::mutex::scoped_lock lock(mutex_);
476febedc516 improvements
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 765
diff changeset
751
476febedc516 improvements
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 765
diff changeset
752 jobs.clear();
476febedc516 improvements
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 765
diff changeset
753
476febedc516 improvements
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 765
diff changeset
754 for (Jobs::const_iterator
476febedc516 improvements
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 765
diff changeset
755 it = jobs_.begin(); it != jobs_.end(); it++)
476febedc516 improvements
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 765
diff changeset
756 {
476febedc516 improvements
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 765
diff changeset
757 jobs.push_back(it->first);
476febedc516 improvements
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 765
diff changeset
758 }
476febedc516 improvements
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 765
diff changeset
759 }
765
fc97f762834c scheduler
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 760
diff changeset
760 };
fc97f762834c scheduler
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 760
diff changeset
761
fc97f762834c scheduler
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 760
diff changeset
762 }
fc97f762834c scheduler
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 760
diff changeset
763
fc97f762834c scheduler
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 760
diff changeset
764
fc97f762834c scheduler
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 760
diff changeset
765
fc97f762834c scheduler
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 760
diff changeset
766 class Tutu : public IServerFilter
fc97f762834c scheduler
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 760
diff changeset
767 {
fc97f762834c scheduler
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 760
diff changeset
768 private:
fc97f762834c scheduler
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 760
diff changeset
769 int factor_;
fc97f762834c scheduler
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 760
diff changeset
770
fc97f762834c scheduler
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 760
diff changeset
771 public:
fc97f762834c scheduler
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 760
diff changeset
772 Tutu(int f) : factor_(f)
fc97f762834c scheduler
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 760
diff changeset
773 {
fc97f762834c scheduler
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 760
diff changeset
774 }
fc97f762834c scheduler
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 760
diff changeset
775
fc97f762834c scheduler
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 760
diff changeset
776 virtual bool Apply(ListOfStrings& outputs,
fc97f762834c scheduler
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 760
diff changeset
777 const ListOfStrings& inputs)
fc97f762834c scheduler
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 760
diff changeset
778 {
fc97f762834c scheduler
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 760
diff changeset
779 for (ListOfStrings::const_iterator
fc97f762834c scheduler
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 760
diff changeset
780 it = inputs.begin(); it != inputs.end(); it++)
fc97f762834c scheduler
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 760
diff changeset
781 {
fc97f762834c scheduler
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 760
diff changeset
782 int a = boost::lexical_cast<int>(*it);
fc97f762834c scheduler
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 760
diff changeset
783 int b = factor_ * a;
fc97f762834c scheduler
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 760
diff changeset
784
fc97f762834c scheduler
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 760
diff changeset
785 printf("%d * %d = %d\n", a, factor_, b);
fc97f762834c scheduler
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 760
diff changeset
786
fc97f762834c scheduler
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 760
diff changeset
787 //if (a == 84) { printf("BREAK\n"); return false; }
fc97f762834c scheduler
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 760
diff changeset
788
fc97f762834c scheduler
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 760
diff changeset
789 outputs.push_back(boost::lexical_cast<std::string>(b));
fc97f762834c scheduler
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 760
diff changeset
790 }
fc97f762834c scheduler
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 760
diff changeset
791
fc97f762834c scheduler
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 760
diff changeset
792 Toolbox::USleep(1000000);
fc97f762834c scheduler
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 760
diff changeset
793
fc97f762834c scheduler
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 760
diff changeset
794 return true;
fc97f762834c scheduler
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 760
diff changeset
795 }
fc97f762834c scheduler
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 760
diff changeset
796 };
fc97f762834c scheduler
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 760
diff changeset
797
768
476febedc516 improvements
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 765
diff changeset
798
476febedc516 improvements
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 765
diff changeset
799 static void Tata(ServerScheduler* s, ServerJob* j)
476febedc516 improvements
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 765
diff changeset
800 {
476febedc516 improvements
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 765
diff changeset
801 #if 1
476febedc516 improvements
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 765
diff changeset
802 for (;;)
476febedc516 improvements
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 765
diff changeset
803 {
476febedc516 improvements
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 765
diff changeset
804 ListOfStrings l;
476febedc516 improvements
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 765
diff changeset
805 s->GetListOfJobs(l);
476febedc516 improvements
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 765
diff changeset
806 for (ListOfStrings::iterator i = l.begin(); i != l.end(); i++)
476febedc516 improvements
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 765
diff changeset
807 printf(">> %s: %0.1f\n", i->c_str(), 100.0f * s->GetProgress(*i));
476febedc516 improvements
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 765
diff changeset
808 Toolbox::USleep(100000);
476febedc516 improvements
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 765
diff changeset
809 }
476febedc516 improvements
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 765
diff changeset
810 #else
476febedc516 improvements
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 765
diff changeset
811 ListOfStrings l;
476febedc516 improvements
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 765
diff changeset
812 s->GetListOfJobs(l);
476febedc516 improvements
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 765
diff changeset
813 for (ListOfStrings::iterator i = l.begin(); i != l.end(); i++)
476febedc516 improvements
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 765
diff changeset
814 printf(">> %s\n", i->c_str());
476febedc516 improvements
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 765
diff changeset
815 Toolbox::USleep(1500000);
476febedc516 improvements
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 765
diff changeset
816 s->Cancel(*j);
476febedc516 improvements
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 765
diff changeset
817 Toolbox::USleep(1000000);
476febedc516 improvements
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 765
diff changeset
818 s->GetListOfJobs(l);
476febedc516 improvements
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 765
diff changeset
819 for (ListOfStrings::iterator i = l.begin(); i != l.end(); i++)
476febedc516 improvements
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 765
diff changeset
820 printf(">> %s\n", i->c_str());
476febedc516 improvements
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 765
diff changeset
821 #endif
476febedc516 improvements
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 765
diff changeset
822 }
476febedc516 improvements
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 765
diff changeset
823
476febedc516 improvements
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 765
diff changeset
824
765
fc97f762834c scheduler
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 760
diff changeset
825 TEST(Toto, Toto)
fc97f762834c scheduler
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 760
diff changeset
826 {
fc97f762834c scheduler
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 760
diff changeset
827 ServerScheduler scheduler;
fc97f762834c scheduler
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 760
diff changeset
828
fc97f762834c scheduler
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 760
diff changeset
829 ServerJob job;
fc97f762834c scheduler
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 760
diff changeset
830 FilterWrapper& f2 = job.AddFilter(new Tutu(2));
fc97f762834c scheduler
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 760
diff changeset
831 FilterWrapper& f3 = job.AddFilter(new Tutu(3));
fc97f762834c scheduler
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 760
diff changeset
832 FilterWrapper& f4 = job.AddFilter(new Tutu(4));
768
476febedc516 improvements
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 765
diff changeset
833 FilterWrapper& f5 = job.AddFilter(new Tutu(5));
765
fc97f762834c scheduler
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 760
diff changeset
834 f2.AddInput(boost::lexical_cast<std::string>(42));
fc97f762834c scheduler
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 760
diff changeset
835 //f3.AddInput(boost::lexical_cast<std::string>(42));
fc97f762834c scheduler
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 760
diff changeset
836 //f4.AddInput(boost::lexical_cast<std::string>(42));
fc97f762834c scheduler
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 760
diff changeset
837 f2.ConnectNext(f3);
fc97f762834c scheduler
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 760
diff changeset
838 f3.ConnectNext(f4);
768
476febedc516 improvements
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 765
diff changeset
839 f4.ConnectNext(f5);
765
fc97f762834c scheduler
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 760
diff changeset
840
fc97f762834c scheduler
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 760
diff changeset
841 job.SetDescription("tutu");
fc97f762834c scheduler
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 760
diff changeset
842
768
476febedc516 improvements
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 765
diff changeset
843 boost::thread t(Tata, &scheduler, &job);
476febedc516 improvements
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 765
diff changeset
844
476febedc516 improvements
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 765
diff changeset
845
765
fc97f762834c scheduler
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 760
diff changeset
846 //scheduler.Submit(job);
fc97f762834c scheduler
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 760
diff changeset
847
fc97f762834c scheduler
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 760
diff changeset
848 ListOfStrings l;
fc97f762834c scheduler
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 760
diff changeset
849 scheduler.SubmitAndWait(l, job);
fc97f762834c scheduler
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 760
diff changeset
850
fc97f762834c scheduler
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 760
diff changeset
851 for (ListOfStrings::iterator i = l.begin(); i != l.end(); i++)
fc97f762834c scheduler
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 760
diff changeset
852 {
fc97f762834c scheduler
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 760
diff changeset
853 printf("** %s\n", i->c_str());
fc97f762834c scheduler
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 760
diff changeset
854 }
fc97f762834c scheduler
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 760
diff changeset
855
fc97f762834c scheduler
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 760
diff changeset
856 //Toolbox::ServerBarrier();
768
476febedc516 improvements
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 765
diff changeset
857 //Toolbox::USleep(3000000);
476febedc516 improvements
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 765
diff changeset
858
476febedc516 improvements
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 765
diff changeset
859 //t.join();
765
fc97f762834c scheduler
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 760
diff changeset
860 }