Overview
Comment: | OFTimer: Make rescheduling possible. |
---|---|
Downloads: | Tarball | ZIP archive | SQL archive |
Timelines: | family | ancestors | descendants | both | trunk |
Files: | files | file ages | folders |
SHA3-256: |
4572170728a33dc1a2de2e3b49ba6e58 |
User & Date: | js on 2012-12-20 13:57:13 |
Other Links: | manifest | tags |
Context
2012-12-20
| ||
14:20 | OFTimer: Release target in -[invalidate]. check-in: a86271a67a user: js tags: trunk | |
13:57 | OFTimer: Make rescheduling possible. check-in: 4572170728 user: js tags: trunk | |
13:03 | OFHTTPServer: Make is possible to stop the server. check-in: a31bba0947 user: js tags: trunk | |
Changes
Modified src/OFRunLoop.h from [414cbc9314] to [e4bd69633c].
︙ | |||
86 87 88 89 90 91 92 93 94 95 96 97 98 | 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 | + + | /*! * @brief Adds an OFTimer to the run loop. * * @param timer The timer to add */ - (void)addTimer: (OFTimer*)timer; - (void)OF_removeTimer: (OFTimer*)timer; /*! * @brief Starts the run loop. */ - (void)run; @end |
Modified src/OFRunLoop.m from [cee8e6c735] to [ce73e14376].
︙ | |||
314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 | 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 | + + + + + + + + + + + + + + + + + + + + | [timersQueueLock lock]; @try { [timersQueue insertObject: timer]; } @finally { [timersQueueLock unlock]; } [timer OF_setInRunLoop: self]; [streamObserver cancel]; } - (void)OF_removeTimer: (OFTimer*)timer { [timersQueueLock lock]; @try { of_list_object_t *iter; for (iter = [timersQueue firstListObject]; iter != NULL; iter = iter->next) { if ([iter->object isEqual: timer]) { [timersQueue removeListObject: iter]; break; } } } @finally { [timersQueueLock unlock]; } } - (void)streamIsReadyForReading: (OFStream*)stream { OFList *queue = [readQueues objectForKey: stream]; of_list_object_t *listObject; OF_ENSURE(queue != nil); |
︙ | |||
563 564 565 566 567 568 569 570 571 572 573 574 575 576 | 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 | + + | if (listObject != NULL && [[listObject->object fireDate] compare: now] != OF_ORDERED_DESCENDING) { timer = [[listObject->object retain] autorelease]; [timersQueue removeListObject: listObject]; [timer OF_setInRunLoop: nil]; } else timer = nil; } @finally { [timersQueueLock unlock]; } if ([timer isValid]) |
︙ |
Modified src/OFTimer.h from [91db3a9035] to [7d93190810].
︙ | |||
15 16 17 18 19 20 21 22 23 24 25 26 27 28 | 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 | + | */ #import "OFObject.h" @class OFTimer; @class OFDate; @class OFCondition; @class OFRunLoop; #ifdef OF_HAVE_BLOCKS typedef void (^of_timer_block_t)(OFTimer*); #endif /*! * @brief A class for creating and firing timers. |
︙ | |||
36 37 38 39 40 41 42 43 44 45 | 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 | + - + | uint8_t arguments; BOOL repeats; #ifdef OF_HAVE_BLOCKS of_timer_block_t block; #endif BOOL isValid, done; OFCondition *condition; OFRunLoop *inRunLoop; } #ifdef OF_HAVE_PROPERTIES |
︙ | |||
271 272 273 274 275 276 277 278 279 280 281 282 283 284 | 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 | + + + + + + + + + + + + | /*! * @brief Returns the next date at which the timer will fire. * * @return The next date at which the timer will fire */ - (OFDate*)fireDate; /*! * @brief Sets the next date at which the timer will fire. * * If the timer is already scheduled in a run loop, it will be rescheduled. * Note that rescheduling is an expensive operation, though it still might be * preferrable to reschedule instead of invalidating the timer and creating a * new one. * * @param fireDate The next date at which the timer will fire */ - (void)setFireDate: (OFDate*)fireDate; /*! * @brief Invalidates the timer, preventing it from firing. */ - (void)invalidate; /*! * @brief Returns whether the timer is valid. |
︙ | |||
296 297 298 299 300 301 302 303 | 310 311 312 313 314 315 316 317 318 319 | + + | */ - (double)timeInterval; /*! * @brief Waits until the timer fired. */ - (void)waitUntilDone; - (void)OF_setInRunLoop: (OFRunLoop*)inRunLoop; @end |
Modified src/OFTimer.m from [ccda29e08b] to [8cac3a9eb9].
︙ | |||
12 13 14 15 16 17 18 19 20 21 22 23 24 25 | 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 | + + | * Public License, either version 2 or 3, which can be found in the file * LICENSE.GPLv2 or LICENSE.GPLv3 respectively included in the packaging of this * file. */ #include "config.h" #include <assert.h> #import "OFTimer.h" #import "OFDate.h" #import "OFRunLoop.h" #import "OFCondition.h" #import "OFInvalidArgumentException.h" #import "OFNotImplementedException.h" |
︙ | |||
311 312 313 314 315 316 317 318 319 320 321 322 323 324 | 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 | + + + + + + | return self; } #endif - (void)dealloc { /* * The run loop references the timer, so it should never be deallocated * if it is still in a run loop. */ assert(inRunLoop == nil); [fireDate release]; [target release]; [object1 release]; [object2 release]; #ifdef OF_HAVE_BLOCKS [block release]; #endif |
︙ | |||
387 388 389 390 391 392 393 394 395 396 397 398 399 400 | 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 | + + + + + + + + + + + + + + + + | isValid = NO; } - (OFDate*)fireDate { OF_GETTER(fireDate, YES) } - (void)setFireDate: (OFDate*)fireDate_ { [self retain]; @try { @synchronized (self) { [inRunLoop OF_removeTimer: self]; OF_SETTER(fireDate, fireDate_, YES, 0) [inRunLoop addTimer: self]; } } @finally { [self release]; } } - (double)timeInterval { return interval; } - (void)invalidate |
︙ | |||
417 418 419 420 421 422 423 424 | 441 442 443 444 445 446 447 448 449 450 451 452 453 | + + + + + | } [condition wait]; } @finally { [condition unlock]; } } - (void)OF_setInRunLoop: (OFRunLoop*)inRunLoop_ { OF_SETTER(inRunLoop, inRunLoop_, YES, 0) } @end |