Ejemplo n.º 1
0
int InitiationDispatcher:: HandleEvents(Time_Value* timeout){
    MpEvent::iterator it ;
    for(it = m_mpEvent.begin(); it!= m_mpEvent.end(); it++){
        EventHandle* pEvent = it->first;
        pEvent->HandleEvents(it->second);
    }
    return 0;
}
Ejemplo n.º 2
0
void ThreadPoolTaskExecutor::waitForEvent(const EventHandle& event) {
    invariant(event.isValid());
    auto eventState = checked_cast<EventState*>(getEventFromHandle(event));
    stdx::unique_lock<stdx::mutex> lk(_mutex);
    while (!eventState->isSignaledFlag) {
        eventState->isSignaledCondition.wait(lk);
    }
}
Ejemplo n.º 3
0
void ThreadPoolTaskExecutor::signalEvent_inlock(const EventHandle& event) {
    invariant(event.isValid());
    auto eventState = checked_cast<EventState*>(getEventFromHandle(event));
    invariant(!eventState->isSignaledFlag);
    eventState->isSignaledFlag = true;
    eventState->isSignaledCondition.notify_all();
    scheduleIntoPool_inlock(&eventState->waiters);
    _unsignaledEvents.erase(eventState->iter);
}
Ejemplo n.º 4
0
 void ReplicationExecutor::waitForEvent(const EventHandle& event) {
     boost::unique_lock<boost::mutex> lk(_mutex);
     invariant(event.isValid());
     ++_totalEventWaiters;
     while ((event._generation == event._iter->generation) && !event._iter->isSignaled) {
         event._iter->isSignaledCondition->wait(lk);
     }
     --_totalEventWaiters;
     maybeNotifyShutdownComplete_inlock();
 }
void testEventHandler() {
    EventHandler *handler = new EventHandler();

    //handler->createEvent(&testObjectTOP, 0);
    EventHandle *handle1 = handler->createEvent(&testObjectMID, 2);
    handle1->setRecurrences(6); // "Times" to happen
    handle1->setPeriod(100); // period in milliseconds

    EventHandle *handle = handler->createEvent(&testObjectBOT, 1);
    handle->setRecurrences(3);
    handle->setPeriod(100);

    // add a single event
    EventHandle *handlex = handler->createEvent(&testObjectSingle, 0);
    handlex->setRecurrences(200);
    handlex->setPeriod(10);
    handlex->arg1 = (void*)"aaa";

    // slower single event
    EventHandle *handlex2 = handler->createEvent(&testObjectSingle, 0);
    handlex2->setRecurrences(5);
    handlex2->setPeriod(1000);
    handlex2->arg1 = (void*)"bbb";

    while(!handler->isEmpty()) {
        handler->handleEvents();
    }
}
Ejemplo n.º 6
0
// queue is only set for the top item
void _doEvents(EventHandler* handler, PriorityQueue* handles, PriorityItem* item, bool threaded) {
    // handle left first, then handle right
    if(item == 0x0) return;
    debugLogEH("dE1");

    // execute event
    if(item->data != 0x0) {
        EventHandle* handle = (EventHandle*)item->data;
        debugLogEH("dE2---xx");
        if(!handle->handle()) {
            debugLogEH("dE3---" << handles->getSize());
            handles->remove(item);
            debugLogEH("dE4");
        }
        debugLogEH("dE5---xx");
    }
    debugLogEH("dE6");

    // go through the branches
    if(item->left != 0x0) {
        if(threaded){ 
            handler->pool.enqueue(_doEvents, handler, handles, item->left, threaded);
            /*void (*f1)(EventHandler* handler, PriorityQueue* handles, PriorityItem* item, bool threaded);
            f1 = &_doEvents;
            handler->pool.enqueue([f1, handler, handles, item, threaded]{
                return (*_doEvents)(handler, handles, item->left, threaded);
            }); //&_doEvents, handler, handles, item->left, threaded);*/
        }else{
            (*_doEvents)(handler, handles, item->left, threaded);
        }
    }
    if(item->right != 0x0) {
        if(threaded){
            handler->pool.enqueue(_doEvents, handler, handles, item->right, threaded);
        }else{
            _doEvents(handler, handles, item->right, threaded);
        }
    }
}
Ejemplo n.º 7
0
 StatusWith<ReplicationExecutor::CallbackHandle> ReplicationExecutor::onEvent(
         const EventHandle& event,
         const CallbackFn& work) {
     boost::lock_guard<boost::mutex> lk(_mutex);
     invariant(event.isValid());
     invariant(event._generation <= event._iter->generation);
     WorkQueue* queue = &_readyQueue;
     if (event._generation == event._iter->generation && !event._iter->isSignaled) {
         queue = &event._iter->waiters;
     }
     else {
         queue = &_readyQueue;
     }
     return enqueueWork_inlock(queue, work);
 }
Ejemplo n.º 8
0
StatusWith<TaskExecutor::CallbackHandle> ThreadPoolTaskExecutor::onEvent(const EventHandle& event,
                                                                         const CallbackFn& work) {
    stdx::lock_guard<stdx::mutex> lk(_mutex);
    if (!event.isValid()) {
        return {ErrorCodes::BadValue, "Passed invalid event handle to onEvent"};
    }
    auto eventState = checked_cast<EventState*>(getEventFromHandle(event));
    auto cbHandle = enqueueCallbackState_inlock(&eventState->waiters, work);
    if (!cbHandle.isOK()) {
        return cbHandle;
    }
    if (eventState->isSignaledFlag) {
        scheduleIntoPool_inlock(&eventState->waiters);
    }
    return cbHandle;
}