annotate Core/MultiThreading/ArrayFilledByThreads.cpp @ 610:5ba825b87b21 find-move-scp

fix static build
author Sebastien Jodogne <s.jodogne@gmail.com>
date Fri, 18 Oct 2013 10:32:12 +0200
parents 0cd977e94479
children a811bdf8b8eb
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
479
0cd977e94479 initial commit of the c++ client
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1 #include "ArrayFilledByThreads.h"
0cd977e94479 initial commit of the c++ client
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2
0cd977e94479 initial commit of the c++ client
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3 #include "../MultiThreading/ThreadedCommandProcessor.h"
0cd977e94479 initial commit of the c++ client
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
4 #include "../OrthancException.h"
0cd977e94479 initial commit of the c++ client
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
5
0cd977e94479 initial commit of the c++ client
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
6 namespace Orthanc
0cd977e94479 initial commit of the c++ client
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
7 {
0cd977e94479 initial commit of the c++ client
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
8 class ArrayFilledByThreads::Command : public ICommand
0cd977e94479 initial commit of the c++ client
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
9 {
0cd977e94479 initial commit of the c++ client
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
10 private:
0cd977e94479 initial commit of the c++ client
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
11 ArrayFilledByThreads& that_;
0cd977e94479 initial commit of the c++ client
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
12 size_t index_;
0cd977e94479 initial commit of the c++ client
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
13
0cd977e94479 initial commit of the c++ client
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
14 public:
0cd977e94479 initial commit of the c++ client
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
15 Command(ArrayFilledByThreads& that,
0cd977e94479 initial commit of the c++ client
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
16 size_t index) :
0cd977e94479 initial commit of the c++ client
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
17 that_(that),
0cd977e94479 initial commit of the c++ client
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
18 index_(index)
0cd977e94479 initial commit of the c++ client
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
19 {
0cd977e94479 initial commit of the c++ client
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
20 }
0cd977e94479 initial commit of the c++ client
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
21
0cd977e94479 initial commit of the c++ client
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
22 virtual bool Execute()
0cd977e94479 initial commit of the c++ client
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
23 {
0cd977e94479 initial commit of the c++ client
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
24 std::auto_ptr<IDynamicObject> obj(that_.filler_.GetFillerItem(index_));
0cd977e94479 initial commit of the c++ client
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
25 if (obj.get() == NULL)
0cd977e94479 initial commit of the c++ client
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
26 {
0cd977e94479 initial commit of the c++ client
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
27 return false;
0cd977e94479 initial commit of the c++ client
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
28 }
0cd977e94479 initial commit of the c++ client
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
29 else
0cd977e94479 initial commit of the c++ client
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
30 {
0cd977e94479 initial commit of the c++ client
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
31 boost::mutex::scoped_lock lock(that_.mutex_);
0cd977e94479 initial commit of the c++ client
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
32 that_.array_[index_] = obj.release();
0cd977e94479 initial commit of the c++ client
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
33 return true;
0cd977e94479 initial commit of the c++ client
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
34 }
0cd977e94479 initial commit of the c++ client
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
35 }
0cd977e94479 initial commit of the c++ client
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
36 };
0cd977e94479 initial commit of the c++ client
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
37
0cd977e94479 initial commit of the c++ client
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
38 void ArrayFilledByThreads::Clear()
0cd977e94479 initial commit of the c++ client
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
39 {
0cd977e94479 initial commit of the c++ client
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
40 for (size_t i = 0; i < array_.size(); i++)
0cd977e94479 initial commit of the c++ client
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
41 {
0cd977e94479 initial commit of the c++ client
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
42 if (array_[i])
0cd977e94479 initial commit of the c++ client
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
43 delete array_[i];
0cd977e94479 initial commit of the c++ client
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
44 }
0cd977e94479 initial commit of the c++ client
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
45
0cd977e94479 initial commit of the c++ client
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
46 array_.clear();
0cd977e94479 initial commit of the c++ client
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
47 filled_ = false;
0cd977e94479 initial commit of the c++ client
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
48 }
0cd977e94479 initial commit of the c++ client
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
49
0cd977e94479 initial commit of the c++ client
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
50 void ArrayFilledByThreads::Update()
0cd977e94479 initial commit of the c++ client
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
51 {
0cd977e94479 initial commit of the c++ client
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
52 if (!filled_)
0cd977e94479 initial commit of the c++ client
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
53 {
0cd977e94479 initial commit of the c++ client
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
54 array_.resize(filler_.GetFillerSize());
0cd977e94479 initial commit of the c++ client
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
55
0cd977e94479 initial commit of the c++ client
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
56 Orthanc::ThreadedCommandProcessor processor(threadCount_);
0cd977e94479 initial commit of the c++ client
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
57 for (size_t i = 0; i < array_.size(); i++)
0cd977e94479 initial commit of the c++ client
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
58 {
0cd977e94479 initial commit of the c++ client
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
59 processor.Post(new Command(*this, i));
0cd977e94479 initial commit of the c++ client
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
60 }
0cd977e94479 initial commit of the c++ client
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
61
0cd977e94479 initial commit of the c++ client
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
62 processor.Join();
0cd977e94479 initial commit of the c++ client
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
63 filled_ = true;
0cd977e94479 initial commit of the c++ client
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
64 }
0cd977e94479 initial commit of the c++ client
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
65 }
0cd977e94479 initial commit of the c++ client
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
66
0cd977e94479 initial commit of the c++ client
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
67
0cd977e94479 initial commit of the c++ client
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
68 ArrayFilledByThreads::ArrayFilledByThreads(IFiller& filler) : filler_(filler)
0cd977e94479 initial commit of the c++ client
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
69 {
0cd977e94479 initial commit of the c++ client
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
70 filled_ = false;
0cd977e94479 initial commit of the c++ client
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
71 threadCount_ = 4;
0cd977e94479 initial commit of the c++ client
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
72 }
0cd977e94479 initial commit of the c++ client
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
73
0cd977e94479 initial commit of the c++ client
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
74
0cd977e94479 initial commit of the c++ client
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
75 ArrayFilledByThreads::~ArrayFilledByThreads()
0cd977e94479 initial commit of the c++ client
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
76 {
0cd977e94479 initial commit of the c++ client
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
77 Clear();
0cd977e94479 initial commit of the c++ client
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
78 }
0cd977e94479 initial commit of the c++ client
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
79
0cd977e94479 initial commit of the c++ client
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
80
0cd977e94479 initial commit of the c++ client
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
81 void ArrayFilledByThreads::Reload()
0cd977e94479 initial commit of the c++ client
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
82 {
0cd977e94479 initial commit of the c++ client
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
83 Clear();
0cd977e94479 initial commit of the c++ client
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
84 Update();
0cd977e94479 initial commit of the c++ client
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
85 }
0cd977e94479 initial commit of the c++ client
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
86
0cd977e94479 initial commit of the c++ client
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
87
0cd977e94479 initial commit of the c++ client
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
88 void ArrayFilledByThreads::Invalidate()
0cd977e94479 initial commit of the c++ client
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
89 {
0cd977e94479 initial commit of the c++ client
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
90 Clear();
0cd977e94479 initial commit of the c++ client
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
91 }
0cd977e94479 initial commit of the c++ client
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
92
0cd977e94479 initial commit of the c++ client
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
93
0cd977e94479 initial commit of the c++ client
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
94 void ArrayFilledByThreads::SetThreadCount(unsigned int t)
0cd977e94479 initial commit of the c++ client
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
95 {
0cd977e94479 initial commit of the c++ client
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
96 if (t < 1)
0cd977e94479 initial commit of the c++ client
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
97 {
0cd977e94479 initial commit of the c++ client
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
98 throw OrthancException(ErrorCode_ParameterOutOfRange);
0cd977e94479 initial commit of the c++ client
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
99 }
0cd977e94479 initial commit of the c++ client
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
100
0cd977e94479 initial commit of the c++ client
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
101 threadCount_ = t;
0cd977e94479 initial commit of the c++ client
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
102 }
0cd977e94479 initial commit of the c++ client
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
103
0cd977e94479 initial commit of the c++ client
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
104
0cd977e94479 initial commit of the c++ client
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
105 size_t ArrayFilledByThreads::GetSize()
0cd977e94479 initial commit of the c++ client
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
106 {
0cd977e94479 initial commit of the c++ client
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
107 Update();
0cd977e94479 initial commit of the c++ client
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
108 return array_.size();
0cd977e94479 initial commit of the c++ client
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
109 }
0cd977e94479 initial commit of the c++ client
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
110
0cd977e94479 initial commit of the c++ client
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
111
0cd977e94479 initial commit of the c++ client
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
112 IDynamicObject& ArrayFilledByThreads::GetItem(size_t index)
0cd977e94479 initial commit of the c++ client
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
113 {
0cd977e94479 initial commit of the c++ client
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
114 if (index >= GetSize())
0cd977e94479 initial commit of the c++ client
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
115 {
0cd977e94479 initial commit of the c++ client
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
116 throw Orthanc::OrthancException(Orthanc::ErrorCode_ParameterOutOfRange);
0cd977e94479 initial commit of the c++ client
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
117 }
0cd977e94479 initial commit of the c++ client
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
118
0cd977e94479 initial commit of the c++ client
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
119 return *array_[index];
0cd977e94479 initial commit of the c++ client
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
120 }
0cd977e94479 initial commit of the c++ client
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
121 }