PageRenderTime 70ms CodeModel.GetById 15ms RepoModel.GetById 0ms app.codeStats 0ms

/mordor/workerpool.cpp

http://github.com/mozy/mordor
C++ | 41 lines | 32 code | 8 blank | 1 comment | 2 complexity | 80902fa88235c9003d7765de99f539a1 MD5 | raw file
Possible License(s): BSD-3-Clause
  1. // Copyright (c) 2009 - Mozy, Inc.
  2. #include "workerpool.h"
  3. #include "fiber.h"
  4. #include "log.h"
  5. namespace Mordor {
  6. static Logger::ptr g_log = Log::lookup("mordor:workerpool");
  7. WorkerPool::WorkerPool(size_t threads, bool useCaller, size_t batchSize)
  8. : Scheduler(threads, useCaller, batchSize)
  9. {
  10. start();
  11. }
  12. void
  13. WorkerPool::idle()
  14. {
  15. while (true) {
  16. if (stopping()) {
  17. return;
  18. }
  19. m_semaphore.wait();
  20. try {
  21. Fiber::yield();
  22. } catch (OperationAbortedException &) {
  23. return;
  24. }
  25. }
  26. }
  27. void
  28. WorkerPool::tickle()
  29. {
  30. MORDOR_LOG_DEBUG(g_log) << this << " tickling";
  31. m_semaphore.notify();
  32. }
  33. }