Project

General

Profile

Revision 0e7ff5c8

ID0e7ff5c845cc8caa56f4ed6f37b2918b84466d7e

Added by Simon Tenbusch almost 9 years ago

[nullduration] moved asyncModuleLocks to earlier position and added getProcessingDelay return value that makes the event get handled sequentially:
We have to lock before getProcessingDelay is called, and must only be released, once the corresponding event has been handled. This is because in the meantime, other events could alter the module and therefore change the outcome of getProcessingDelay nondeterministically.

Also in the sequential case, we still have to lock because it could be the case that a parallel event on the same module is active while we try to execute a sequential one.

The locking is now taking place in cMessage::getEventDuration, which calls getProcessingDelay. Unlocking takes now place both after sequential and parallel execution.

If SimTime::simTimeSequentialExecution is returned by getProcessingDelay, the event is handled sequentially with duration 0 (useful for management events)

View differences:

src/sim/csimulation.cc
682 682
            cAsyncModule* aMod = (cAsyncModule*) mod;
683 683

  
684 684
            simtime_t duration = msg->getEventDuration();
685
            bool sequentialExecution = (duration == SimTime::simTimeSequentialExecution);
686

  
687
            if (sequentialExecution)
688
                duration = SimTime::simTimeZero;
689

  
685 690
            if (duration < SimTime::simTimeZero)
686 691
            {
687 692
                throw cRuntimeError("negative event duration not allowed.");
......
689 694

  
690 695
            bool mayPar = aMod->mayParallelize(msg, duration);
691 696
            // execute this event in parallel
692
            if (mayPar && threaded)
697
            if (mayPar && threaded && !sequentialExecution)
693 698
            {
694
                // block if another thread is busy inside this module
695
                // then set the module to busy
696
                aMod->waitIfBusy();
697
                aMod->setBusy();
698 699
                //printf("Offloading: %s\n",mod->getName());
699 700
                threadPool->insertTask(msg, duration);
701
                // the threadpool unsets the module busy after it finishes the event
700 702
            }
701 703
            else
702 704
            {
......
705 707
                setContextType(CTX_EVENT);
706 708
                // take ownership in callHandleMessage after concurrency check
707 709
                aMod->callHandleMessage(msg);
710
                // unset busy to release module for further events
711
                aMod->unsetBusy();
708 712
            }
709 713
        }
710 714
        else

Also available in: Unified diff