X-Git-Url: http://sraa.de/git/?a=blobdiff_plain;f=dol%2Fsrc%2Fdol%2Fvisitor%2FPipeAndFilter%2Flib%2FEvent.cpp;fp=dol%2Fsrc%2Fdol%2Fvisitor%2FPipeAndFilter%2Flib%2FEvent.cpp;h=52490b2dc44b856708433c50b85840e2612b2745;hb=8c411cf24ed0eb889191aaeafd8fa1e69081df42;hp=0000000000000000000000000000000000000000;hpb=dea7a4fb1ed110d3ce6e6d9255103d724bd66c0e;p=jump.git diff --git a/dol/src/dol/visitor/PipeAndFilter/lib/Event.cpp b/dol/src/dol/visitor/PipeAndFilter/lib/Event.cpp new file mode 100644 index 0000000..52490b2 --- /dev/null +++ b/dol/src/dol/visitor/PipeAndFilter/lib/Event.cpp @@ -0,0 +1,73 @@ +#include "Event.h" + +Event::Event() { + _name = "Event"; + //std::cout << "Create " << _name << "." << std::endl; + _mutex = new Mutex(); + _condition = new Condition(_mutex); + _waitMutex = new Mutex(); + _waitCondition = new Condition(_waitMutex); + _pendingWait = false; +} + + +Event::Event(std::string name) { + _name = "Event " + name; + //std::cout << "Create " << _name << "." << std::endl; + _mutex = new Mutex(); + _condition = new Condition(_mutex); + _waitMutex = new Mutex(); + _waitCondition = new Condition(_waitMutex); + _pendingWait = false; +} + + +Event::~Event() { + //std::cout << "Delete " << _name << "." << std::endl; + delete _condition; + delete _waitCondition; + delete _mutex; + delete _waitMutex; + //std::cout << "Deleted " << _name << "." << std::endl; +} + + +void Event::notify() { + _mutex->lock(); + _condition->notify(); + _mutex->unlock(); +} + + +void Event::notifyAll() { + _mutex->lock(); + _condition->notifyAll(); + _mutex->unlock(); +} + + +void Event::wait() { + _mutex->lock(); + _pendingWait = true; + _waitMutex->lock(); + _waitCondition->notify(); + _waitMutex->unlock(); + _condition->wait(); + _pendingWait = false; + _mutex->unlock(); +} + + +void Event::notifyAfterWait() { + _mutex->lock(); + + if (!_pendingWait) { + _waitMutex->lock(); + _mutex->unlock(); + _waitCondition->wait(); + _mutex->lock(); + _waitMutex->unlock(); + } + _condition->notify(); + _mutex->unlock(); +}