ObjFW  Diff

Differences From Artifact [67276b0c18]:

  • File src/OFThread.m — part of check-in [77780c7596] at 2019-09-01 15:29:31 on branch trunk — OFThread: Allow specifying a name before starting

    This allows specifying a name before the thread gets started, so that
    the name can be decided by whoever starts the thread, rather than just
    by the thread itself once it's running.

    This is especially useful as some operating systems do not support
    changing the name of the thread once it's running. (user: js, size: 10645) [annotate] [blame] [check-ins using]

To Artifact [590ace3cab]:


82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
82
83
84
85
86
87
88




89
90
91
92
93
94
95







-
-
-
-







# import "OFThreadStillRunningException.h"
#endif

#ifdef OF_HAVE_ATOMIC_OPS
# import "atomic.h"
#endif

#ifdef OF_DJGPP
# define lrint(x) rint(x)
#endif

#if defined(OF_HAVE_THREADS)
# import "tlskey.h"
# if defined(OF_AMIGAOS) && defined(OF_HAVE_SOCKETS)
#  import "socket.h"
# endif

static of_tlskey_t threadSelfKey;
246
247
248
249
250
251
252
253

254
255
256
257
258
259
260
242
243
244
245
246
247
248

249
250
251
252
253
254
255
256







-
+







		@throw [OFOutOfRangeException exception];

	svcSleepThread((int64_t)(timeInterval * 1000000000));
#elif defined(HAVE_NANOSLEEP)
	struct timespec rqtp;

	rqtp.tv_sec = (time_t)timeInterval;
	rqtp.tv_nsec = lrint((timeInterval - rqtp.tv_sec) * 1000000000);
	rqtp.tv_nsec = (timeInterval - rqtp.tv_sec) * 1000000000;

	if (rqtp.tv_sec != trunc(timeInterval))
		@throw [OFOutOfRangeException exception];

	nanosleep(&rqtp, NULL);
#elif defined(OF_AMIGAOS)
	if (timeInterval * 50 > ULONG_MAX)
271
272
273
274
275
276
277
278
279


280
281
282
283
284
285
286
267
268
269
270
271
272
273


274
275
276
277
278
279
280
281
282







-
-
+
+







	while (counter--)
		swiWaitForVBlank();
#else
	if (timeInterval > UINT_MAX)
		@throw [OFOutOfRangeException exception];

	sleep((unsigned int)timeInterval);
	usleep((unsigned int)lrint(
	    (timeInterval - trunc(timeInterval)) * 1000000));
	usleep((unsigned int)
	    (timeInterval - (unsigned int)timeInterval) * 1000000);
#endif
}

+ (void)sleepUntilDate: (OFDate *)date
{
	[self sleepForTimeInterval: date.timeIntervalSinceNow];
}