コード例 #1
0
void ThreadGroup::executeTask(const TaskPtr& task)
{
    try {
        std::unique_lock<std::recursive_mutex> state_lock(execution_mtx_);
        ProfilerPtr profiler = getProfiler();
        Trace::Ptr interlude;
        if (profiler && profiler->isEnabled()) {
            TimerPtr timer = profiler->getTimer(getName());
            interlude.reset(new Trace(timer, task->getName()));
        }

        task->execute();

    } catch (const std::exception& e) {
        TaskGenerator* gen = task->getParent();
        if (gen) {
            gen->setError(e.what());
        }
    } catch (const std::string& s) {
        std::cerr << "Uncaught exception (string) exception: " << s << std::endl;

    } catch (const csapex::Failure& assertion) {
        handler_.handleAssertionFailure(assertion);

    } catch (...) {
        std::cerr << "Uncaught exception of unknown type and origin in execution of task " << task->getName() << "!" << std::endl;
        throw;
    }
}
コード例 #2
0
std::vector<TaskPtr> ThreadGroup::remove(TaskGenerator* generator)
{
    std::vector<TaskPtr> remaining_tasks;

    std::unique_lock<std::recursive_mutex> lock(tasks_mtx_);

    TaskGeneratorPtr removed;

    for (auto it = tasks_.begin(); it != tasks_.end();) {
        TaskPtr task = *it;
        if (task->getParent() == generator) {
            remaining_tasks.push_back(task);
            it = tasks_.erase(it);
        } else {
            ++it;
        }
    }

    for (auto it = generators_.begin(); it != generators_.end();) {
        if (it->get() == generator) {
            removed = *it;
            it = generators_.erase(it);
        } else {
            ++it;
        }
    }

    work_available_.notify_all();

    generator_connections_[generator].clear();

    generator_removed(removed);

    return remaining_tasks;
}