From caa56a972c203ff7938b3f972afc33080aac68c1 Mon Sep 17 00:00:00 2001 From: Mike Buland Date: Wed, 2 May 2018 23:18:41 -0600 Subject: Event added. It could be a little better. --- src/stable/event.h | 65 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 65 insertions(+) create mode 100644 src/stable/event.h (limited to 'src/stable') diff --git a/src/stable/event.h b/src/stable/event.h new file mode 100644 index 0000000..d6c9f5e --- /dev/null +++ b/src/stable/event.h @@ -0,0 +1,65 @@ +/* + * Copyright (C) 2007-2014 Xagasoft, All rights reserved. + * + * This file is part of the libbu++ library and is released under the + * terms of the license contained in the file LICENSE. + */ + +#ifndef BU_EVENT_H +#define BU_EVENT_H + +#include + +#include "bu/mutex.h" +#include "bu/condition.h" + +namespace Bu +{ + /** + *@ingroup Threading + */ + class Event + { + public: + Event() + { + } + + ~Event() + { + } + + void wait() + { + cBlock.lock(); + cBlock.wait(); + cBlock.unlock(); + } + + void wait( int nSec, int nUSec ) + { + cBlock.lock(); + cBlock.wait( nSec, nUSec ); + cBlock.unlock(); + } + + void unblockOne() + { + cBlock.lock(); + cBlock.signal(); + cBlock.unlock(); + } + + void unblockAll() + { + cBlock.lock(); + cBlock.broadcast(); + cBlock.unlock(); + } + + private: + Condition cBlock; /**< The condition for blocking dequeues. */ + }; +} + +#endif -- cgit v1.2.3