root/mpich2/trunk/src/pm/hydra/utils/timer/timer.c @ 4887

Revision 4887, 0.9 KB (checked in by balaji, 5 months ago)

Warning stomp.

Line 
1/* -*- Mode: C; c-basic-offset:4 ; -*- */
2/*
3 *  (C) 2008 by Argonne National Laboratory.
4 *      See COPYRIGHT in top-level directory.
5 */
6
7#include "hydra_utils.h"
8
9/* FIXME: Here we assume that the timer is gettimeofday. */
10
11void HYDU_time_set(HYD_Time * time_p, int *val)
12{
13    if (val == NULL) {
14        /* Set time to right now */
15        gettimeofday(time_p, NULL);
16    }
17    else {
18        time_p->tv_sec = *val;
19        time_p->tv_usec = 0;
20    }
21}
22
23
24int HYDU_time_left(HYD_Time start, HYD_Time timeout)
25{
26    HYD_Time now;
27    int time_left;
28
29    HYDU_FUNC_ENTER();
30
31    if (timeout.tv_sec < 0) {
32        time_left = -1;
33        goto fn_exit;
34    }
35    else {
36        gettimeofday(&now, NULL);
37        if (timeout.tv_sec > (now.tv_sec - start.tv_sec)) {
38            time_left = (1000 * (timeout.tv_sec - now.tv_sec + start.tv_sec));
39        }
40        else
41            time_left = 0;
42    }
43
44  fn_exit:
45    HYDU_FUNC_EXIT();
46    return time_left;
47}
Note: See TracBrowser for help on using the browser.