void PendingChecks::runChecks()
{
    DynMutex::Guard guard = m_mutex.lock();
    Checks::iterator it = m_checks.begin();
    bool removed = false;
    while (it != m_checks.end()) {
        bool cont;
        try {
            cont = (**it)();
        } catch (...) {
            Exception::handle(HANDLE_EXCEPTION_FATAL);
            // keep compiler happy
            cont = false;
        }

        if (!cont) {
            // Done with this check
            Checks::iterator next = it;
            ++next;
            m_checks.erase(it);
            it = next;
            removed = true;
        } else {
            ++it;
        }
    }
    // Tell blockOnCheck() calls that they may have completed.
    if (removed) {
        m_cond.signal();
    }
}
void PendingChecks::blockOnCheck(const boost::function<bool ()> &check, bool checkFirst)
{
    DynMutex::Guard guard = m_mutex.lock();
    // When we get here, the conditions for returning may already have
    // been met.  Check before sleeping. If we need to continue, then
    // holding the mutex ensures that the main thread will run the
    // check on the next iteration.
    if (!checkFirst || check()) {
        m_checks.insert(&check);
        if (!checkFirst) {
            // Must wake up the main thread from its g_main_context_iteration.
            g_main_context_wakeup(g_main_context_default());
        }
        do {
             m_cond.wait(m_mutex);
        } while (m_checks.find(&check) != m_checks.end());
    }
}
Esempio n. 3
0
 void finish() {
   for (Checks::iterator i = checks.begin(), e = checks.end(); i != e; ++i) i->finish();
   checks.clear();
 }
Esempio n. 4
0
 void start() {
   for (Checks::iterator i = checks.begin(), e = checks.end(); i != e; ++i) i->start();
 }