Ejemplo n.º 1
0
bool Worker::addProcessor(int id, Runnable *processor)
{
    bool ret = false;
    std::map<int, Runnable*> runnables;
    Runnable* current;

    std::lock_guard<std::mutex> guard(mtx);

    while (!processors.empty()){
        current = processors.top();
        processors.pop();
        runnables[current->getId()] = current;
    }

    if (runnables.count(id) == 0) {
        processor->setId(id);
        runnables[id] = processor;
        ret = true;
    }

    for (auto it : runnables){
        processors.push(it.second);
    }

    return ret;
}
Ejemplo n.º 2
0
bool Worker::removeProcessor(int id)
{
    bool ret = false;
    std::map<int, Runnable*> runnables;
    Runnable* current;

    std::lock_guard<std::mutex> guard(mtx);

    while (!processors.empty()){
        current = processors.top();
        processors.pop();
        runnables[current->getId()] = current;
    }

    while (runnables.count(id) > 0) {
        runnables.erase(id);
        ret = true;
    }

    for (auto it : runnables){
        processors.push(it.second);
    }

    return ret;
}
Ejemplo n.º 3
0
//TODO: avoid void functions
void Worker::getState(Jzon::Object &workerNode)
{
    Jzon::Array pList;
    std::map<int, Runnable*> runnables;
    Runnable* current;

    {
        std::lock_guard<std::mutex> guard(mtx);

        while (!processors.empty()){
            current = processors.top();
            processors.pop();
            runnables[current->getId()] = current;
        }

        for (auto it : runnables){
            processors.push(it.second);
        }

    }

    for (auto it : runnables) {
        pList.Add(it.first);
    }

    workerNode.Add("type", utils::getWorkerTypeAsString(type));
    workerNode.Add("processors", pList);
}