#include "event.h"
#include "kernel.h"
#include "process.h"

bool Event::Wait(timeout_t ticks)
{
	return true;

#if 0
    CriticalSection cs;

    if ( _value){                                           // if flag already signaled
        _value = efOff;                                  // clear flag
        return true;
    } else {
        BaseProcess* p = Kernel.Running();
        p->_timeout = ticks;
        ProcessMap prioTag = GetPrioTag(Kernel.CurProcPriority);
        SetPrioTag(_processMap, prioTag);                // put current process to the wait map
        ClrPrioTag(Kernel.ReadyProcessMap, prioTag);    // remove current process from the ready map
        Kernel.Scheduler();
        p->_timeout = 0;
        if( !(_processMap & prioTag) )                   // if waked up by signal() or signal_ISR()
            return true;

        ClrPrioTag(_processMap, prioTag);                // otherwise waked up by timeout or by
        return false;                                   // OS::ForceWakeUpProcess(), remove process from the wait map
    }
#endif
}

void Event::Signal()
{
#if 0
    TCritSect cs;
    if (_processMap) {                                         // if any process waits for event
        ProcessMap Timeouted = Kernel.ReadyProcessMap;     // Process has its tag set in ReadyProcessMap if timeout expired
                                                            // or it was waked up by OS::ForceWakeUpProcess()

        if( _processMap & ~Timeouted ) {                     // if any process has to be waked up
            SetPrioTag(Kernel.ReadyProcessMap, ProcessMap); // place all waiting processes to the ready map
            ClrPrioTag(_processMap, ~Timeouted);             // remove all non-timeouted processes from the waiting map.
                                                            // Used to check that process waked up by signal() or signalISR()
                                                            // and not by timeout or OS::ForceWakeUpProcess()
            Kernel.Scheduler();
            return;
        }
    }
    Value = efOn;
#endif
}
