Index: src/OFCondition.h ================================================================== --- src/OFCondition.h +++ src/OFCondition.h @@ -14,10 +14,12 @@ * file. */ #import "OFMutex.h" +@class OFDate; + /*! * @brief A class implementing a condition variable for thread synchronization. */ @interface OFCondition: OFMutex { @@ -36,10 +38,28 @@ * @brief Blocks the current thread until another thread calls @ref signal or * @ref broadcast. */ - (void)wait; +/*! + * @brief Blocks the current thread until another thread calls @ref signal, + * @ref broadcast or the timeout is reached. + * + * @param timeInterval The time interval until the timeout is reached + * @return Whether the condition has been signaled + */ +- (bool)waitForTimeInterval: (double)timeInterval; + +/*! + * @brief Blocks the current thread until another thread calls @ref signal, + * @ref broadcast or the timeout is reached. + * + * @param date The date at which the timeout is reached + * @return Whether the condition has been signaled + */ +- (bool)waitUntilDate: (OFDate*)date; + /*! * @brief Signals the next waiting thread to continue. */ - (void)signal; Index: src/OFCondition.m ================================================================== --- src/OFCondition.m +++ src/OFCondition.m @@ -15,10 +15,11 @@ */ #include "config.h" #import "OFCondition.h" +#import "OFDate.h" #import "OFConditionBroadcastFailedException.h" #import "OFConditionSignalFailedException.h" #import "OFConditionStillWaitingException.h" #import "OFConditionWaitFailedException.h" @@ -61,10 +62,21 @@ if (!of_condition_wait(&_condition, &_mutex)) @throw [OFConditionWaitFailedException exceptionWithClass: [self class] condition: self]; } + +- (bool)waitForTimeInterval: (double)timeInterval +{ + return of_condition_timed_wait(&_condition, &_mutex, timeInterval); +} + +- (bool)waitUntilDate: (OFDate*)date +{ + return of_condition_timed_wait(&_condition, &_mutex, + [date timeIntervalSinceNow]); +} - (void)signal { if (!of_condition_signal(&_condition)) @throw [OFConditionSignalFailedException