Mercurial > hg > orthanc
comparison Core/MultiThreading/BagOfTasksProcessor.cpp @ 2110:5b818f677dd6
fix in BagOfTasksProcessor
author | Sebastien Jodogne <s.jodogne@gmail.com> |
---|---|
date | Wed, 26 Oct 2016 15:36:39 +0200 |
parents | 0ae26237569a |
children | a3a65de1840f |
comparison
equal
deleted
inserted
replaced
2109:d5c29fd74ffa | 2110:5b818f677dd6 |
---|---|
31 | 31 |
32 | 32 |
33 #include "../PrecompiledHeaders.h" | 33 #include "../PrecompiledHeaders.h" |
34 #include "BagOfTasksProcessor.h" | 34 #include "BagOfTasksProcessor.h" |
35 | 35 |
36 #include "../Logging.h" | |
36 #include "../OrthancException.h" | 37 #include "../OrthancException.h" |
37 | 38 |
39 #include <stdio.h> | |
38 | 40 |
39 namespace Orthanc | 41 namespace Orthanc |
40 { | 42 { |
41 class BagOfTasksProcessor::Task : public IDynamicObject | 43 class BagOfTasksProcessor::Task : public IDynamicObject |
42 { | 44 { |
56 { | 58 { |
57 try | 59 try |
58 { | 60 { |
59 return command_->Execute(); | 61 return command_->Execute(); |
60 } | 62 } |
61 catch (OrthancException&) | 63 catch (OrthancException& e) |
62 { | 64 { |
65 LOG(ERROR) << "Exception while processing a bag of tasks: " << e.What(); | |
63 return false; | 66 return false; |
64 } | 67 } |
65 catch (std::runtime_error&) | 68 catch (std::runtime_error& e) |
66 { | 69 { |
70 LOG(ERROR) << "Runtime exception while processing a bag of tasks: " << e.what(); | |
67 return false; | 71 return false; |
68 } | 72 } |
73 catch (...) | |
74 { | |
75 LOG(ERROR) << "Native exception while processing a bag of tasks"; | |
76 return false; | |
77 } | |
69 } | 78 } |
70 | 79 |
71 uint64_t GetBag() | 80 uint64_t GetBag() |
72 { | 81 { |
73 return bag_; | 82 return bag_; |
74 } | 83 } |
75 }; | 84 }; |
76 | 85 |
86 | |
87 void BagOfTasksProcessor::SignalProgress(Task& task, | |
88 Bag& bag) | |
89 { | |
90 assert(bag.done_ < bag.size_); | |
91 | |
92 bag.done_ += 1; | |
93 | |
94 if (bag.done_ == bag.size_) | |
95 { | |
96 exitStatus_[task.GetBag()] = (bag.status_ == BagStatus_Running); | |
97 bagFinished_.notify_all(); | |
98 } | |
99 } | |
77 | 100 |
78 void BagOfTasksProcessor::Worker(BagOfTasksProcessor* that) | 101 void BagOfTasksProcessor::Worker(BagOfTasksProcessor* that) |
79 { | 102 { |
80 while (that->continue_) | 103 while (that->continue_) |
81 { | 104 { |
91 assert(bag != that->bags_.end()); | 114 assert(bag != that->bags_.end()); |
92 assert(bag->second.done_ < bag->second.size_); | 115 assert(bag->second.done_ < bag->second.size_); |
93 | 116 |
94 if (bag->second.status_ != BagStatus_Running) | 117 if (bag->second.status_ != BagStatus_Running) |
95 { | 118 { |
96 // This bag of task has failed or is tagged as canceled, do nothing | 119 // Do not execute this task, as its parent bag of tasks |
97 bag->second.done_ += 1; | 120 // has failed or is tagged as canceled |
121 that->SignalProgress(task, bag->second); | |
98 continue; | 122 continue; |
99 } | 123 } |
100 } | 124 } |
101 | 125 |
102 bool success = task.Execute(); | 126 bool success = task.Execute(); |
110 if (!success) | 134 if (!success) |
111 { | 135 { |
112 bag->second.status_ = BagStatus_Failed; | 136 bag->second.status_ = BagStatus_Failed; |
113 } | 137 } |
114 | 138 |
115 assert(bag->second.done_ < bag->second.size_); | 139 that->SignalProgress(task, bag->second); |
116 bag->second.done_ += 1; | |
117 | |
118 if (bag->second.done_ == bag->second.size_) | |
119 { | |
120 that->exitStatus_[task.GetBag()] = (bag->second.status_ == BagStatus_Running); | |
121 that->bagFinished_.notify_all(); | |
122 } | |
123 } | 140 } |
124 } | 141 } |
125 } | 142 } |
126 } | 143 } |
127 | 144 |