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

os_clock.c

00001 /*-
00002  * See the file LICENSE for redistribution information.
00003  *
00004  * Copyright (c) 2001-2005
00005  *      Sleepycat Software.  All rights reserved.
00006  *
00007  * $Id: os_clock.c,v 12.1 2005/06/16 20:23:23 bostic Exp $
00008  */
00009 
00010 #include "db_config.h"
00011 
00012 #ifndef NO_SYSTEM_INCLUDES
00013 #include <sys/types.h>
00014 
00015 #if TIME_WITH_SYS_TIME
00016 #include <sys/time.h>
00017 #include <time.h>
00018 #else
00019 #if HAVE_SYS_TIME_H
00020 #include <sys/time.h>
00021 #else
00022 #include <time.h>
00023 #endif /* HAVE_SYS_TIME_H */
00024 #endif /* TIME_WITH SYS_TIME */
00025 
00026 #include <string.h>
00027 #endif
00028 
00029 #include "db_int.h"
00030 
00031 /*
00032  * __os_clock --
00033  *      Return the current time-of-day clock in seconds and microseconds.
00034  *
00035  * PUBLIC: void __os_clock __P((DB_ENV *, u_int32_t *, u_int32_t *));
00036  */
00037 void
00038 __os_clock(dbenv, secsp, usecsp)
00039         DB_ENV *dbenv;
00040         u_int32_t *secsp, *usecsp;      /* Seconds and microseconds. */
00041 {
00042         const char *sc;
00043         int ret;
00044 
00045 #if defined(HAVE_GETTIMEOFDAY)
00046         struct timeval tp;
00047 
00048         RETRY_CHK((gettimeofday(&tp, NULL)), ret);
00049         if (ret != 0) {
00050                 sc = "gettimeofday";
00051                 goto err;
00052         }
00053 
00054         if (secsp != NULL)
00055                 *secsp = (u_int32_t)tp.tv_sec;
00056         if (usecsp != NULL)
00057                 *usecsp = (u_int32_t)tp.tv_usec;
00058 #endif
00059 #if !defined(HAVE_GETTIMEOFDAY) && defined(HAVE_CLOCK_GETTIME)
00060         struct timespec tp;
00061 
00062         RETRY_CHK((clock_gettime(CLOCK_REALTIME, &tp)), ret);
00063         if (ret != 0) {
00064                 sc = "clock_gettime";
00065                 goto err;
00066         }
00067 
00068         if (secsp != NULL)
00069                 *secsp = tp.tv_sec;
00070         if (usecsp != NULL)
00071                 *usecsp = tp.tv_nsec / 1000;
00072 #endif
00073 #if !defined(HAVE_GETTIMEOFDAY) && !defined(HAVE_CLOCK_GETTIME)
00074         time_t now;
00075 
00076         RETRY_CHK((time(&now) == (time_t)-1 ? 1 : 0), ret);
00077         if (ret != 0) {
00078                 sc = "time";
00079                 goto err;
00080         }
00081 
00082         if (secsp != NULL)
00083                 *secsp = now;
00084         if (usecsp != NULL)
00085                 *usecsp = 0;
00086 #endif
00087         return;
00088 
00089 err:    __db_err(dbenv, "%s: %s", sc, strerror(ret));
00090         (void)__db_panic(dbenv, ret);
00091 }

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