ObjFW  Diff

Differences From Artifact [a5c17b66d7]:

  • File src/OFRunLoop.m — part of check-in [7a8a5a2995] at 2012-11-24 00:07:49 on branch trunk — -[OFSortedList addObject:] -> -[insertObject:].

    The rationale behind this is that otherwise, there are two methods
    called addObject: with a different signature, the one from
    OFMutableArray and the one from OFSortedList. As OFSortedList is
    actually using insertion sort and all other methods on an OFList start
    with insert anyway, this is also more consistent. (user: js, size: 12903) [annotate] [blame] [check-ins using]

To Artifact [5845195cdf]:


16
17
18
19
20
21
22

23
24
25
26
27
28
29

#include "config.h"

#import "OFRunLoop.h"
#import "OFDictionary.h"
#import "OFThread.h"
#import "OFSortedList.h"

#import "OFTimer.h"
#import "OFDate.h"

#import "autorelease.h"
#import "macros.h"

static OFRunLoop *mainRunLoop = nil;







>







16
17
18
19
20
21
22
23
24
25
26
27
28
29
30

#include "config.h"

#import "OFRunLoop.h"
#import "OFDictionary.h"
#import "OFThread.h"
#import "OFSortedList.h"
#import "OFMutex.h"
#import "OFTimer.h"
#import "OFDate.h"

#import "autorelease.h"
#import "macros.h"

static OFRunLoop *mainRunLoop = nil;
262
263
264
265
266
267
268

269
270
271
272
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
299
300
301
302

- init
{
	self = [super init];

	@try {
		timersQueue = [[OFSortedList alloc] init];


		streamObserver = [[OFStreamObserver alloc] init];
		[streamObserver setDelegate: self];

		readQueues = [[OFMutableDictionary alloc] init];
	} @catch (id e) {
		[self release];
		@throw e;
	}

	return self;
}

- (void)dealloc
{
	[timersQueue release];

	[streamObserver release];
	[readQueues release];

	[super dealloc];
}

- (void)addTimer: (OFTimer*)timer
{
	@synchronized (timersQueue) {

		[timersQueue insertObject: timer];


	}

	[streamObserver cancel];
}

- (void)streamIsReadyForReading: (OFStream*)stream
{
	OFList *queue = [readQueues objectForKey: stream];
	of_list_object_t *listObject;







>
















>








|
>

>
>

>







263
264
265
266
267
268
269
270
271
272
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
299
300
301
302
303
304
305
306
307
308
309

- init
{
	self = [super init];

	@try {
		timersQueue = [[OFSortedList alloc] init];
		timersQueueLock = [[OFMutex alloc] init];

		streamObserver = [[OFStreamObserver alloc] init];
		[streamObserver setDelegate: self];

		readQueues = [[OFMutableDictionary alloc] init];
	} @catch (id e) {
		[self release];
		@throw e;
	}

	return self;
}

- (void)dealloc
{
	[timersQueue release];
	[timersQueueLock release];
	[streamObserver release];
	[readQueues release];

	[super dealloc];
}

- (void)addTimer: (OFTimer*)timer
{
	[timersQueueLock lock];
	@try {
		[timersQueue insertObject: timer];
	} @finally {
		[timersQueueLock unlock];
	}

	[streamObserver cancel];
}

- (void)streamIsReadyForReading: (OFStream*)stream
{
	OFList *queue = [readQueues objectForKey: stream];
	of_list_object_t *listObject;
526
527
528
529
530
531
532
533

534
535
536
537
538
539
540
541
542
543
544
545


546
547
548
549
550
551

552


553
554
555
556
557
558
559
{
	for (;;) {
		void *pool = objc_autoreleasePoolPush();
		OFDate *now = [OFDate date];
		OFTimer *timer;
		OFDate *nextTimer;

		@synchronized (timersQueue) {

			of_list_object_t *listObject =
			    [timersQueue firstListObject];

			if (listObject != NULL &&
			    [[listObject->object fireDate] compare: now] !=
			    OF_ORDERED_DESCENDING) {
				timer =
				    [[listObject->object retain] autorelease];

				[timersQueue removeListObject: listObject];
			} else
				timer = nil;


		}

		if ([timer isValid])
			[timer fire];

		@synchronized (timersQueue) {

			nextTimer = [[timersQueue firstObject] fireDate];


		}

		/* Watch for stream events until the next timer is due */
		if (nextTimer != nil) {
			double timeout = [nextTimer timeIntervalSinceNow];

			if (timeout > 0)







|
>












>
>





|
>

>
>







533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
{
	for (;;) {
		void *pool = objc_autoreleasePoolPush();
		OFDate *now = [OFDate date];
		OFTimer *timer;
		OFDate *nextTimer;

		[timersQueueLock lock];
		@try {
			of_list_object_t *listObject =
			    [timersQueue firstListObject];

			if (listObject != NULL &&
			    [[listObject->object fireDate] compare: now] !=
			    OF_ORDERED_DESCENDING) {
				timer =
				    [[listObject->object retain] autorelease];

				[timersQueue removeListObject: listObject];
			} else
				timer = nil;
		} @finally {
			[timersQueueLock unlock];
		}

		if ([timer isValid])
			[timer fire];

		[timersQueueLock lock];
		@try {
			nextTimer = [[timersQueue firstObject] fireDate];
		} @finally {
			[timersQueueLock unlock];
		}

		/* Watch for stream events until the next timer is due */
		if (nextTimer != nil) {
			double timeout = [nextTimer timeIntervalSinceNow];

			if (timeout > 0)