Main Page | Class Hierarchy | Data Structures | Directories | File List | Data Fields | Related Pages

os_spin.c

00001 /*-
00002  * See the file LICENSE for redistribution information.
00003  *
00004  * Copyright (c) 1997-2005
00005  *      Sleepycat Software.  All rights reserved.
00006  *
00007  * $Id: os_spin.c,v 12.3 2005/08/10 15:47:27 bostic Exp $
00008  */
00009 
00010 #include "db_config.h"
00011 
00012 #ifndef NO_SYSTEM_INCLUDES
00013 #include <sys/types.h>
00014 #if defined(HAVE_PSTAT_GETDYNAMIC)
00015 #include <sys/pstat.h>
00016 #endif
00017 
00018 #include <limits.h>                     /* Needed for sysconf on Solaris. */
00019 #endif
00020 
00021 #include "db_int.h"
00022 
00023 #if defined(HAVE_PSTAT_GETDYNAMIC)
00024 static int __os_pstat_getdynamic __P((void));
00025 
00026 /*
00027  * __os_pstat_getdynamic --
00028  *      HP/UX.
00029  */
00030 static int
00031 __os_pstat_getdynamic()
00032 {
00033         struct pst_dynamic psd;
00034 
00035         return (pstat_getdynamic(&psd,
00036             sizeof(psd), (size_t)1, 0) == -1 ? 1 : psd.psd_proc_cnt);
00037 }
00038 #endif
00039 
00040 #if defined(HAVE_SYSCONF) && defined(_SC_NPROCESSORS_ONLN)
00041 static u_int32_t __os_sysconf __P((void));
00042 
00043 /*
00044  * __os_sysconf --
00045  *      Solaris, Linux.
00046  */
00047 static u_int32_t
00048 __os_sysconf()
00049 {
00050         long nproc;
00051 
00052         nproc = sysconf(_SC_NPROCESSORS_ONLN);
00053         return ((u_int32_t)(nproc > 1 ? nproc : 1));
00054 }
00055 #endif
00056 
00057 /*
00058  * __os_spin --
00059  *      Set the number of default spins before blocking.
00060  *
00061  * PUBLIC: u_int32_t __os_spin __P((DB_ENV *));
00062  */
00063 u_int32_t
00064 __os_spin(dbenv)
00065         DB_ENV *dbenv;
00066 {
00067         u_int32_t tas_spins;
00068 
00069         COMPQUIET(dbenv, NULL);
00070 
00071         tas_spins = 1;
00072 #if defined(HAVE_PSTAT_GETDYNAMIC)
00073         tas_spins = __os_pstat_getdynamic();
00074 #endif
00075 #if defined(HAVE_SYSCONF) && defined(_SC_NPROCESSORS_ONLN)
00076         tas_spins = __os_sysconf();
00077 #endif
00078 
00079         /*
00080          * Spin 50 times per processor, we have anecdotal evidence that this
00081          * is a reasonable value.
00082          */
00083         if (tas_spins != 1)
00084                 tas_spins *= 50;
00085 
00086         return (tas_spins);
00087 }
00088 
00089 /*
00090  * __os_yield --
00091  *      Yield the processor.
00092  *
00093  * PUBLIC: void __os_yield __P((DB_ENV*, u_long));
00094  */
00095 void
00096 __os_yield(dbenv, usecs)
00097         DB_ENV *dbenv;
00098         u_long usecs;
00099 {
00100         if (DB_GLOBAL(j_yield) != NULL && DB_GLOBAL(j_yield)() == 0)
00101                 return;
00102 #ifdef HAVE_VXWORKS
00103         taskDelay(1);
00104 #endif
00105         __os_sleep(dbenv, 0, usecs);
00106 }

Generated on Sun Dec 25 12:14:42 2005 for Berkeley DB 4.4.16 by  doxygen 1.4.2