summaryrefslogtreecommitdiff
path: root/src/microhttpd/mhd_mono_clock.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/microhttpd/mhd_mono_clock.c')
-rw-r--r--src/microhttpd/mhd_mono_clock.c96
1 files changed, 64 insertions, 32 deletions
diff --git a/src/microhttpd/mhd_mono_clock.c b/src/microhttpd/mhd_mono_clock.c
index a54673d2..353e04c0 100644
--- a/src/microhttpd/mhd_mono_clock.c
+++ b/src/microhttpd/mhd_mono_clock.c
@@ -130,6 +130,7 @@ enum _MHD_mono_clock_source
_MHD_CLOCK_PERFCOUNTER
};
+
/**
* Initialise monotonic seconds counter.
*/
@@ -149,74 +150,91 @@ MHD_monotonic_sec_counter_init (void)
mono_clock_service = _MHD_INVALID_CLOCK_SERV;
#endif /* HAVE_CLOCK_GET_TIME */
+ /* just a little syntactic trick to get the
+ various following ifdef's to work out nicely */
if (0)
- {
- } else
+ {
+ }
+ else
#ifdef HAVE_CLOCK_GETTIME
#ifdef CLOCK_MONOTONIC_COARSE
/* Linux-specific fast value-getting clock */
/* Can be affected by frequency adjustment and don't count time in suspend, */
/* but preferred since it's fast */
- if (0 == clock_gettime (CLOCK_MONOTONIC_COARSE, &ts))
+ if (0 == clock_gettime (CLOCK_MONOTONIC_COARSE,
+ &ts))
{
mono_clock_id = CLOCK_MONOTONIC_COARSE;
mono_clock_start = ts.tv_sec;
mono_clock_source = _MHD_CLOCK_GETTIME;
- } else
+ }
+ else
#endif /* CLOCK_MONOTONIC_COARSE */
#ifdef CLOCK_MONOTONIC_FAST
/* FreeBSD/DragonFly fast value-getting clock */
/* Can be affected by frequency adjustment, but preferred since it's fast */
- if (0 == clock_gettime (CLOCK_MONOTONIC_FAST, &ts))
+ if (0 == clock_gettime (CLOCK_MONOTONIC_FAST,
+ &ts))
{
mono_clock_id = CLOCK_MONOTONIC_FAST;
mono_clock_start = ts.tv_sec;
mono_clock_source = _MHD_CLOCK_GETTIME;
- } else
+ }
+ else
#endif /* CLOCK_MONOTONIC_COARSE */
#ifdef CLOCK_MONOTONIC_RAW
/* Linux-specific clock */
/* Not affected by frequency adjustment, but don't count time in suspend */
- if (0 == clock_gettime (CLOCK_MONOTONIC_RAW , &ts))
+ if (0 == clock_gettime (CLOCK_MONOTONIC_RAW,
+ &ts))
{
mono_clock_id = CLOCK_MONOTONIC_RAW;
mono_clock_start = ts.tv_sec;
mono_clock_source = _MHD_CLOCK_GETTIME;
- } else
+ }
+ else
#endif /* CLOCK_MONOTONIC_RAW */
#ifdef CLOCK_BOOTTIME
/* Linux-specific clock */
/* Count time in suspend so it's real monotonic on Linux, */
/* but can be slower value-getting than other clocks */
- if (0 == clock_gettime(CLOCK_BOOTTIME, &ts))
+ if (0 == clock_gettime (CLOCK_BOOTTIME,
+ &ts))
{
mono_clock_id = CLOCK_BOOTTIME;
mono_clock_start = ts.tv_sec;
mono_clock_source = _MHD_CLOCK_GETTIME;
- } else
+ }
+ else
#endif /* CLOCK_BOOTTIME */
#ifdef CLOCK_MONOTONIC
/* Monotonic clock */
/* Widely supported, may be affected by frequency adjustment */
/* On Linux it's not truly monotonic as it doesn't count time in suspend */
- if (0 == clock_gettime(CLOCK_MONOTONIC, &ts))
+ if (0 == clock_gettime (CLOCK_MONOTONIC,
+ &ts))
{
mono_clock_id = CLOCK_MONOTONIC;
mono_clock_start = ts.tv_sec;
mono_clock_source = _MHD_CLOCK_GETTIME;
- } else
+ }
+ else
#endif /* CLOCK_BOOTTIME */
#endif /* HAVE_CLOCK_GETTIME */
#ifdef HAVE_CLOCK_GET_TIME
/* Darwin-specific monotonic clock */
/* Should be monotonic as clock_set_time function always unconditionally */
/* failed on latest kernels */
- if (KERN_SUCCESS == host_get_clock_service(mach_host_self(), SYSTEM_CLOCK, &mono_clock_service) &&
- KERN_SUCCESS == clock_get_time(mono_clock_service, &cur_time))
+ if ( (KERN_SUCCESS == host_get_clock_service (mach_host_self(),
+ SYSTEM_CLOCK,
+ &mono_clock_service)) &&
+ (KERN_SUCCESS == clock_get_time (mono_clock_service,
+ &cur_time)) )
{
mono_clock_start = cur_time.tv_sec;
mono_clock_source = _MHD_CLOCK_GET_TIME;
- } else
+ }
+ else
#endif /* HAVE_CLOCK_GET_TIME */
#ifdef _WIN32
#if _WIN32_WINNT >= 0x0600
@@ -224,33 +242,39 @@ MHD_monotonic_sec_counter_init (void)
/* Available since Vista, ~15ms accuracy */
if (1)
{
- tick_start = GetTickCount64();
+ tick_start = GetTickCount64 ();
mono_clock_source = _MHD_CLOCK_GETTICKCOUNT64;
- } else
+ }
+ else
#else /* _WIN32_WINNT < 0x0600 */
/* W32 specific monotonic clock */
/* Available on Windows 2000 and later */
if (1)
{
- LARGE_INTEGER freq, perf_counter;
- QueryPerformanceFrequency(&freq); /* never fail on XP and later */
- QueryPerformanceCounter(&perf_counter); /* never fail on XP and later */
+ LARGE_INTEGER freq;
+ LARGE_INTEGER perf_counter;
+
+ QueryPerformanceFrequency (&freq); /* never fail on XP and later */
+ QueryPerformanceCounter (&perf_counter); /* never fail on XP and later */
perf_freq = freq.QuadPart;
perf_start = perf_counter.QuadPart;
mono_clock_source = _MHD_CLOCK_PERFCOUNTER;
- } else
+ }
+ else
#endif /* _WIN32_WINNT < 0x0600 */
#endif /* _WIN32 */
#ifdef HAVE_CLOCK_GETTIME
#ifdef CLOCK_HIGHRES
/* Solaris-specific monotonic high-resolution clock */
/* Not preferred due to be potentially resource-hungry */
- if (0 == clock_gettime (CLOCK_HIGHRES, &ts))
+ if (0 == clock_gettime (CLOCK_HIGHRES,
+ &ts))
{
mono_clock_id = CLOCK_HIGHRES;
mono_clock_start = ts.tv_sec;
mono_clock_source = _MHD_CLOCK_GETTIME;
- } else
+ }
+ else
#endif /* CLOCK_HIGHRES */
#endif /* HAVE_CLOCK_GETTIME */
#ifdef HAVE_GETHRTIME
@@ -258,9 +282,10 @@ MHD_monotonic_sec_counter_init (void)
/* Not preferred due to be potentially resource-hungry */
if (1)
{
- hrtime_start = gethrtime();
+ hrtime_start = gethrtime ();
mono_clock_source = _MHD_CLOCK_GETHRTIME;
- } else
+ }
+ else
#endif /* HAVE_GETHRTIME */
{
/* no suitable clock source was found */
@@ -272,7 +297,8 @@ MHD_monotonic_sec_counter_init (void)
(_MHD_INVALID_CLOCK_SERV != mono_clock_service) )
{
/* clock service was initialised but clock_get_time failed */
- mach_port_deallocate (mach_task_self(), mono_clock_service);
+ mach_port_deallocate (mach_task_self(),
+ mono_clock_service);
mono_clock_service = _MHD_INVALID_CLOCK_SERV;
}
#else
@@ -292,12 +318,14 @@ MHD_monotonic_sec_counter_finish (void)
#ifdef HAVE_CLOCK_GET_TIME
if (_MHD_INVALID_CLOCK_SERV != mono_clock_service)
{
- mach_port_deallocate(mach_task_self(), mono_clock_service);
+ mach_port_deallocate (mach_task_self(),
+ mono_clock_service);
mono_clock_service = _MHD_INVALID_CLOCK_SERV;
}
#endif /* HAVE_CLOCK_GET_TIME */
}
+
/**
* Monotonic seconds counter, useful for timeout calculation.
* Tries to be not affected by manually setting the system real time
@@ -311,15 +339,18 @@ MHD_monotonic_sec_counter (void)
#ifdef HAVE_CLOCK_GETTIME
struct timespec ts;
- if (_MHD_UNWANTED_CLOCK != mono_clock_id &&
- 0 == clock_gettime (mono_clock_id , &ts))
+ if ( (_MHD_UNWANTED_CLOCK != mono_clock_id) &&
+ (0 == clock_gettime (mono_clock_id ,
+ &ts)) )
return ts.tv_sec - mono_clock_start;
#endif /* HAVE_CLOCK_GETTIME */
#ifdef HAVE_CLOCK_GET_TIME
if (_MHD_INVALID_CLOCK_SERV != mono_clock_service)
{
mach_timespec_t cur_time;
- if (KERN_SUCCESS == clock_get_time(mono_clock_service, &cur_time))
+
+ if (KERN_SUCCESS == clock_get_time(mono_clock_service,
+ &cur_time))
return cur_time.tv_sec - mono_clock_start;
}
#endif /* HAVE_CLOCK_GET_TIME */
@@ -331,14 +362,15 @@ MHD_monotonic_sec_counter (void)
if (0 != perf_freq)
{
LARGE_INTEGER perf_counter;
- QueryPerformanceCounter(&perf_counter); /* never fail on XP and later */
+
+ QueryPerformanceCounter (&perf_counter); /* never fail on XP and later */
return (time_t)(((uint64_t)(perf_counter.QuadPart - perf_start)) / perf_freq);
}
#endif /* _WIN32_WINNT < 0x0600 */
#endif /* _WIN32 */
#ifdef HAVE_GETHRTIME
if (1)
- return (time_t)(((uint64_t)(gethrtime() - hrtime_start)) / 1000000000);
+ return (time_t)(((uint64_t) (gethrtime () - hrtime_start)) / 1000000000);
#endif /* HAVE_GETHRTIME */
return time (NULL) - sys_clock_start;