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

os_sleep.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_sleep.c,v 12.2 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 
00015 #ifdef HAVE_SYS_SELECT_H
00016 #include <sys/select.h>
00017 #endif
00018 
00019 #ifdef HAVE_VXWORKS
00020 #include <sys/times.h>
00021 #include <time.h>
00022 #include <selectLib.h>
00023 #else
00024 #if TIME_WITH_SYS_TIME
00025 #include <sys/time.h>
00026 #include <time.h>
00027 #else
00028 #if HAVE_SYS_TIME_H
00029 #include <sys/time.h>
00030 #else
00031 #include <time.h>
00032 #endif /* HAVE_SYS_TIME_H */
00033 #endif /* TIME_WITH SYS_TIME */
00034 #endif /* HAVE_VXWORKS */
00035 
00036 #include <string.h>
00037 #endif
00038 
00039 #include "db_int.h"
00040 
00041 /*
00042  * __os_sleep --
00043  *      Yield the processor for a period of time.
00044  *
00045  * PUBLIC: void __os_sleep __P((DB_ENV *, u_long, u_long));
00046  */
00047 void
00048 __os_sleep(dbenv, secs, usecs)
00049         DB_ENV *dbenv;
00050         u_long secs, usecs;             /* Seconds and microseconds. */
00051 {
00052         struct timeval t;
00053         int ret;
00054 
00055         /* Don't require that the values be normalized. */
00056         for (; usecs >= 1000000; usecs -= 1000000)
00057                 ++secs;
00058 
00059         if (DB_GLOBAL(j_sleep) != NULL) {
00060                 (void)DB_GLOBAL(j_sleep)(secs, usecs);
00061                 return;
00062         }
00063 
00064         /*
00065          * It's important that we yield the processor here so that other
00066          * processes or threads are permitted to run.
00067          *
00068          * Sheer raving paranoia -- don't select for 0 time.
00069          */
00070         t.tv_sec = (long)secs;
00071         if (secs == 0 && usecs == 0)
00072                 t.tv_usec = 1;
00073         else
00074                 t.tv_usec = (long)usecs;
00075 
00076         /*
00077          * We don't catch interrupts and restart the system call here, unlike
00078          * other Berkeley DB system calls.  This may be a user attempting to
00079          * interrupt a sleeping DB utility (for example, db_checkpoint), and
00080          * we want the utility to see the signal and quit.  This assumes it's
00081          * always OK for DB to sleep for less time than originally scheduled.
00082          */
00083         if (select(0, NULL, NULL, NULL, &t) == -1)
00084                  if ((ret = __os_get_errno()) != EINTR)
00085                         __db_err(dbenv, "select: %s", strerror(ret));
00086 }

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