ObjFW  Check-in [c96dbe88c6]

Overview
Comment:Add -[OFTimer waitUntilDone].
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA3-256: c96dbe88c61d2fd13ea66474f11a5796b5742cdf2e63f77d037c5b0a7a98897c
User & Date: js on 2012-09-16 22:29:49
Other Links: manifest | tags
Context
2012-09-16
22:31
Add -[performSelector:onThread:waitUntilDone:]. check-in: e9cbd5e12a user: js tags: trunk
22:29
Add -[OFTimer waitUntilDone]. check-in: c96dbe88c6 user: js tags: trunk
22:26
Every OFThread now always has a run loop. check-in: 4c8f9edda8 user: js tags: trunk
Changes

Modified src/OFTimer.h from [ff1fcecae5] to [98ed7e03b4].

17
18
19
20
21
22
23

24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39

40
41
42
43
44
45
46
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48







+
















+







#import "OFObject.h"

#ifdef OF_HAVE_BLOCKS
typedef void (^of_timer_block_t)(void);
#endif

@class OFDate;
@class OFCondition;

/**
 * \brief A class for creating and firing timers.
 */
@interface OFTimer: OFObject <OFComparing>
{
	OFDate *fireDate;
	double interval;
	id target, object1, object2;
	SEL selector;
	uint8_t arguments;
	BOOL repeats;
#ifdef OF_HAVE_BLOCKS
	of_timer_block_t block;
#endif
	BOOL isValid;
	OFCondition *condition;
}

/**
 * \brief Creates and schedules a new timer with the specified time interval.
 *
 * \param interval The time interval after which the timer should be executed
 *		   when fired
280
281
282
283
284
285
286





287
282
283
284
285
286
287
288
289
290
291
292
293
294







+
+
+
+
+

 * \brief Returns the time interval in which the timer will repeat, if it is a
 *	  repeating timer.
 *
 * \return The time interval in which the timer will repeat, if it is a
 *	   repeating timer
 */
- (double)timeInterval;

/**
 * \brief Waits until the timer fired.
 */
- (void)waitUntilDone;
@end

Modified src/OFTimer.m from [925c86fe94] to [71481b674a].

15
16
17
18
19
20
21

22
23

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







+


+







 */

#include "config.h"

#import "OFTimer.h"
#import "OFDate.h"
#import "OFRunLoop.h"
#import "OFThread.h"

#import "OFInvalidArgumentException.h"
#import "OFNotImplementedException.h"

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

@implementation OFTimer
+ scheduledTimerWithTimeInterval: (double)interval
			  target: (id)target
193
194
195
196
197
198
199








200
201
202
203
204
205
206
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216







+
+
+
+
+
+
+
+








	[timer retain];
	objc_autoreleasePoolPop(pool);

	return [timer autorelease];
}
#endif

- init
{
	Class c = [self class];
	[self release];
	@throw [OFNotImplementedException exceptionWithClass: c
						    selector: _cmd];
}

- OF_initWithFireDate: (OFDate*)fireDate_
	     interval: (double)interval_
	       target: (id)target_
	     selector: (SEL)selector_
	       object: (id)object1_
	       object: (id)object2_
215
216
217
218
219
220
221

222
223
224
225
226
227
228
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239







+







		target = [target_ retain];
		selector = selector_;
		object1 = [object1_ retain];
		object2 = [object2_ retain];
		arguments = arguments_;
		repeats = repeats_;
		isValid = YES;
		condition = [[OFCondition alloc] init];
	} @catch (id e) {
		[self release];
		@throw e;
	}

	return self;
}
305
306
307
308
309
310
311

312
313
314
315
316
317
318
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330







+







	[fireDate release];
	[target release];
	[object1 release];
	[object2 release];
#ifdef OF_HAVE_BLOCKS
	[block release];
#endif
	[condition release];

	[super dealloc];
}

- (of_comparison_result_t)compare: (id <OFComparing>)object_
{
	OFTimer *otherTimer;
350
351
352
353
354
355
356




357
358
359
360
361
362
363
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379







+
+
+
+







				     withObject: object2];
			break;
		}
#ifdef OF_HAVE_BLOCKS
	}
#endif

	[condition lock];
	[condition signal];
	[condition unlock];

	if (repeats) {
		OFDate *old = fireDate;
		fireDate = [[OFDate alloc]
		    initWithTimeIntervalSinceNow: interval];
		[old release];

		[[OFRunLoop currentRunLoop] addTimer: self];
380
381
382
383
384
385
386







387
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410







+
+
+
+
+
+
+

	isValid = NO;
}

- (BOOL)isValid
{
	return isValid;
}

- (void)waitUntilDone
{
	[condition lock];
	[condition wait];
	[condition unlock];
}
@end