PageRenderTime 82ms CodeModel.GetById 40ms app.highlight 3ms RepoModel.GetById 37ms 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
 1// Copyright (c) 2009 - Mozy, Inc.
 2
 3#include "workerpool.h"
 4
 5#include "fiber.h"
 6#include "log.h"
 7
 8namespace Mordor {
 9
10static Logger::ptr g_log = Log::lookup("mordor:workerpool");
11
12WorkerPool::WorkerPool(size_t threads, bool useCaller, size_t batchSize)
13    : Scheduler(threads, useCaller, batchSize)
14{
15    start();
16}
17
18void
19WorkerPool::idle()
20{
21    while (true) {
22        if (stopping()) {
23            return;
24        }
25        m_semaphore.wait();
26        try {
27            Fiber::yield();
28        } catch (OperationAbortedException &) {
29            return;
30        }
31    }
32}
33
34void
35WorkerPool::tickle()
36{
37    MORDOR_LOG_DEBUG(g_log) << this << " tickling";
38    m_semaphore.notify();
39}
40
41}