Differences From Artifact [fcdc461826]:
- File src/OFRunLoop.m — part of check-in [ab9ad6e515] at 2013-04-30 22:47:28 on branch trunk — observeWithTimeout: -> observeForTimeInterval:. (user: js, size: 15486) [annotate] [blame] [check-ins using]
To Artifact [410ce014df]:
- File
src/OFRunLoop.m
— part of check-in
[56ec27cbdf]
at
2013-05-01 21:05:39
on branch trunk
— OFRunLoop: Work correctly for threads && !sockets.
This was only an issue with --enable-threads --disable-sockets. (user: js, size: 15861) [annotate] [blame] [check-ins using]
︙ | ︙ | |||
22 23 24 25 26 27 28 29 30 31 32 33 34 35 | #import "OFDictionary.h" #ifdef OF_HAVE_SOCKETS # import "OFStreamObserver.h" #endif #import "OFThread.h" #ifdef OF_HAVE_THREADS # import "OFMutex.h" #endif #import "OFSortedList.h" #import "OFTimer.h" #import "OFDate.h" #import "autorelease.h" #import "macros.h" | > | 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 | #import "OFDictionary.h" #ifdef OF_HAVE_SOCKETS # import "OFStreamObserver.h" #endif #import "OFThread.h" #ifdef OF_HAVE_THREADS # import "OFMutex.h" # import "OFCondition.h" #endif #import "OFSortedList.h" #import "OFTimer.h" #import "OFDate.h" #import "autorelease.h" #import "macros.h" |
︙ | ︙ | |||
300 301 302 303 304 305 306 | @try { _timersQueue = [[OFSortedList alloc] init]; #ifdef OF_HAVE_THREADS _timersQueueLock = [[OFMutex alloc] init]; #endif | | > > | > > | < < | > > | | 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 | @try { _timersQueue = [[OFSortedList alloc] init]; #ifdef OF_HAVE_THREADS _timersQueueLock = [[OFMutex alloc] init]; #endif #if defined(OF_HAVE_SOCKETS) _streamObserver = [[OFStreamObserver alloc] init]; [_streamObserver setDelegate: self]; _readQueues = [[OFMutableDictionary alloc] init]; #elif defined(OF_HAVE_THREADS) _condition = [[OFCondition alloc] init]; #endif } @catch (id e) { [self release]; @throw e; } return self; } - (void)dealloc { [_timersQueue release]; #ifdef OF_HAVE_THREADS [_timersQueueLock release]; #endif #if defined(OF_HAVE_SOCKETS) [_streamObserver release]; [_readQueues release]; #elif defined(OF_HAVE_THREADS) [_condition release]; #endif [super dealloc]; } - (void)addTimer: (OFTimer*)timer { #ifdef OF_HAVE_THREADS [_timersQueueLock lock]; @try { #endif [_timersQueue insertObject: timer]; #ifdef OF_HAVE_THREADS } @finally { [_timersQueueLock unlock]; } #endif [timer OF_setInRunLoop: self]; #if defined(OF_HAVE_SOCKETS) [_streamObserver cancel]; #elif defined(OF_HAVE_THREADS) [_condition lock]; [_condition signal]; [_condition unlock]; #endif } - (void)OF_removeTimer: (OFTimer*)timer { #ifdef OF_HAVE_THREADS [_timersQueueLock lock]; |
︙ | ︙ | |||
668 669 670 671 672 673 674 | } #endif /* Watch for stream events until the next timer is due */ if (nextTimer != nil) { double timeout = [nextTimer timeIntervalSinceNow]; | | | > > > > > | > > > > | < < | > > | | 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 | } #endif /* Watch for stream events until the next timer is due */ if (nextTimer != nil) { double timeout = [nextTimer timeIntervalSinceNow]; if (timeout > 0) { #if defined(OF_HAVE_SOCKETS) [_streamObserver observeForTimeInterval: timeout]; #elif defined(OF_HAVE_THREADS) [_condition lock]; [_condition waitForTimeInterval: timeout]; [_condition unlock]; #else [OFThread sleepForTimeInterval: timeout]; #endif } } else { /* * No more timers: Just watch for streams until we get * an event. If a timer is added by another thread, it * cancels the observe. */ #if defined(OF_HAVE_SOCKETS) [_streamObserver observe]; #elif defined(OF_HAVE_THREADS) [_condition lock]; [_condition wait]; [_condition unlock]; #else [OFThread sleepForTimeInterval: 86400]; #endif } objc_autoreleasePoolPop(pool); } } - (void)stop { _running = false; #ifdef OF_HAVE_THREADS of_memory_write_barrier(); #endif #if defined(OF_HAVE_SOCKETS) [_streamObserver cancel]; #elif defined(OF_HAVE_THREADS) [_condition lock]; [_condition signal]; [_condition unlock]; #endif } @end |