From 208b983734d7431699f4bd3534e08321e42ada86 Mon Sep 17 00:00:00 2001 From: Mike Buland Date: Thu, 6 Oct 2011 03:25:22 +0000 Subject: Renamed most of the core threading system, some ancillary systems need some kind of prefix or something, we could stick with Ito, I will until I think of something else. --- src/condition.cpp | 49 +++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 49 insertions(+) create mode 100644 src/condition.cpp (limited to 'src/condition.cpp') diff --git a/src/condition.cpp b/src/condition.cpp new file mode 100644 index 0000000..2f55ce2 --- /dev/null +++ b/src/condition.cpp @@ -0,0 +1,49 @@ +/* + * Copyright (C) 2007-2011 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. + */ + +#include + +#include "bu/condition.h" + +Bu::Condition::Condition() +{ + pthread_cond_init( &cond, NULL ); +} + +Bu::Condition::~Condition() +{ + pthread_cond_destroy( &cond ); +} + +int Bu::Condition::wait() +{ + return pthread_cond_wait( &cond, &mutex ); +} + +int Bu::Condition::wait( int nSec, int nUSec ) +{ + struct timeval now; + struct timespec timeout; + struct timezone tz; + + gettimeofday( &now, &tz ); + timeout.tv_sec = now.tv_sec + nSec + ((now.tv_usec + nUSec)/1000000); + timeout.tv_nsec = ((now.tv_usec + nUSec)%1000000)*1000; + + return pthread_cond_timedwait( &cond, &mutex, &timeout ); +} + +int Bu::Condition::signal() +{ + return pthread_cond_signal( &cond ); +} + +int Bu::Condition::broadcast() +{ + return pthread_cond_broadcast( &cond ); +} + -- cgit v1.2.3