Update.
[glibc.git] / db2 / os / os_spin.c
blob2fd21d018b4a32be0b667da8cfed78e0e071fb7d
1 /*-
2 * See the file LICENSE for redistribution information.
4 * Copyright (c) 1997, 1998
5 * Sleepycat Software. All rights reserved.
6 */
8 #include "config.h"
10 #ifndef lint
11 static const char sccsid[] = "@(#)os_spin.c 10.7 (Sleepycat) 5/20/98";
12 #endif /* not lint */
14 #ifndef NO_SYSTEM_INCLUDES
15 #include <sys/types.h>
17 #include <limits.h>
18 #include <unistd.h>
19 #endif
21 #include "db_int.h"
24 * __os_spin --
25 * Return the number of default spins before blocking.
27 * PUBLIC: int __os_spin __P((void));
29 int
30 __os_spin()
32 static long sys_val;
34 /* If the application specified the spins, use its value. */
35 if (DB_GLOBAL(db_tsl_spins) != 0)
36 return (DB_GLOBAL(db_tsl_spins));
38 /* If we've already figured this out, return the value. */
39 if (sys_val != 0)
40 return (sys_val);
43 * XXX
44 * Solaris and Linux use _SC_NPROCESSORS_ONLN to return the number of
45 * online processors. We don't want to repeatedly call sysconf because
46 * it's quite expensive (requiring multiple filesystem accesses) under
47 * Debian Linux.
49 * Spin 50 times per processor -- we have anecdotal evidence that this
50 * is a reasonable value.
52 #if defined(HAVE_SYSCONF) && defined(_SC_NPROCESSORS_ONLN)
53 if ((sys_val = sysconf(_SC_NPROCESSORS_ONLN)) > 1)
54 sys_val *= 50;
55 else
56 sys_val = 1;
57 #else
58 sys_val = 1;
59 #endif
60 return (sys_val);