@@ -23,10 +23,11 @@ # include #endif #import "OFThread.h" #import "OFList.h" +#import "OFDate.h" #import "OFAutoreleasePool.h" #import "OFExceptions.h" #import "threading.h" @@ -101,10 +102,31 @@ usleep(msecs * 1000); #else Sleep(msecs); #endif } + ++ (void)sleepUntilDate: (OFDate*)date +{ + OFAutoreleasePool *pool = [[OFAutoreleasePool alloc] init]; + OFDate *now = [OFDate date]; + int64_t sec; + uint32_t usec; + + if ((sec = [date timeIntervalSinceDate: now]) < 0) + @throw [OFOutOfRangeException newWithClass: self]; + + usec = [date microsecondsOfTimeIntervalSinceDate: now]; + + [pool release]; + +#ifndef _WIN32 + usleep(sec * 1000000 + usec); +#else + Sleep(sec * 1000 + usec / 1000); +#endif +} + (void)yield { #ifndef _WIN32 sched_yield();