about summary refs log tree commit diff
path: root/db2/os/os_spin.c
diff options
context:
space:
mode:
Diffstat (limited to 'db2/os/os_spin.c')
-rw-r--r--db2/os/os_spin.c41
1 files changed, 23 insertions, 18 deletions
diff --git a/db2/os/os_spin.c b/db2/os/os_spin.c
index fb693c2848..2fd21d018b 100644
--- a/db2/os/os_spin.c
+++ b/db2/os/os_spin.c
@@ -1,14 +1,14 @@
 /*-
  * See the file LICENSE for redistribution information.
  *
- * Copyright (c) 1997
+ * Copyright (c) 1997, 1998
  *	Sleepycat Software.  All rights reserved.
  */
 
 #include "config.h"
 
 #ifndef lint
-static const char sccsid[] = "@(#)os_spin.c	10.3 (Sleepycat) 11/25/97";
+static const char sccsid[] = "@(#)os_spin.c	10.7 (Sleepycat) 5/20/98";
 #endif /* not lint */
 
 #ifndef NO_SYSTEM_INCLUDES
@@ -29,28 +29,33 @@ static const char sccsid[] = "@(#)os_spin.c	10.3 (Sleepycat) 11/25/97";
 int
 __os_spin()
 {
-	extern int __db_tsl_spins;
+	static long sys_val;
 
 	/* If the application specified the spins, use its value. */
-	if (__db_tsl_spins != 0)
-		return (__db_tsl_spins);
+	if (DB_GLOBAL(db_tsl_spins) != 0)
+		return (DB_GLOBAL(db_tsl_spins));
+
+	/* If we've already figured this out, return the value. */
+	if (sys_val != 0)
+		return (sys_val);
 
 	/*
 	 * XXX
-	 * Sysconf: Solaris uses _SC_NPROCESSORS_ONLN to return the number
-	 * of online processors.  I don't know if this call is portable or
-	 * not.
+	 * Solaris and Linux use _SC_NPROCESSORS_ONLN to return the number of
+	 * online processors.  We don't want to repeatedly call sysconf because
+	 * it's quite expensive (requiring multiple filesystem accesses) under
+	 * Debian Linux.
+	 *
+	 * Spin 50 times per processor -- we have anecdotal evidence that this
+	 * is a reasonable value.
 	 */
 #if defined(HAVE_SYSCONF) && defined(_SC_NPROCESSORS_ONLN)
-	{
-		long sys_val;
-
-		sys_val = sysconf(_SC_NPROCESSORS_ONLN);
-		if (sys_val > 0)
-			return (sys_val * 50);
-	}
+	if ((sys_val = sysconf(_SC_NPROCESSORS_ONLN)) > 1)
+		sys_val *= 50;
+	else
+		sys_val = 1;
+#else
+	sys_val = 1;
 #endif
-
-	/* Default to a single processor. */
-	return (1);
+	return (sys_val);
 }