ObjFW  Check-in [6ec0a033bd]

Overview
Comment:Fix calculation of microseconds.
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA3-256: 6ec0a033bded1bcda858d7cf5dd96b791ebf618ae496b8d9765b54a662628620
User & Date: js on 2011-09-19 11:39:15
Other Links: manifest | tags
Context
2011-09-19
12:07
Improve OFStreamObserver. check-in: d3f6cf9293 user: js tags: trunk
11:39
Fix calculation of microseconds. check-in: 6ec0a033bd user: js tags: trunk
2011-09-18
20:52
Fix a typo. check-in: e5cfcebae5 user: js tags: trunk
Changes

Modified src/OFDate.m from [0cf451e330] to [127168a624].

371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
	[element autorelease];

	return element;
}

- (uint32_t)microsecond
{
	return (uint32_t)nearbyint(remainder(seconds, 1) * 1000000);
}

- (uint8_t)second
{
	GMTIME_RET(tm_sec)
}








|







371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
	[element autorelease];

	return element;
}

- (uint32_t)microsecond
{
	return (uint32_t)fmod(seconds * 1000000, 1000000);
}

- (uint8_t)second
{
	GMTIME_RET(tm_sec)
}

Modified src/OFThread.m from [95ced5e160] to [e46284151e].

164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
		@throw [OFOutOfRangeException newWithClass: self];

#ifndef _WIN32
	if (seconds > UINT_MAX)
		@throw [OFOutOfRangeException newWithClass: self];

	sleep((unsigned int)seconds);
	usleep((uint32_t)nearbyint(remainder(seconds, 1) * 1000000));
#else
	if (seconds * 1000 > UINT_MAX)
		@throw [OFOutOfRangeException newWithClass: self];

	Sleep((unsigned int)(seconds * 1000));
#endif
}

+ (void)sleepUntilDate: (OFDate*)date
{
	double seconds = [date timeIntervalSinceNow];

#ifndef _WIN32
	if (seconds > UINT_MAX)
		@throw [OFOutOfRangeException newWithClass: self];

	sleep((unsigned int)seconds);
	usleep((uint32_t)nearbyint(remainder(seconds, 1) * 1000000));
#else
	if (seconds * 1000 > UINT_MAX)
		@throw [OFOutOfRangeException newWithClass: self];

	Sleep((unsigned int)(seconds * 1000));
#endif
}







|

















|







164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
		@throw [OFOutOfRangeException newWithClass: self];

#ifndef _WIN32
	if (seconds > UINT_MAX)
		@throw [OFOutOfRangeException newWithClass: self];

	sleep((unsigned int)seconds);
	usleep((useconds_t)fmod(seconds * 1000000, 1000000));
#else
	if (seconds * 1000 > UINT_MAX)
		@throw [OFOutOfRangeException newWithClass: self];

	Sleep((unsigned int)(seconds * 1000));
#endif
}

+ (void)sleepUntilDate: (OFDate*)date
{
	double seconds = [date timeIntervalSinceNow];

#ifndef _WIN32
	if (seconds > UINT_MAX)
		@throw [OFOutOfRangeException newWithClass: self];

	sleep((unsigned int)seconds);
	usleep((useconds_t)fmod(seconds * 1000000, 1000000));
#else
	if (seconds * 1000 > UINT_MAX)
		@throw [OFOutOfRangeException newWithClass: self];

	Sleep((unsigned int)(seconds * 1000));
#endif
}