Mercurial > hg > orthanc
comparison OrthancServer/ServerIndex.cpp @ 220:bb8c260c0092
fix for windows
author | Sebastien Jodogne <s.jodogne@gmail.com> |
---|---|
date | Thu, 29 Nov 2012 15:06:50 +0100 |
parents | f276b175dcaf |
children | 4eb0c7ce86c9 |
comparison
equal
deleted
inserted
replaced
219:5459f05b4f54 | 220:bb8c260c0092 |
---|---|
164 return true; | 164 return true; |
165 } | 165 } |
166 | 166 |
167 | 167 |
168 static void FlushThread(DatabaseWrapper* db, | 168 static void FlushThread(DatabaseWrapper* db, |
169 boost::mutex* mutex) | 169 boost::mutex* mutex, |
170 { | 170 unsigned int sleep) |
171 // By default, wait for 10 seconds before flushing | 171 { |
172 unsigned int sleep = 10; | |
173 | |
174 { | |
175 boost::mutex::scoped_lock lock(*mutex); | |
176 std::string s = db->GetGlobalProperty(GlobalProperty_FlushSleep); | |
177 try | |
178 { | |
179 sleep = boost::lexical_cast<unsigned int>(s); | |
180 } | |
181 catch (boost::bad_lexical_cast&) | |
182 { | |
183 } | |
184 } | |
185 | |
186 LOG(INFO) << "Starting the database flushing thread (sleep = " << sleep << ")"; | 172 LOG(INFO) << "Starting the database flushing thread (sleep = " << sleep << ")"; |
187 | 173 |
188 while (1) | 174 while (1) |
189 { | 175 { |
190 boost::this_thread::sleep(boost::posix_time::seconds(sleep)); | 176 boost::this_thread::sleep(boost::posix_time::seconds(sleep)); |
193 } | 179 } |
194 } | 180 } |
195 | 181 |
196 | 182 |
197 ServerIndex::ServerIndex(FileStorage& fileStorage, | 183 ServerIndex::ServerIndex(FileStorage& fileStorage, |
198 const std::string& dbPath) | 184 const std::string& dbPath) : mutex_() |
199 { | 185 { |
200 listener_.reset(new Internals::ServerIndexListener(fileStorage)); | 186 listener_.reset(new Internals::ServerIndexListener(fileStorage)); |
201 | 187 |
202 if (dbPath == ":memory:") | 188 if (dbPath == ":memory:") |
203 { | 189 { |
216 } | 202 } |
217 | 203 |
218 db_.reset(new DatabaseWrapper(p.string() + "/index", *listener_)); | 204 db_.reset(new DatabaseWrapper(p.string() + "/index", *listener_)); |
219 } | 205 } |
220 | 206 |
221 flushThread_ = boost::thread(FlushThread, db_.get(), &mutex_); | 207 unsigned int sleep; |
208 try | |
209 { | |
210 std::string sleepString = db_->GetGlobalProperty(GlobalProperty_FlushSleep); | |
211 sleep = boost::lexical_cast<unsigned int>(sleepString); | |
212 } | |
213 catch (boost::bad_lexical_cast&) | |
214 { | |
215 // By default, wait for 10 seconds before flushing | |
216 sleep = 10; | |
217 } | |
218 | |
219 flushThread_ = boost::thread(FlushThread, db_.get(), &mutex_, sleep); | |
222 } | 220 } |
223 | 221 |
224 | 222 |
225 ServerIndex::~ServerIndex() | 223 ServerIndex::~ServerIndex() |
226 { | 224 { |
227 LOG(INFO) << "Stopping the database flushing thread"; | 225 LOG(INFO) << "Stopping the database flushing thread"; |
228 flushThread_.interrupt(); | 226 /*flushThread_.terminate(); |
229 flushThread_.join(); | 227 flushThread_.join();*/ |
230 } | 228 } |
231 | 229 |
232 | 230 |
233 StoreStatus ServerIndex::Store(const DicomMap& dicomSummary, | 231 StoreStatus ServerIndex::Store(const DicomMap& dicomSummary, |
234 const std::string& fileUuid, | 232 const std::string& fileUuid, |