2 * See the file LICENSE for redistribution information.
4 * Copyright (c) 1997, 1998
5 * Sleepycat Software. All rights reserved.
11 static const char sccsid
[] = "@(#)os_spin.c 10.10 (Sleepycat) 10/12/98";
14 #ifndef NO_SYSTEM_INCLUDES
15 #include <sys/types.h>
16 #if defined(HAVE_PSTAT_GETDYNAMIC)
17 #include <sys/pstat.h>
27 #if defined(HAVE_PSTAT_GETDYNAMIC)
29 * __os_pstat_getdynamic --
33 __os_pstat_getdynamic()
35 struct pst_dynamic psd
;
37 return (pstat_getdynamic(&psd
,
38 sizeof(psd
), (size_t)1, 0) == -1 ? 1 : psd
.psd_proc_cnt
);
42 #if defined(HAVE_SYSCONF) && defined(_SC_NPROCESSORS_ONLN)
52 return ((nproc
= sysconf(_SC_NPROCESSORS_ONLN
)) > 1 ? nproc
: 1);
58 * Return the number of default spins before blocking.
60 * PUBLIC: int __os_spin __P((void));
66 * If the application specified a value or we've already figured it
70 * We don't want to repeatedly call the underlying function because
71 * it can be expensive (e.g., requiring multiple filesystem accesses
72 * under Debian Linux).
74 if (DB_GLOBAL(db_tsl_spins
) != 0)
75 return (DB_GLOBAL(db_tsl_spins
));
77 DB_GLOBAL(db_tsl_spins
) = 1;
78 #if defined(HAVE_PSTAT_GETDYNAMIC)
79 DB_GLOBAL(db_tsl_spins
) = __os_pstat_getdynamic();
81 #if defined(HAVE_SYSCONF) && defined(_SC_NPROCESSORS_ONLN)
82 DB_GLOBAL(db_tsl_spins
) = __os_sysconf();
86 * Spin 50 times per processor, we have anecdotal evidence that this
87 * is a reasonable value.
89 DB_GLOBAL(db_tsl_spins
) *= 50;
91 return (DB_GLOBAL(db_tsl_spins
));
96 * Yield the processor.
98 * PUBLIC: void __os_yield __P((u_long));
104 if (__db_jump
.j_yield
!= NULL
&& __db_jump
.j_yield() == 0)
106 __os_sleep(0, usecs
);