ObjFW  Check-in [db70226153]

Overview
Comment:Use nanosleep() if available.
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA3-256: db70226153483ea243e388de4e4213ef57c0b7337054507229f2995cc3c8cdca
User & Date: js on 2013-04-26 21:10:50
Other Links: manifest | tags
Context
2013-04-26
22:25
Better checks for functions used in OFFile. check-in: c01ed004b0 user: js tags: trunk
21:10
Use nanosleep() if available. check-in: db70226153 user: js tags: trunk
20:40
Make sure +[OFThread sleep*] is always available. check-in: 71d45a29d1 user: js tags: trunk
Changes

Modified configure.ac from [073b0b3501] to [5b0cf6b041].

569
570
571
572
573
574
575
576

577
578
579
580
581
582
583
584
585
586
587
588
569
570
571
572
573
574
575

576





577
578
579
580
581
582
583







-
+
-
-
-
-
-







AC_MSG_CHECKING(for atomic operations)
AS_IF([test x"$atomic_ops" != x"none"], [
	AC_DEFINE(OF_HAVE_ATOMIC_OPS, 1, [Whether we have atomic operations])
	AC_SUBST(ATOMIC_H, "atomic.h")
])
AC_MSG_RESULT($atomic_ops)

AC_CHECK_FUNC(gmtime_r, [
AC_CHECK_FUNCS([gmtime_r localtime_r nanosleep])
	AC_DEFINE(HAVE_GMTIME_R, 1, [Whether we have gmtime_r])
])
AC_CHECK_FUNC(localtime_r, [
	AC_DEFINE(HAVE_LOCALTIME_R, 1, [Whether we have localtime_r])
])

AC_ARG_ENABLE(sockets,
	AS_HELP_STRING([--disable-sockets], [disable socket support]))
