Skip to content
This repository
Fetching contributors…

Cannot retrieve contributors at this time

file 272 lines (170 sloc) 5.628 kb
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272
/* File: "os_time.h", Time-stamp: <2008-09-03 14:33:47 feeley> */

/* Copyright (c) 1994-2008 by Marc Feeley, All Rights Reserved. */

#ifndef ___OS_TIME_H
#define ___OS_TIME_H

#include "os.h"


/*---------------------------------------------------------------------------*/


#define TIME_REFERENCE_POINT 1970

#define DAYS_UNTIL_JAN_1_2000(year) \
(730119 - ((year)-1)*365 - ((year)-1)/4 + ((year)-1)/100 - ((year)-1)/400)

#define DAYS_UNTIL_TIME_REFERENCE_POINT(year) \
(DAYS_UNTIL_JAN_1_2000(year) - DAYS_UNTIL_JAN_1_2000(TIME_REFERENCE_POINT))

#define JAN_1(year)(DAYS_UNTIL_TIME_REFERENCE_POINT(year) * 24 * 60 * 60)

#define FILETIME_TO_SECONDS(ft) \
(((ft).dwHighDateTime * 4294967296.0 + (ft).dwLowDateTime) / 1.0e7)

#define FILETIME_TO_TIME(ft) (FILETIME_TO_SECONDS(ft) - JAN_1(1601LL))


/*---------------------------------------------------------------------------*/


#define ___FLOAT_TIME_REPRESENTATION


#ifdef ___DIVISION_BY_ZERO_WORKS_PROPERLY
#define POS_INFINITY (1.0/0.0) /* positive infinity */
#define NEG_INFINITY (-1.0/0.0) /* negative infinity */
#else
#define POS_INFINITY (1.7976931348623157e308) /* positive infinity */
#define NEG_INFINITY (-1.7976931348623157e308) /* negative infinity */
#endif


#ifdef ___FLOAT_TIME_REPRESENTATION

typedef ___F64 ___time;

#define TIME_POS_INFINITY POS_INFINITY
#define TIME_NEG_INFINITY NEG_INFINITY

#endif


#ifdef ___INT_TIME_REPRESENTATION

typedef struct ___time_struct
  {
    ___SM32 secs;
    ___SM32 nsecs;
  } ___time;

#define TIME_POS_INFINITY { 2147483647, 999999999 }
#define TIME_NEG_INFINITY { -2147483648, 0 }

#endif


/*---------------------------------------------------------------------------*/


typedef struct ___time_module_struct
  {
    ___BOOL setup;

    ___time time_pos_infinity;
    ___time time_neg_infinity;

    ___F64 process_start_seconds; /* process start in real time */
    ___F64 current_heartbeat_interval;

    void (*heartbeat_interrupt_handler) ___PVOID;

#ifdef USE_dos_setvect_1Ch

    ___BOOL heartbeat_enabled;
    long heartbeat_interval;
    long heartbeat_countdown;
    void (__interrupt __far *prev_vector_1Ch) ___PVOID;

#define ___TIME_MODULE_INIT , 0, 0, 0, 0

#endif

#ifdef USE_DosStartTimer

    ___BOOL heartbeat_enabled;
    ___BOOL heartbeat_hev;
    ___BOOL heartbeat_tid;
    ___BOOL heartbeat_htimer;
    HEV hev;
    TID tid;
    HTIMER htimer;

#define ___TIME_MODULE_INIT , 0, 0, 0, 0, 0, 0, 0

#endif

#ifdef USE_VInstall

    ___BOOL heartbeat_enabled;
    ___BOOL heartbeat_task_installed;
    short heartbeat_task_ticks;
    VBLTask heartbeat_task;

#define ___TIME_MODULE_INIT , 0, 0, 0, 0

#endif

#ifdef USE_CreateThread

    ___BOOL heartbeat_enabled;
    DWORD heartbeat_interval;
    HANDLE heartbeat_thread;
    HANDLE heartbeat_update; /* heartbeat needs updating when signaled */

#define ___TIME_MODULE_INIT , 0, 0, 0, 0

#endif
  } ___time_module;


extern ___time_module ___time_mod;


/*---------------------------------------------------------------------------*/

/* Time management. */


extern void ___time_from_nsecs
   ___P((___time *tim,
         ___SM32 secs,
         ___SM32 nsecs),
        ());

extern void ___time_add
   ___P((___time *tim1,
         ___time tim2),
        ());

extern void ___time_subtract
   ___P((___time *tim1,
         ___time tim2),
        ());

extern ___BOOL ___time_equal
   ___P((___time tim1,
         ___time tim2),
        ());

extern ___BOOL ___time_less
   ___P((___time tim1,
         ___time tim2),
        ());

extern ___BOOL ___time_positive
   ___P((___time tim),
        ());

extern void ___time_get_current_time
   ___P((___time *tim),
        ());

extern void ___time_to_seconds
   ___P((___time tim,
         ___F64 *seconds),
        ());

extern void ___time_from_seconds
   ___P((___time *tim,
         ___F64 seconds),
        ());

extern void ___process_times
   ___P((___F64 *user,
         ___F64 *sys,
         ___F64 *real),
        ());

extern ___F64 ___set_heartbeat_interval
   ___P((___F64 seconds),
        ());

extern void ___absolute_time_to_relative_time
   ___P((___time tim,
         ___time *rtim),
        ());

#ifndef LINEEDITOR_WITH_NONBLOCKING_IO

extern void ___absolute_time_sleep
   ___P((___time tim),
        ());

#endif

#ifdef USE_select

extern void ___absolute_time_to_nonnegative_timeval
   ___P((___time tim,
         struct timeval **tv),
        ());

#endif

#ifdef USE_MsgWaitForMultipleObjects

extern void ___absolute_time_to_nonnegative_msecs
   ___P((___time tim,
         DWORD *ms),
        ());

#endif


/*---------------------------------------------------------------------------*/

/* Measurement of process times. */


extern void ___process_times
   ___P((___F64 *user,
         ___F64 *sys,
         ___F64 *real),
        ());


/*---------------------------------------------------------------------------*/

/* Heartbeat interrupt handling. */


extern ___SCMOBJ ___setup_heartbeat_interrupt_handling ___PVOID;

extern void ___cleanup_heartbeat_interrupt_handling ___PVOID;

extern void ___disable_heartbeat_interrupts ___PVOID;

extern void ___enable_heartbeat_interrupts ___PVOID;

extern ___F64 ___set_heartbeat_interval
   ___P((___F64 seconds),
        ());


/*---------------------------------------------------------------------------*/

/* Time module initialization/finalization. */


extern ___SCMOBJ ___setup_time_module
   ___P((void (*heartbeat_interrupt_handler) ___PVOID),
        ());

extern void ___cleanup_time_module ___PVOID;


/*---------------------------------------------------------------------------*/


#endif
Something went wrong with that request. Please try again.