Mercurial > hg > orthanc-stone
comparison Platforms/Generic/Oracle.cpp @ 271:46c5296d867e am-2
OracleWebService and BasicSdlApplicationContext using the same global mutex
author | am@osimis.io |
---|---|
date | Thu, 23 Aug 2018 17:12:54 +0200 |
parents | 5412adf19980 |
children | 14ef1227120f |
comparison
equal
deleted
inserted
replaced
270:2d64f4d39610 | 271:46c5296d867e |
---|---|
25 #include <Core/MultiThreading/SharedMessageQueue.h> | 25 #include <Core/MultiThreading/SharedMessageQueue.h> |
26 #include <Core/OrthancException.h> | 26 #include <Core/OrthancException.h> |
27 | 27 |
28 #include <vector> | 28 #include <vector> |
29 #include <stdio.h> | 29 #include <stdio.h> |
30 #include <boost/thread/mutex.hpp> | |
30 | 31 |
31 namespace OrthancStone | 32 namespace OrthancStone |
32 { | 33 { |
33 class Oracle::PImpl | 34 class Oracle::PImpl |
34 { | 35 { |
38 State_Init, | 39 State_Init, |
39 State_Started, | 40 State_Started, |
40 State_Stopped | 41 State_Stopped |
41 }; | 42 }; |
42 | 43 |
43 boost::mutex* globalMutex_; | |
44 boost::mutex oracleMutex_; | 44 boost::mutex oracleMutex_; |
45 State state_; | 45 State state_; |
46 std::vector<boost::thread*> threads_; | 46 std::vector<boost::thread*> threads_; |
47 Orthanc::SharedMessageQueue queue_; | 47 Orthanc::SharedMessageQueue queue_; |
48 | 48 |
69 command.Execute(); | 69 command.Execute(); |
70 | 70 |
71 // Random sleeping to test | 71 // Random sleeping to test |
72 //boost::this_thread::sleep(boost::posix_time::milliseconds(50 * (1 + rand() % 10))); | 72 //boost::this_thread::sleep(boost::posix_time::milliseconds(50 * (1 + rand() % 10))); |
73 | 73 |
74 if (that->globalMutex_ != NULL) | 74 command.Commit(); |
75 { | |
76 boost::mutex::scoped_lock lock(*that->globalMutex_); | |
77 command.Commit(); | |
78 } | |
79 else | |
80 { | |
81 command.Commit(); | |
82 } | |
83 } | 75 } |
84 } | 76 } |
85 } | 77 } |
86 | 78 |
87 public: | 79 public: |
88 PImpl(boost::mutex* globalMutex, | 80 PImpl(unsigned int threadCount) : |
89 unsigned int threadCount) : | |
90 globalMutex_(globalMutex), | |
91 state_(State_Init), | 81 state_(State_Init), |
92 threads_(threadCount) | 82 threads_(threadCount) |
93 { | 83 { |
94 } | 84 } |
95 | 85 |
180 } | 170 } |
181 } | 171 } |
182 }; | 172 }; |
183 | 173 |
184 | 174 |
185 Oracle::Oracle(boost::mutex& globalMutex, | |
186 unsigned int threadCount) : | |
187 pimpl_(new PImpl(&globalMutex, threadCount)) | |
188 { | |
189 } | |
190 | |
191 | |
192 Oracle::Oracle(unsigned int threadCount) : | 175 Oracle::Oracle(unsigned int threadCount) : |
193 pimpl_(new PImpl(NULL, threadCount)) | 176 pimpl_(new PImpl(threadCount)) |
194 { | 177 { |
195 } | 178 } |
196 | |
197 | 179 |
198 void Oracle::Start() | 180 void Oracle::Start() |
199 { | 181 { |
200 pimpl_->Start(); | 182 pimpl_->Start(); |
201 } | 183 } |