AS_IF([test x"$enable_sockets" != x"no"], [
	AC_DEFINE(OF_HAVE_SOCKETS, 1, [Whether we have sockets])
	AC_SUBST(USE_SRCS_SOCKETS, '${SRCS_SOCKETS}')

Modified src/OFThread.m from [426c027f93] to [64480ed795].

18
19
20
21
22
23
24

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







+








#define OF_THREAD_M

#define __NO_EXT_QNX

#include <stdlib.h>
#include <math.h>
#include <time.h>

#ifndef _WIN32
# include <unistd.h>
#endif

#ifdef OF_HAVE_SCHED_YIELD
# include <sched.h>
180
181
182
183
184
185
186


187









188
189
190
191
192

193
194
195
196
197
198
199
200
201
202
203

204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
181
182
183
184
185
186
187
188
189

190
191
192
193
194
195
196
197
198
199
200
201
202

203
204
205
206
207
208
209
210
211
212
213

214













215
216
217
218
219
220
221







+
+
-
+
+
+
+
+
+
+
+
+




-
+










-
+
-
-
-
-
-
-
-
-
-
-
-
-
-







#endif

+ (void)sleepForTimeInterval: (double)seconds
{
	if (seconds < 0)
		@throw [OFOutOfRangeException exceptionWithClass: self];

#if defined(HAVE_NANOSLEEP)
	struct timespec rqtp;
#ifndef _WIN32

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

	if (rqtp.tv_sec != floor(seconds))
		@throw [OFOutOfRangeException exceptionWithClass: self];

	nanosleep(&rqtp, NULL);
#elif !defined(_WIN32)
	if (seconds > UINT_MAX)
		@throw [OFOutOfRangeException exceptionWithClass: self];

	sleep((unsigned int)seconds);
	usleep((useconds_t)rint((seconds - floor(seconds)) * 1000000));
	usleep((useconds_t)lrint((seconds - floor(seconds)) * 1000000));
#else
	if (seconds * 1000 > UINT_MAX)
		@throw [OFOutOfRangeException exceptionWithClass: self];

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

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

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

	sleep((unsigned int)seconds);
	usleep((useconds_t)rint((seconds - floor(seconds)) * 1000000));
#else
	if (seconds * 1000 > UINT_MAX)
		@throw [OFOutOfRangeException exceptionWithClass: self];

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

+ (void)yield
{
#ifdef OF_HAVE_SCHED_YIELD
	sched_yield();
#else

Modified src/exceptions/OFConditionBroadcastFailedException.h from [8280acbac2] to [ee86acd7f5].

11
12
13
14
15
16
17




18
19
20
21
22
23
24
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28







+
+
+
+







 * Alternatively, it may be distributed under the terms of the GNU General
 * Public License, either version 2 or 3, which can be found in the file
 * LICENSE.GPLv2 or LICENSE.GPLv3 respectively included in the packaging of this
 * file.
 */

#import "OFException.h"

#ifndef OF_HAVE_THREADS
# error No threads available!
#endif

@class OFCondition;

/*!
 * @brief An exception indicating broadcasting a condition failed.
 */
@interface OFConditionBroadcastFailedException: OFException

Modified src/exceptions/OFConditionSignalFailedException.h from [ce8cf52835] to [8c1e25e6f7].

11
12
13
14
15
16
17




18
19
20
21
22
23
24
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28







+
+
+
+







 * Alternatively, it may be distributed under the terms of the GNU General
 * Public License, either version 2 or 3, which can be found in the file
 * LICENSE.GPLv2 or LICENSE.GPLv3 respectively included in the packaging of this
 * file.
 */

#import "OFException.h"

#ifndef OF_HAVE_THREADS
# error No threads available!
#endif

@class OFCondition;

/*!
 * @brief An exception indicating signaling a condition failed.
 */
@interface OFConditionSignalFailedException: OFException

Modified src/exceptions/OFConditionStillWaitingException.h from [fdfddc2862] to [ac276fe3d0].

11
12
13
14
15
16
17




18
19
20
21
22
23
24
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28







+
+
+
+







 * Alternatively, it may be distributed under the terms of the GNU General
 * Public License, either version 2 or 3, which can be found in the file
 * LICENSE.GPLv2 or LICENSE.GPLv3 respectively included in the packaging of this
 * file.
 */

#import "OFException.h"

#ifndef OF_HAVE_THREADS
# error No threads available!
#endif

@class OFCondition;

/*!
 * @brief An exception indicating that a thread is still waiting for a
 *	  condition.
 */

Modified src/exceptions/OFConditionWaitFailedException.h from [c95a31d0d6] to [3dfb34d904].

11
12
13
14
15
16
17




18
19
20
21
22
23
24
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28







+
+
+
+







 * Alternatively, it may be distributed under the terms of the GNU General
 * Public License, either version 2 or 3, which can be found in the file
 * LICENSE.GPLv2 or LICENSE.GPLv3 respectively included in the packaging of this
 * file.
 */

#import "OFException.h"

#ifndef OF_HAVE_THREADS
# error No threads available!
#endif

@class OFCondition;

/*!
 * @brief An exception indicating waiting for a condition failed.
 */
@interface OFConditionWaitFailedException: OFException

Modified src/exceptions/OFThreadJoinFailedException.h from [8ae844634a] to [cce8752e74].

11
12
13
14
15
16
17




18
19
20
21
22
23
24
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28







+
+
+
+







 * Alternatively, it may be distributed under the terms of the GNU General
 * Public License, either version 2 or 3, which can be found in the file
 * LICENSE.GPLv2 or LICENSE.GPLv3 respectively included in the packaging of this
 * file.
 */

#import "OFException.h"

#ifndef OF_HAVE_THREADS
# error No threads available!
#endif

@class OFThread;

/*!
 * @brief An exception indicating that joining a thread failed.
 */
@interface OFThreadJoinFailedException: OFException

Modified src/exceptions/OFThreadStartFailedException.h from [b941a35e28] to [81a280beae].

11
12
13
14
15
16
17




18
19
20
21
22
23
24
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28







+
+
+
+







 * Alternatively, it may be distributed under the terms of the GNU General
 * Public License, either version 2 or 3, which can be found in the file
 * LICENSE.GPLv2 or LICENSE.GPLv3 respectively included in the packaging of this
 * file.
 */

#import "OFException.h"

#ifndef OF_HAVE_THREADS
# error No threads available!
#endif

@class OFThread;

/*!
 * @brief An exception indicating that starting a thread failed.
 */
@interface OFThreadStartFailedException: OFException

Modified src/exceptions/OFThreadStillRunningException.h from [405b10fbdf] to [4064d31434].

11
12
13
14
15
16
17




18
19
20
21
22
23
24
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28







+
+
+
+







 * Alternatively, it may be distributed under the terms of the GNU General
 * Public License, either version 2 or 3, which can be found in the file
 * LICENSE.GPLv2 or LICENSE.GPLv3 respectively included in the packaging of this
 * file.
 */

#import "OFException.h"

#ifndef OF_HAVE_THREADS
# error No threads available!
#endif

@class OFThread;

/*!
 * @brief An exception indicating that a thread is still running.
 */
@interface OFThreadStillRunningException: OFException