Commit e4e173e8 by Peter Pettersson

Allow compilation on systems without CLOCK_MONOTONIC

Makes usage of CLOCK_MONOTONIC conditional and makes functions that uses
git__timer handle clock resynchronization.

Call gettimeofday with tzp set to NULL as required by
https://pubs.opengroup.org/onlinepubs/9699919799/functions/gettimeofday.html
parent f15a6792
...@@ -251,7 +251,7 @@ int git_packbuilder_insert(git_packbuilder *pb, const git_oid *oid, ...@@ -251,7 +251,7 @@ int git_packbuilder_insert(git_packbuilder *pb, const git_oid *oid,
double current_time = git__timer(); double current_time = git__timer();
double elapsed = current_time - pb->last_progress_report_time; double elapsed = current_time - pb->last_progress_report_time;
if (elapsed >= MIN_PROGRESS_UPDATE_INTERVAL) { if (elapsed < 0 || elapsed >= MIN_PROGRESS_UPDATE_INTERVAL) {
pb->last_progress_report_time = current_time; pb->last_progress_report_time = current_time;
ret = pb->progress_cb( ret = pb->progress_cb(
...@@ -922,7 +922,7 @@ static int report_delta_progress( ...@@ -922,7 +922,7 @@ static int report_delta_progress(
double current_time = git__timer(); double current_time = git__timer();
double elapsed = current_time - pb->last_progress_report_time; double elapsed = current_time - pb->last_progress_report_time;
if (force || elapsed >= MIN_PROGRESS_UPDATE_INTERVAL) { if (force || elapsed < 0 || elapsed >= MIN_PROGRESS_UPDATE_INTERVAL) {
pb->last_progress_report_time = current_time; pb->last_progress_report_time = current_time;
ret = pb->progress_cb( ret = pb->progress_cb(
......
...@@ -975,9 +975,10 @@ static int stream_thunk(void *buf, size_t size, void *data) ...@@ -975,9 +975,10 @@ static int stream_thunk(void *buf, size_t size, void *data)
if (payload->cb) { if (payload->cb) {
double current_time = git__timer(); double current_time = git__timer();
double elapsed = current_time - payload->last_progress_report_time;
payload->last_bytes += size; payload->last_bytes += size;
if ((current_time - payload->last_progress_report_time) >= MIN_PROGRESS_UPDATE_INTERVAL) { if (elapsed < 0 || elapsed >= MIN_PROGRESS_UPDATE_INTERVAL) {
payload->last_progress_report_time = current_time; payload->last_progress_report_time = current_time;
error = payload->cb(payload->pb->nr_written, payload->pb->nr_objects, payload->last_bytes, payload->cb_payload); error = payload->cb(payload->pb->nr_written, payload->pb->nr_objects, payload->last_bytes, payload->cb_payload);
} }
......
...@@ -376,17 +376,17 @@ GIT_INLINE(double) git__timer(void) ...@@ -376,17 +376,17 @@ GIT_INLINE(double) git__timer(void)
GIT_INLINE(double) git__timer(void) GIT_INLINE(double) git__timer(void)
{ {
struct timespec tp; struct timeval tv;
if (clock_gettime(CLOCK_MONOTONIC, &tp) == 0) { #ifdef CLOCK_MONOTONIC
struct timespec tp;
if (clock_gettime(CLOCK_MONOTONIC, &tp) == 0)
return (double) tp.tv_sec + (double) tp.tv_nsec / 1.0E9; return (double) tp.tv_sec + (double) tp.tv_nsec / 1.0E9;
} else { #endif
/* Fall back to using gettimeofday */
struct timeval tv; /* Fall back to using gettimeofday */
struct timezone tz; gettimeofday(&tv, NULL);
gettimeofday(&tv, &tz); return (double)tv.tv_sec + (double)tv.tv_usec / 1.0E6;
return (double)tv.tv_sec + (double)tv.tv_usec / 1.0E6;
}
} }
#endif #endif
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment