Project

General

Profile

Revision a3be1d55

IDa3be1d55d349d5c722e7358b42efe4eb720c04fa

Added by Simon Tenbusch about 9 years ago

[eefscheduler] moved barrierwaiting to scheduler
- now the scheduler always returns a non barrier event

View differences:

src/sim/csimulation.cc
645 645
#ifdef NOBARRIER
646 646
        //TODO move to scheduler?
647 647
        // Do we have to wait for a barrier?
648
        if(threaded) {
648
        if(threaded)
649
        {
649 650
            barrierMin = threadPool->waitAtBarrier(barrierMin, &msgQueue);
650 651
        }
651 652
#endif
......
653 654
        msg = schedulerp->getNextEvent();
654 655

  
655 656
        //Advance Simulation Time
656
        //TODO Move to scheduler? (only in case of barrier)
657 657
        cThreadPool::setSimTime(msg->getArrivalTime());
658 658

  
659
#ifndef NOBARRIER
660
        //TODO: move to scheduler
661
        // check if this is an barrier message indicating the end of an event
662
        cBarrierMessage* barrier = dynamic_cast<cBarrierMessage*> (msg);
663
        if (barrier != NULL) {
664
            // wait for the task to complete
665
            barrier->wait();
666
            delete barrier;
667

  
668
            //It was a Barrier Message, after waiting, we are done and can return
669
            setGlobalContext();
670
            event_num++;
671
            return;
672
        }
673
#endif
674 659
        // Update mod pointer:
675 660
        mod = (cSimpleModule*) simulation.vect[msg->getArrivalModuleId()];
676 661
        // notify the environment about the event (writes eventlog, etc.)
......
679 664
        // sequence chart tool if the message doesn't get immediately deleted or
680 665
        // sent out again
681 666
        msg->setPreviousEventNumber(event_num);
682

  
683 667
        // check if this module supports parallel execution
684
        if (mod->isAsyncModule()) {
668
        if (mod->isAsyncModule())
669
        {
685 670
            // yes, it does. Next, check if this event should be executed
686 671
            // in parallel
687 672
            cAsyncModule* aMod = (cAsyncModule*) mod;
688 673

  
689 674
            simtime_t duration = aMod->getProcessingDelay(msg);
690

  
691
            if (duration < SimTime::simTimeZero) {
675
            if (duration < SimTime::simTimeZero)
676
            {
692 677
                throw cRuntimeError("negative event duration not allowed.");
693 678
            }
694 679
            msg->setEventDuration(duration);
695 680

  
696 681
            bool mayPar = aMod->mayParallelize(msg, duration);
697 682
            // execute this event in parallel
698
            if (mayPar && threaded) {
683
            if (mayPar && threaded)
684
            {
699 685
                // block if another thread is busy inside this module
700 686
                // then set the module to busy
701 687
                aMod->waitIfBusy();
702 688
                aMod->setBusy();
703 689
                //printf("Offloading: %s\n",mod->getName());
704 690
                barrierMin = threadPool->insertTask(msg, duration, barrierMin);
705
            } else {
691
            }
692
            else
693
            {
706 694
                // set the context for sequential execution
707 695
                setContext(mod);
708 696
                setContextType(CTX_EVENT);
709 697
                // take ownership in callHandleMessage after concurrency check
710

  
711 698
                aMod->callHandleMessage(msg);
712 699
            }
713

  
714
            //We have handled the Message / offloaded it. We can return
715
            setGlobalContext();
716
            event_num++;
717
            return;
718 700
        }
719

  
720
        //The module is no cAsyncModule
721
        // set the context for sequential execution
722
        setContext(mod);
723
        setContextType(CTX_EVENT);
724
        // take owner here: no danger of a race condition since
725
        // simple modules are only called from here
726
        mod->take(msg);
727
        // if there was an error during simulation, handleMessage()
728
        // will come back with an exception
729
        mod->handleMessage(msg);
730

  
701
        else
702
        { //The module is not a cAsyncModule
703

  
704
            // set the context for sequential execution
705
            setContext(mod);
706
            setContextType(CTX_EVENT);
707
            // take owner here: no danger of a race condition since
708
            // simple modules are only called from here
709
            mod->take(msg);
710
            // if there was an error during simulation, handleMessage()
711
            // will come back with an exception
712
            mod->handleMessage(msg);
713
        }
731 714

  
732 715
        //We have handled the Message, return
733 716
        setGlobalContext();
734 717
        event_num++;
735 718
        return;
736

  
737 719
    }
738 720
    catch (cDeleteModuleException& e)
739 721
    {

Also available in: Unified diff