Mercurial > hg > orthanc
annotate OrthancFramework/Resources/Graveyard/Multithreading/BagOfTasksProcessor.h @ 5095:b52fe770aec0
more logs in HttpClient
author | Alain Mazy <am@osimis.io> |
---|---|
date | Wed, 12 Oct 2022 09:22:08 +0200 |
parents | 43e613a7756b |
children | 0ea402b4d901 |
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 | |
4870
43e613a7756b
upgrade to year 2022
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4831
diff
changeset
|
5 * Copyright (C) 2017-2022 Osimis S.A., Belgium |
43e613a7756b
upgrade to year 2022
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4831
diff
changeset
|
6 * Copyright (C) 2021-2022 Sebastien Jodogne, ICTEAM UCLouvain, Belgium |
1920 | 7 * |
8 * 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
|
9 * 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
|
10 * 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
|
11 * the License, or (at your option) any later version. |
1920 | 12 * |
13 * This program is distributed in the hope that it will be useful, but | |
14 * WITHOUT ANY WARRANTY; without even the implied warranty of | |
15 * 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
|
16 * Lesser General Public License for more details. |
1920 | 17 * |
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
|
18 * 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
|
19 * 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
|
20 * <http://www.gnu.org/licenses/>. |
1920 | 21 **/ |
22 | |
23 | |
24 #pragma once | |
25 | |
26 #include "BagOfTasks.h" | |
27 #include "SharedMessageQueue.h" | |
28 | |
29 #include <stdint.h> | |
30 #include <map> | |
31 | |
32 namespace Orthanc | |
33 { | |
34 class BagOfTasksProcessor : public boost::noncopyable | |
35 { | |
36 private: | |
37 enum BagStatus | |
38 { | |
39 BagStatus_Running, | |
40 BagStatus_Canceled, | |
41 BagStatus_Failed | |
42 }; | |
43 | |
44 | |
45 struct Bag | |
46 { | |
47 size_t size_; | |
48 size_t done_; | |
49 BagStatus status_; | |
50 | |
51 Bag() : | |
52 size_(0), | |
53 done_(0), | |
54 status_(BagStatus_Failed) | |
55 { | |
56 } | |
57 | |
2223 | 58 explicit Bag(size_t size) : |
59 size_(size), | |
60 done_(0), | |
61 status_(BagStatus_Running) | |
1920 | 62 { |
63 } | |
64 }; | |
65 | |
66 class Task; | |
67 | |
68 | |
69 typedef std::map<uint64_t, Bag> Bags; | |
70 typedef std::map<uint64_t, bool> ExitStatus; | |
71 | |
72 SharedMessageQueue queue_; | |
73 | |
74 boost::mutex mutex_; | |
75 uint64_t countBags_; | |
76 Bags bags_; | |
77 std::vector<boost::thread*> threads_; | |
78 ExitStatus exitStatus_; | |
79 bool continue_; | |
80 | |
81 boost::condition_variable bagFinished_; | |
82 | |
83 static void Worker(BagOfTasksProcessor* that); | |
84 | |
85 void Cancel(int64_t bag); | |
86 | |
87 bool Join(int64_t bag); | |
88 | |
89 float GetProgress(int64_t bag); | |
90 | |
2110
5b818f677dd6
fix in BagOfTasksProcessor
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1923
diff
changeset
|
91 void SignalProgress(Task& task, |
5b818f677dd6
fix in BagOfTasksProcessor
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1923
diff
changeset
|
92 Bag& bag); |
5b818f677dd6
fix in BagOfTasksProcessor
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1923
diff
changeset
|
93 |
1920 | 94 public: |
95 class Handle : public boost::noncopyable | |
96 { | |
97 friend class BagOfTasksProcessor; | |
98 | |
99 private: | |
100 BagOfTasksProcessor& that_; | |
101 uint64_t bag_; | |
102 bool hasJoined_; | |
103 bool status_; | |
104 | |
105 Handle(BagOfTasksProcessor& that, | |
1923
6ac7f31fc543
fix freeze if empty bag of tasks
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1920
diff
changeset
|
106 uint64_t bag, |
6ac7f31fc543
fix freeze if empty bag of tasks
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1920
diff
changeset
|
107 bool empty) : |
1920 | 108 that_(that), |
109 bag_(bag), | |
1923
6ac7f31fc543
fix freeze if empty bag of tasks
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1920
diff
changeset
|
110 hasJoined_(empty) |
1920 | 111 { |
112 } | |
113 | |
114 public: | |
115 ~Handle() | |
116 { | |
117 Join(); | |
118 } | |
119 | |
120 void Cancel() | |
121 { | |
122 that_.Cancel(bag_); | |
123 } | |
124 | |
125 bool Join(); | |
126 | |
127 float GetProgress() | |
128 { | |
129 return that_.GetProgress(bag_); | |
130 } | |
131 }; | |
132 | |
133 | |
2223 | 134 explicit BagOfTasksProcessor(size_t countThreads); |
1920 | 135 |
136 ~BagOfTasksProcessor(); | |
137 | |
138 Handle* Submit(BagOfTasks& tasks); | |
139 }; | |
140 } |