os_sleep.c

Go to the documentation of this file.
00001 /*-
00002  * See the file LICENSE for redistribution information.
00003  *
00004  * Copyright (c) 1997, 1998, 1999, 2000
00005  *      Sleepycat Software.  All rights reserved.
00006  */
00007 
00008 #include "config.h"
00009 
00010 #ifndef lint
00011 static const char revid[] = "$Id: os__sleep_8c-source.html,v 1.1 2008/06/08 10:21:31 sebdiaz Exp $";
00012 #endif /* not lint */
00013 
00014 #ifndef NO_SYSTEM_INCLUDES
00015 #include <sys/types.h>
00016 
00017 #ifdef HAVE_SYS_SELECT_H
00018 #include <sys/select.h>
00019 #endif
00020 
00021 #ifdef HAVE_VXWORKS
00022 #include <sys/times.h>
00023 #include <time.h>
00024 #else
00025 #if TIME_WITH_SYS_TIME
00026 #include <sys/time.h>
00027 #include <time.h>
00028 #else
00029 #if HAVE_SYS_TIME_H
00030 #include <sys/time.h>
00031 #else
00032 #include <time.h>
00033 #endif /* HAVE_SYS_TIME_H */
00034 #endif /* TIME_WITH SYS_TIME */
00035 #endif /* HAVE_VXWORKS */
00036 
00037 #include <string.h>
00038 #include <unistd.h>
00039 #endif
00040 
00041 #include "db_int.h"
00042 #include "os_jump.h"
00043 
00044 /*
00045  * CDB___os_sleep --
00046  *      Yield the processor for a period of time.
00047  *
00048  * PUBLIC: int CDB___os_sleep __P((DB_ENV *, u_long, u_long));
00049  */
00050 int
00051 CDB___os_sleep(dbenv, secs, usecs)
00052         DB_ENV *dbenv;
00053         u_long secs, usecs;             /* Seconds and microseconds. */
00054 {
00055         struct timeval t;
00056         int ret;
00057 
00058         /* Don't require that the values be normalized. */
00059         for (; usecs >= 1000000; usecs -= 1000000)
00060                 ++secs;
00061 
00062         if (CDB___db_jump.j_sleep != NULL)
00063                 return (CDB___db_jump.j_sleep(secs, usecs));
00064 
00065         /*
00066          * It's important that we yield the processor here so that other
00067          * processes or threads are permitted to run.
00068          */
00069         t.tv_sec = secs;
00070         t.tv_usec = usecs;
00071         ret =  select(0, NULL, NULL, NULL, &t) == -1 ? CDB___os_get_errno() : 0;
00072 
00073         if (ret != 0)
00074                 CDB___db_err(dbenv, "select: %s", strerror(ret));
00075 
00076         return (ret);
00077 }

Generated on Sun Jun 8 10:56:38 2008 for GNUmifluz by  doxygen 1.5.5