Mercurial > hg > orthanc
comparison OrthancServer/ServerIndex.cpp @ 2665:389d050a2e66 jobs
fix deadlock, speed up unit tests
author | Sebastien Jodogne <s.jodogne@gmail.com> |
---|---|
date | Fri, 08 Jun 2018 13:51:31 +0200 |
parents | a21b244efb37 |
children | d26dd081df97 |
comparison
equal
deleted
inserted
replaced
2664:a21b244efb37 | 2665:389d050a2e66 |
---|---|
340 | 340 |
341 return true; | 341 return true; |
342 } | 342 } |
343 | 343 |
344 | 344 |
345 void ServerIndex::FlushThread(ServerIndex* that) | 345 void ServerIndex::FlushThread(ServerIndex* that, |
346 unsigned int threadSleep) | |
346 { | 347 { |
347 // By default, wait for 10 seconds before flushing | 348 // By default, wait for 10 seconds before flushing |
348 unsigned int sleep = 10; | 349 unsigned int sleep = 10; |
349 | 350 |
350 try | 351 try |
366 | 367 |
367 unsigned int count = 0; | 368 unsigned int count = 0; |
368 | 369 |
369 while (!that->done_) | 370 while (!that->done_) |
370 { | 371 { |
371 boost::this_thread::sleep(boost::posix_time::seconds(1)); | 372 boost::this_thread::sleep(boost::posix_time::milliseconds(threadSleep)); |
372 count++; | 373 count++; |
373 if (count < sleep) | 374 if (count < sleep) |
374 { | 375 { |
375 continue; | 376 continue; |
376 } | 377 } |
536 return id; | 537 return id; |
537 } | 538 } |
538 | 539 |
539 | 540 |
540 ServerIndex::ServerIndex(ServerContext& context, | 541 ServerIndex::ServerIndex(ServerContext& context, |
541 IDatabaseWrapper& db) : | 542 IDatabaseWrapper& db, |
543 unsigned int threadSleep) : | |
542 done_(false), | 544 done_(false), |
543 db_(db), | 545 db_(db), |
544 maximumStorageSize_(0), | 546 maximumStorageSize_(0), |
545 maximumPatients_(0) | 547 maximumPatients_(0) |
546 { | 548 { |
553 // execution of Orthanc | 555 // execution of Orthanc |
554 StandaloneRecycling(); | 556 StandaloneRecycling(); |
555 | 557 |
556 if (db.HasFlushToDisk()) | 558 if (db.HasFlushToDisk()) |
557 { | 559 { |
558 flushThread_ = boost::thread(FlushThread, this); | 560 flushThread_ = boost::thread(FlushThread, this, threadSleep); |
559 } | 561 } |
560 | 562 |
561 unstableResourcesMonitorThread_ = boost::thread(UnstableResourcesMonitorThread, this); | 563 unstableResourcesMonitorThread_ = boost::thread |
564 (UnstableResourcesMonitorThread, this, threadSleep); | |
562 } | 565 } |
563 | 566 |
564 | 567 |
565 | 568 |
566 ServerIndex::~ServerIndex() | 569 ServerIndex::~ServerIndex() |
1876 GetStatisticsInternal(compressedSize, uncompressedSize, countStudies, | 1879 GetStatisticsInternal(compressedSize, uncompressedSize, countStudies, |
1877 countSeries, countInstances, top, type); | 1880 countSeries, countInstances, top, type); |
1878 } | 1881 } |
1879 | 1882 |
1880 | 1883 |
1881 void ServerIndex::UnstableResourcesMonitorThread(ServerIndex* that) | 1884 void ServerIndex::UnstableResourcesMonitorThread(ServerIndex* that, |
1885 unsigned int threadSleep) | |
1882 { | 1886 { |
1883 int stableAge = Configuration::GetGlobalUnsignedIntegerParameter("StableAge", 60); | 1887 int stableAge = Configuration::GetGlobalUnsignedIntegerParameter("StableAge", 60); |
1884 if (stableAge <= 0) | 1888 if (stableAge <= 0) |
1885 { | 1889 { |
1886 stableAge = 60; | 1890 stableAge = 60; |
1888 | 1892 |
1889 LOG(INFO) << "Starting the monitor for stable resources (stable age = " << stableAge << ")"; | 1893 LOG(INFO) << "Starting the monitor for stable resources (stable age = " << stableAge << ")"; |
1890 | 1894 |
1891 while (!that->done_) | 1895 while (!that->done_) |
1892 { | 1896 { |
1893 // Check for stable resources each second | 1897 // Check for stable resources each few seconds |
1894 boost::this_thread::sleep(boost::posix_time::seconds(1)); | 1898 boost::this_thread::sleep(boost::posix_time::milliseconds(threadSleep)); |
1895 | 1899 |
1896 boost::mutex::scoped_lock lock(that->mutex_); | 1900 boost::mutex::scoped_lock lock(that->mutex_); |
1897 | 1901 |
1898 while (!that->unstableResources_.IsEmpty() && | 1902 while (!that->unstableResources_.IsEmpty() && |
1899 that->unstableResources_.GetOldestPayload().GetAge() > static_cast<unsigned int>(stableAge)) | 1903 that->unstableResources_.GetOldestPayload().GetAge() > static_cast<unsigned int>(stableAge)) |