aboutsummaryrefslogtreecommitdiffstats
path: root/contrib/libs/curl/lib/timeval.c
diff options
context:
space:
mode:
authordeshevoy <deshevoy@yandex-team.ru>2022-02-10 16:46:57 +0300
committerDaniil Cherednik <dcherednik@yandex-team.ru>2022-02-10 16:46:57 +0300
commit28148f76dbfcc644d96427d41c92f36cbf2fdc6e (patch)
treeb83306b6e37edeea782e9eed673d89286c4fef35 /contrib/libs/curl/lib/timeval.c
parente988f30484abe5fdeedcc7a5d3c226c01a21800c (diff)
downloadydb-28148f76dbfcc644d96427d41c92f36cbf2fdc6e.tar.gz
Restoring authorship annotation for <deshevoy@yandex-team.ru>. Commit 2 of 2.
Diffstat (limited to 'contrib/libs/curl/lib/timeval.c')
-rw-r--r--contrib/libs/curl/lib/timeval.c160
1 files changed, 80 insertions, 80 deletions
diff --git a/contrib/libs/curl/lib/timeval.c b/contrib/libs/curl/lib/timeval.c
index 8a3e99b81f..8523dad400 100644
--- a/contrib/libs/curl/lib/timeval.c
+++ b/contrib/libs/curl/lib/timeval.c
@@ -29,9 +29,9 @@ extern LARGE_INTEGER Curl_freq;
extern bool Curl_isVistaOrGreater;
/* In case of bug fix this function has a counterpart in tool_util.c */
-struct curltime Curl_now(void)
+struct curltime Curl_now(void)
{
- struct curltime now;
+ struct curltime now;
if(Curl_isVistaOrGreater) { /* QPC timer might have issues pre-Vista */
LARGE_INTEGER count;
QueryPerformanceCounter(&count);
@@ -44,12 +44,12 @@ struct curltime Curl_now(void)
#if defined(_MSC_VER)
#pragma warning(push)
#pragma warning(disable:28159)
-#endif
+#endif
DWORD milliseconds = GetTickCount();
#if defined(_MSC_VER)
#pragma warning(pop)
#endif
-
+
now.tv_sec = milliseconds / 1000;
now.tv_usec = (milliseconds % 1000) * 1000;
}
@@ -58,7 +58,7 @@ struct curltime Curl_now(void)
#elif defined(HAVE_CLOCK_GETTIME_MONOTONIC)
-struct curltime Curl_now(void)
+struct curltime Curl_now(void)
{
/*
** clock_gettime() is granted to be increased monotonically when the
@@ -70,27 +70,27 @@ struct curltime Curl_now(void)
#ifdef HAVE_GETTIMEOFDAY
struct timeval now;
#endif
- struct curltime cnow;
+ struct curltime cnow;
struct timespec tsnow;
-
- /*
- ** clock_gettime() may be defined by Apple's SDK as weak symbol thus
- ** code compiles but fails during run-time if clock_gettime() is
- ** called on unsupported OS version.
- */
-#if defined(__APPLE__) && (HAVE_BUILTIN_AVAILABLE == 1)
- bool have_clock_gettime = FALSE;
- if(__builtin_available(macOS 10.12, iOS 10, tvOS 10, watchOS 3, *))
- have_clock_gettime = TRUE;
-#endif
-
- if(
-#if defined(__APPLE__) && (HAVE_BUILTIN_AVAILABLE == 1)
- have_clock_gettime &&
-#endif
- (0 == clock_gettime(CLOCK_MONOTONIC, &tsnow))) {
- cnow.tv_sec = tsnow.tv_sec;
- cnow.tv_usec = (unsigned int)(tsnow.tv_nsec / 1000);
+
+ /*
+ ** clock_gettime() may be defined by Apple's SDK as weak symbol thus
+ ** code compiles but fails during run-time if clock_gettime() is
+ ** called on unsupported OS version.
+ */
+#if defined(__APPLE__) && (HAVE_BUILTIN_AVAILABLE == 1)
+ bool have_clock_gettime = FALSE;
+ if(__builtin_available(macOS 10.12, iOS 10, tvOS 10, watchOS 3, *))
+ have_clock_gettime = TRUE;
+#endif
+
+ if(
+#if defined(__APPLE__) && (HAVE_BUILTIN_AVAILABLE == 1)
+ have_clock_gettime &&
+#endif
+ (0 == clock_gettime(CLOCK_MONOTONIC, &tsnow))) {
+ cnow.tv_sec = tsnow.tv_sec;
+ cnow.tv_usec = (unsigned int)(tsnow.tv_nsec / 1000);
}
/*
** Even when the configure process has truly detected monotonic clock
@@ -98,54 +98,54 @@ struct curltime Curl_now(void)
** run-time. When this occurs simply fallback to other time source.
*/
#ifdef HAVE_GETTIMEOFDAY
- else {
+ else {
(void)gettimeofday(&now, NULL);
- cnow.tv_sec = now.tv_sec;
- cnow.tv_usec = (unsigned int)now.tv_usec;
- }
+ cnow.tv_sec = now.tv_sec;
+ cnow.tv_usec = (unsigned int)now.tv_usec;
+ }
#else
else {
- cnow.tv_sec = time(NULL);
- cnow.tv_usec = 0;
+ cnow.tv_sec = time(NULL);
+ cnow.tv_usec = 0;
}
#endif
- return cnow;
+ return cnow;
+}
+
+#elif defined(HAVE_MACH_ABSOLUTE_TIME)
+
+#include <stdint.h>
+#include <mach/mach_time.h>
+
+struct curltime Curl_now(void)
+{
+ /*
+ ** Monotonic timer on Mac OS is provided by mach_absolute_time(), which
+ ** returns time in Mach "absolute time units," which are platform-dependent.
+ ** To convert to nanoseconds, one must use conversion factors specified by
+ ** mach_timebase_info().
+ */
+ static mach_timebase_info_data_t timebase;
+ struct curltime cnow;
+ uint64_t usecs;
+
+ if(0 == timebase.denom)
+ (void) mach_timebase_info(&timebase);
+
+ usecs = mach_absolute_time();
+ usecs *= timebase.numer;
+ usecs /= timebase.denom;
+ usecs /= 1000;
+
+ cnow.tv_sec = usecs / 1000000;
+ cnow.tv_usec = (int)(usecs % 1000000);
+
+ return cnow;
}
-#elif defined(HAVE_MACH_ABSOLUTE_TIME)
-
-#include <stdint.h>
-#include <mach/mach_time.h>
-
-struct curltime Curl_now(void)
-{
- /*
- ** Monotonic timer on Mac OS is provided by mach_absolute_time(), which
- ** returns time in Mach "absolute time units," which are platform-dependent.
- ** To convert to nanoseconds, one must use conversion factors specified by
- ** mach_timebase_info().
- */
- static mach_timebase_info_data_t timebase;
- struct curltime cnow;
- uint64_t usecs;
-
- if(0 == timebase.denom)
- (void) mach_timebase_info(&timebase);
-
- usecs = mach_absolute_time();
- usecs *= timebase.numer;
- usecs /= timebase.denom;
- usecs /= 1000;
-
- cnow.tv_sec = usecs / 1000000;
- cnow.tv_usec = (int)(usecs % 1000000);
-
- return cnow;
-}
-
#elif defined(HAVE_GETTIMEOFDAY)
-struct curltime Curl_now(void)
+struct curltime Curl_now(void)
{
/*
** gettimeofday() is not granted to be increased monotonically, due to
@@ -153,22 +153,22 @@ struct curltime Curl_now(void)
** forward or backward in time.
*/
struct timeval now;
- struct curltime ret;
+ struct curltime ret;
(void)gettimeofday(&now, NULL);
- ret.tv_sec = now.tv_sec;
- ret.tv_usec = (int)now.tv_usec;
- return ret;
+ ret.tv_sec = now.tv_sec;
+ ret.tv_usec = (int)now.tv_usec;
+ return ret;
}
#else
-struct curltime Curl_now(void)
+struct curltime Curl_now(void)
{
/*
** time() returns the value of time in seconds since the Epoch.
*/
- struct curltime now;
- now.tv_sec = time(NULL);
+ struct curltime now;
+ now.tv_sec = time(NULL);
now.tv_usec = 0;
return now;
}
@@ -176,31 +176,31 @@ struct curltime Curl_now(void)
#endif
/*
- * Returns: time difference in number of milliseconds. For too large diffs it
- * returns max value.
+ * Returns: time difference in number of milliseconds. For too large diffs it
+ * returns max value.
*
- * @unittest: 1323
+ * @unittest: 1323
*/
-timediff_t Curl_timediff(struct curltime newer, struct curltime older)
+timediff_t Curl_timediff(struct curltime newer, struct curltime older)
{
timediff_t diff = (timediff_t)newer.tv_sec-older.tv_sec;
if(diff >= (TIMEDIFF_T_MAX/1000))
return TIMEDIFF_T_MAX;
else if(diff <= (TIMEDIFF_T_MIN/1000))
return TIMEDIFF_T_MIN;
- return diff * 1000 + (newer.tv_usec-older.tv_usec)/1000;
+ return diff * 1000 + (newer.tv_usec-older.tv_usec)/1000;
}
/*
- * Returns: time difference in number of microseconds. For too large diffs it
- * returns max value.
+ * Returns: time difference in number of microseconds. For too large diffs it
+ * returns max value.
*/
-timediff_t Curl_timediff_us(struct curltime newer, struct curltime older)
+timediff_t Curl_timediff_us(struct curltime newer, struct curltime older)
{
timediff_t diff = (timediff_t)newer.tv_sec-older.tv_sec;
if(diff >= (TIMEDIFF_T_MAX/1000000))
return TIMEDIFF_T_MAX;
else if(diff <= (TIMEDIFF_T_MIN/1000000))
return TIMEDIFF_T_MIN;
- return diff * 1000000 + newer.tv_usec-older.tv_usec;
+ return diff * 1000000 + newer.tv_usec-older.tv_usec;
}