InfoCacheReader.cpp 2.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. /*##############################################################################
  2. HPCC SYSTEMS software Copyright (C) 2019 HPCC Systems®.
  3. Licensed under the Apache License, Version 2.0 (the "License");
  4. you may not use this file except in compliance with the License.
  5. You may obtain a copy of the License at
  6. http://www.apache.org/licenses/LICENSE-2.0
  7. Unless required by applicable law or agreed to in writing, software
  8. distributed under the License is distributed on an "AS IS" BASIS,
  9. WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  10. See the License for the specific language governing permissions and
  11. limitations under the License.
  12. ############################################################################## */
  13. #pragma warning (disable : 4786)
  14. #include "InfoCacheReader.hpp"
  15. bool CInfoCache::isCachedInfoValid(unsigned timeOutSeconds)
  16. {
  17. CDateTime timeNow;
  18. timeNow.setNow();
  19. return timeNow.getSimple() <= timeCached.getSimple() + timeOutSeconds;;
  20. }
  21. void CInfoCacheReaderThread::threadmain()
  22. {
  23. PROGLOG("CInfoCacheReaderThread %s started.", name.get());
  24. unsigned int autoRebuildMillSeconds = 1000*autoRebuildSeconds;
  25. while (!stopping)
  26. {
  27. if (active)
  28. {
  29. try
  30. {
  31. CCycleTimer timer;
  32. Owned<CInfoCache> info = infoCacheReader->read();
  33. PROGLOG("CInfoCacheReaderThread %s: InfoCache collected (%u seconds).", name.get(), timer.elapsedMs()/1000);
  34. CriticalBlock b(crit);
  35. infoCache.setown(info.getClear());
  36. // if 1st and getActivityInfo blocked, release it.
  37. if (first)
  38. {
  39. first = false;
  40. if (firstBlocked)
  41. {
  42. firstBlocked = false;
  43. firstSem.signal();
  44. }
  45. }
  46. }
  47. catch(IException *e)
  48. {
  49. StringBuffer msg;
  50. IERRLOG("Exception %d:%s in CInfoCacheReaderThread(%s)::run", e->errorCode(), e->errorMessage(msg).str(), name.get());
  51. e->Release();
  52. }
  53. catch(...)
  54. {
  55. IERRLOG("Unknown exception in CInfoCacheReaderThread(%s)::run", name.get());
  56. }
  57. }
  58. waiting = true;
  59. if (!sem.wait(autoRebuildMillSeconds))
  60. {
  61. bool expected = true;
  62. waiting.compare_exchange_strong(expected, false);
  63. }
  64. }
  65. }