ObjFW  Diff

Differences From Artifact [646227ddee]:

To Artifact [f5145d052f]:


24
25
26
27
28
29
30
31
32

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


31
32
33
34
35
36
37
38







-
-
+







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

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

static OFTLSKey *currentRunLoopKey;
static OFRunLoop *mainRunLoop;
static OFRunLoop *mainRunLoop = nil;

#ifdef OF_HAVE_BLOCKS
@interface OFRunLoop_ReadQueueItem: OFObject
{
	void *buffer;
	size_t length;
	of_stream_async_read_block_t block;
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112

113

114
115

116
117

118
119



120
121

122
123
124

125

126

127
128

129
130
131
132
133
134
135
92
93
94
95
96
97
98






99
100
101
102
103
104
105
106

107
108

109


110


111
112
113
114

115
116
117

118
119
120

121


122
123
124
125
126
127
128
129







-
-
-
-
-
-







+
-
+

-
+
-
-
+
-
-
+
+
+

-
+


-
+

+
-
+
-
-
+








	[super dealloc];
}
@end
#endif

@implementation OFRunLoop
+ (void)initialize
{
	if (self == [OFRunLoop class])
		currentRunLoopKey = [[OFTLSKey alloc] init];
}

+ (OFRunLoop*)mainRunLoop
{
	return [[mainRunLoop retain] autorelease];
}

+ (OFRunLoop*)currentRunLoop
{
	OFThread *currentThread = [OFThread currentThread];
	OFRunLoop *runLoop = [OFThread objectForTLSKey: currentRunLoopKey];
	OFRunLoop *runLoop = [currentThread runLoop];

	if (runLoop == nil) {
	if (runLoop != nil)
		runLoop = [[OFRunLoop alloc] init];
		[OFThread setObject: runLoop
		return runLoop;
			  forTLSKey: currentRunLoopKey];
	}

	runLoop = [[[OFRunLoop alloc] init] autorelease];
	[currentThread _setRunLoop: runLoop];

	return [[runLoop retain] autorelease];
	return runLoop;
}

+ (void)_setMainRunLoop: (OFRunLoop*)mainRunLoop_
+ (void)_setMainRunLoop
{
	void *pool = objc_autoreleasePoolPush();
	mainRunLoop = [mainRunLoop_ retain];
	mainRunLoop = [[[OFThread currentThread] runLoop] retain];
	[OFThread setObject: mainRunLoop
		  forTLSKey: currentRunLoopKey];
	objc_autoreleasePoolPop(pool);
}

#ifdef OF_HAVE_BLOCKS
+ (void)_addAsyncReadForStream: (OFStream*)stream
			buffer: (void*)buffer
			length: (size_t)length
			 block: (of_stream_async_read_block_t)block
209
210
211
212
213
214
215
216
217

218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
203
204
205
206
207
208
209


210

211
212
213
214
215


216
217
218
219
220
221
222







-
-
+
-





-
-







#endif

- init
{
	self = [super init];

	@try {
		void *pool = objc_autoreleasePoolPush();

		timersQueue = [[OFSortedList alloc] init];
		timersQueue = [[[OFThread currentThread] _timersQueue] retain];

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

		readQueues = [[OFMutableDictionary alloc] init];

		objc_autoreleasePoolPop(pool);
	} @catch (id e) {
		[self release];
		@throw e;
	}

	return self;
}