~ubuntu-branches/ubuntu/edgy/rpm/edgy

« back to all changes in this revision

Viewing changes to db/os/os_sleep.c

  • Committer: Bazaar Package Importer
  • Author(s): Joey Hess
  • Date: 2002-01-22 20:56:57 UTC
  • Revision ID: james.westby@ubuntu.com-20020122205657-l74j50mr9z8ofcl5
Tags: upstream-4.0.3
ImportĀ upstreamĀ versionĀ 4.0.3

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*-
 
2
 * See the file LICENSE for redistribution information.
 
3
 *
 
4
 * Copyright (c) 1997-2001
 
5
 *      Sleepycat Software.  All rights reserved.
 
6
 */
 
7
 
 
8
#include "db_config.h"
 
9
 
 
10
#ifndef lint
 
11
static const char revid[] = "$Id: os_sleep.c,v 11.9 2001/01/31 14:16:19 bostic Exp $";
 
12
#endif /* not lint */
 
13
 
 
14
#ifndef NO_SYSTEM_INCLUDES
 
15
#include <sys/types.h>
 
16
 
 
17
#ifdef HAVE_SYS_SELECT_H
 
18
#include <sys/select.h>
 
19
#endif
 
20
 
 
21
#ifdef HAVE_VXWORKS
 
22
#include <sys/times.h>
 
23
#include <time.h>
 
24
#else
 
25
#if TIME_WITH_SYS_TIME
 
26
#include <sys/time.h>
 
27
#include <time.h>
 
28
#else
 
29
#if HAVE_SYS_TIME_H
 
30
#include <sys/time.h>
 
31
#else
 
32
#include <time.h>
 
33
#endif /* HAVE_SYS_TIME_H */
 
34
#endif /* TIME_WITH SYS_TIME */
 
35
#endif /* HAVE_VXWORKS */
 
36
 
 
37
#include <string.h>
 
38
#include <unistd.h>
 
39
#endif
 
40
 
 
41
#include "db_int.h"
 
42
#include "os_jump.h"
 
43
 
 
44
/*
 
45
 * __os_sleep --
 
46
 *      Yield the processor for a period of time.
 
47
 *
 
48
 * PUBLIC: int __os_sleep __P((DB_ENV *, u_long, u_long));
 
49
 */
 
50
int
 
51
__os_sleep(dbenv, secs, usecs)
 
52
        DB_ENV *dbenv;
 
53
        u_long secs, usecs;             /* Seconds and microseconds. */
 
54
{
 
55
        struct timeval t;
 
56
        int ret;
 
57
 
 
58
        /* Don't require that the values be normalized. */
 
59
        for (; usecs >= 1000000; usecs -= 1000000)
 
60
                ++secs;
 
61
 
 
62
        if (__db_jump.j_sleep != NULL)
 
63
                return (__db_jump.j_sleep(secs, usecs));
 
64
 
 
65
        /*
 
66
         * It's important that we yield the processor here so that other
 
67
         * processes or threads are permitted to run.
 
68
         */
 
69
        t.tv_sec = secs;
 
70
        t.tv_usec = usecs;
 
71
        ret = select(0, NULL, NULL, NULL, &t) == -1 ? __os_get_errno() : 0;
 
72
 
 
73
        if (ret != 0)
 
74
                __db_err(dbenv, "select: %s", strerror(ret));
 
75
 
 
76
        return (ret);
 
77
}