Mercurial > hg > orthanc
annotate OrthancFramework/Resources/Graveyard/Multithreading/BagOfTasksProcessor.h @ 4361:98f55e7df5ab
rollback incorrect removal for msvc2008
author | Sebastien Jodogne <s.jodogne@gmail.com> |
---|---|
date | Tue, 08 Dec 2020 19:10:46 +0100 |
parents | bf7b9edf6b81 |
children | d9473bd5ed43 |
rev | line source |
---|---|
1920 | 1 /** |
2 * Orthanc - A Lightweight, RESTful DICOM Store | |
3 * Copyright (C) 2012-2016 Sebastien Jodogne, Medical Physics | |
4 * Department, University Hospital of Liege, Belgium | |
3640
94f4a18a79cc
upgrade to year 2020
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3060
diff
changeset
|
5 * Copyright (C) 2017-2020 Osimis S.A., Belgium |
1920 | 6 * |
7 * This program is free software: you can redistribute it and/or | |
4119
bf7b9edf6b81
re-licensing the OrthancFramework to LGPL, in order to license Stone of Orthanc under LGPL
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4044
diff
changeset
|
8 * modify it under the terms of the GNU Lesser General Public License |
bf7b9edf6b81
re-licensing the OrthancFramework to LGPL, in order to license Stone of Orthanc under LGPL
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4044
diff
changeset
|
9 * as published by the Free Software Foundation, either version 3 of |
bf7b9edf6b81
re-licensing the OrthancFramework to LGPL, in order to license Stone of Orthanc under LGPL
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4044
diff
changeset
|
10 * the License, or (at your option) any later version. |
1920 | 11 * |
12 * This program is distributed in the hope that it will be useful, but | |
13 * WITHOUT ANY WARRANTY; without even the implied warranty of | |
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
4119
bf7b9edf6b81
re-licensing the OrthancFramework to LGPL, in order to license Stone of Orthanc under LGPL
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4044
diff
changeset
|
15 * Lesser General Public License for more details. |
1920 | 16 * |
4119
bf7b9edf6b81
re-licensing the OrthancFramework to LGPL, in order to license Stone of Orthanc under LGPL
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4044
diff
changeset
|
17 * You should have received a copy of the GNU Lesser General Public |
bf7b9edf6b81
re-licensing the OrthancFramework to LGPL, in order to license Stone of Orthanc under LGPL
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4044
diff
changeset
|
18 * License along with this program. If not, see |
bf7b9edf6b81
re-licensing the OrthancFramework to LGPL, in order to license Stone of Orthanc under LGPL
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4044
diff
changeset
|
19 * <http://www.gnu.org/licenses/>. |
1920 | 20 **/ |
21 | |
22 | |
23 #pragma once | |
24 | |
25 #include "BagOfTasks.h" | |
26 #include "SharedMessageQueue.h" | |
27 | |
28 #include <stdint.h> | |
29 #include <map> | |
30 | |
31 namespace Orthanc | |
32 { | |
33 class BagOfTasksProcessor : public boost::noncopyable | |
34 { | |
35 private: | |
36 enum BagStatus | |
37 { | |
38 BagStatus_Running, | |
39 BagStatus_Canceled, | |
40 BagStatus_Failed | |
41 }; | |
42 | |
43 | |
44 struct Bag | |
45 { | |
46 size_t size_; | |
47 size_t done_; | |
48 BagStatus status_; | |
49 | |
50 Bag() : | |
51 size_(0), | |
52 done_(0), | |
53 status_(BagStatus_Failed) | |
54 { | |
55 } | |
56 | |
2223 | 57 explicit Bag(size_t size) : |
58 size_(size), | |
59 done_(0), | |
60 status_(BagStatus_Running) | |
1920 | 61 { |
62 } | |
63 }; | |
64 | |
65 class Task; | |
66 | |
67 | |
68 typedef std::map<uint64_t, Bag> Bags; | |
69 typedef std::map<uint64_t, bool> ExitStatus; | |
70 | |
71 SharedMessageQueue queue_; | |
72 | |
73 boost::mutex mutex_; | |
74 uint64_t countBags_; | |
75 Bags bags_; | |
76 std::vector<boost::thread*> threads_; | |
77 ExitStatus exitStatus_; | |
78 bool continue_; | |
79 | |
80 boost::condition_variable bagFinished_; | |
81 | |
82 static void Worker(BagOfTasksProcessor* that); | |
83 | |
84 void Cancel(int64_t bag); | |
85 | |
86 bool Join(int64_t bag); | |
87 | |
88 float GetProgress(int64_t bag); | |
89 | |
2110
5b818f677dd6
fix in BagOfTasksProcessor
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1923
diff
changeset
|
90 void SignalProgress(Task& task, |
5b818f677dd6
fix in BagOfTasksProcessor
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1923
diff
changeset
|
91 Bag& bag); |
5b818f677dd6
fix in BagOfTasksProcessor
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1923
diff
changeset
|
92 |
1920 | 93 public: |
94 class Handle : public boost::noncopyable | |
95 { | |
96 friend class BagOfTasksProcessor; | |
97 | |
98 private: | |
99 BagOfTasksProcessor& that_; | |
100 uint64_t bag_; | |
101 bool hasJoined_; | |
102 bool status_; | |
103 | |
104 Handle(BagOfTasksProcessor& that, | |
1923
6ac7f31fc543
fix freeze if empty bag of tasks
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1920
diff
changeset
|
105 uint64_t bag, |
6ac7f31fc543
fix freeze if empty bag of tasks
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1920
diff
changeset
|
106 bool empty) : |
1920 | 107 that_(that), |
108 bag_(bag), | |
1923
6ac7f31fc543
fix freeze if empty bag of tasks
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1920
diff
changeset
|
109 hasJoined_(empty) |
1920 | 110 { |
111 } | |
112 | |
113 public: | |
114 ~Handle() | |
115 { | |
116 Join(); | |
117 } | |
118 | |
119 void Cancel() | |
120 { | |
121 that_.Cancel(bag_); | |
122 } | |
123 | |
124 bool Join(); | |
125 | |
126 float GetProgress() | |
127 { | |
128 return that_.GetProgress(bag_); | |
129 } | |
130 }; | |
131 | |
132 | |
2223 | 133 explicit BagOfTasksProcessor(size_t countThreads); |
1920 | 134 |
135 ~BagOfTasksProcessor(); | |
136 | |
137 Handle* Submit(BagOfTasks& tasks); | |
138 }; | |
139 } |