| 38 | // |
| 39 | |
| 40 | double // O - Elapsed seconds |
| 41 | _cupsGetClock(void) |
| 42 | { |
| 43 | double secs; // Elapsed seconds |
| 44 | #ifdef _WIN32 |
| 45 | ULONGLONG curtick; // Current tick count |
| 46 | #else |
| 47 | # if defined(CLOCK_MONOTONIC) || defined(CLOCK_MONOTONIC_RAW) |
| 48 | struct timespec curclock; // Current clock value |
| 49 | # endif // CLOCK_MONOTONIC || CLOCK_MONOTONIC_RAW |
| 50 | struct timeval curtime; // Current time value |
| 51 | #endif // _WIN32 |
| 52 | |
| 53 | |
| 54 | _cupsMutexLock(&cups_clock_mutex); |
| 55 | |
| 56 | #ifdef _WIN32 |
| 57 | // Get the current tick count in milliseconds... |
| 58 | curtick = GetTickCount64(); |
| 59 | |
| 60 | if (!cups_clock_init) |
| 61 | { |
| 62 | // First time through initialize the initial tick count... |
| 63 | cups_clock_init = 1; |
| 64 | cups_first_tick = curtick; |
| 65 | } |
| 66 | |
| 67 | // Convert ticks to seconds... |
| 68 | if (curtick < cups_first_tick) |
| 69 | secs = 0.0; |
| 70 | else |
| 71 | secs = 0.001 * (curtick - cups_first_tick); |
| 72 | |
| 73 | #else |
| 74 | # if defined(CLOCK_MONOTONIC) || defined(CLOCK_MONOTONIC_RAW) |
| 75 | // Get the current tick count in milliseconds... |
| 76 | # ifdef CLOCK_MONOTONIC_RAW |
| 77 | if (!clock_gettime(CLOCK_MONOTONIC_RAW, &curclock)) |
| 78 | # else |
| 79 | if (!clock_gettime(CLOCK_MONOTONIC, &curclock)) |
| 80 | # endif // CLOCK_MONOTONIC_RAW |
| 81 | { |
| 82 | if (!cups_clock_init) |
| 83 | { |
| 84 | // First time through initialize the initial clock value... |
| 85 | cups_clock_init = 1; |
| 86 | cups_first_clock = curclock; |
| 87 | } |
| 88 | |
| 89 | // Convert clock value to seconds... |
| 90 | if ((secs = curclock.tv_sec - cups_first_clock.tv_sec + 0.000000001 * (curclock.tv_nsec - cups_first_clock.tv_nsec)) < 0.0) |
| 91 | secs = 0.0; |
| 92 | } |
| 93 | else |
| 94 | # endif // CLOCK_MONOTONIC || CLOCK_MONOTONIC_RAW |
| 95 | { |
| 96 | gettimeofday(&curtime, /*tzp*/NULL); |
| 97 |
no test coverage detected