Differences From Artifact [30c14bee93]:
- File
src/OFRunLoop.m
— part of check-in
[55e7d380e4]
at
2012-09-12 06:11:06
on branch trunk
— OFRunLoop: Remove timer before possible read.
A timer always needs to be removed before its fireDate is changed,
otherwise, this will break the ordering in the OFSortedList. (user: js, size: 3141) [annotate] [blame] [check-ins using]
To Artifact [af64aebbb7]:
- File
src/OFRunLoop.m
— part of check-in
[df53f06922]
at
2012-09-12 06:11:46
on branch trunk
— Run loops have a stream observer now.
This makes async I/O possible! (user: js, size: 2880) [annotate] [blame] [check-ins using]
︙ | ︙ | |||
17 18 19 20 21 22 23 24 25 26 27 28 29 30 | #include "config.h" #import "OFRunLoop.h" #import "OFThread.h" #import "OFSortedList.h" #import "OFTimer.h" #import "OFDate.h" static OFTLSKey *currentRunLoopKey; static OFRunLoop *mainRunLoop; @implementation OFRunLoop + (void)initialize { | > | 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 | #include "config.h" #import "OFRunLoop.h" #import "OFThread.h" #import "OFSortedList.h" #import "OFTimer.h" #import "OFDate.h" #import "OFStreamObserver.h" static OFTLSKey *currentRunLoopKey; static OFRunLoop *mainRunLoop; @implementation OFRunLoop + (void)initialize { |
︙ | ︙ | |||
52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 | { self = [super init]; @try { void *pool = objc_autoreleasePoolPush(); timersQueue = [[[OFThread currentThread] _timersQueue] retain]; [OFThread setObject: self forTLSKey: currentRunLoopKey]; objc_autoreleasePoolPop(pool); } @catch (id e) { [self release]; @throw e; } return self; } - (void)dealloc { [timersQueue release]; [super dealloc]; } - (void)addTimer: (OFTimer*)timer { @synchronized (timersQueue) { [timersQueue addObject: timer]; } } - (void)run { for (;;) { void *pool = objc_autoreleasePoolPush(); OFDate *now = [OFDate date]; | > > > > | 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 | { self = [super init]; @try { void *pool = objc_autoreleasePoolPush(); timersQueue = [[[OFThread currentThread] _timersQueue] retain]; streamObserver = [[OFStreamObserver alloc] init]; [OFThread setObject: self forTLSKey: currentRunLoopKey]; objc_autoreleasePoolPop(pool); } @catch (id e) { [self release]; @throw e; } return self; } - (void)dealloc { [timersQueue release]; [streamObserver release]; [super dealloc]; } - (void)addTimer: (OFTimer*)timer { @synchronized (timersQueue) { [timersQueue addObject: timer]; } [streamObserver cancel]; } - (void)run { for (;;) { void *pool = objc_autoreleasePoolPush(); OFDate *now = [OFDate date]; |
︙ | ︙ | |||
107 108 109 110 111 112 113 | [timersQueue removeListObject: iter]; [timer fire]; objc_autoreleasePoolPop(pool2); } | | | < | > > | < < < < < < < < | < < < | > < > | 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 | [timersQueue removeListObject: iter]; [timer fire]; objc_autoreleasePoolPop(pool2); } /* Watch for stream events till the next timer is due */ if (iter != NULL) { double timeout = [[iter->object fireDate] timeIntervalSinceNow]; [streamObserver observeWithTimeout: timeout]; } 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. */ [streamObserver observe]; } } objc_autoreleasePoolPop(pool); } } @end |