Skip to content

Commit e4e173e

Browse files
committed
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
1 parent f15a679 commit e4e173e

File tree

3 files changed

+13
-12
lines changed

3 files changed

+13
-12
lines changed

src/pack-objects.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -251,7 +251,7 @@ int git_packbuilder_insert(git_packbuilder *pb, const git_oid *oid,
251251
double current_time = git__timer();
252252
double elapsed = current_time - pb->last_progress_report_time;
253253

254-
if (elapsed >= MIN_PROGRESS_UPDATE_INTERVAL) {
254+
if (elapsed < 0 || elapsed >= MIN_PROGRESS_UPDATE_INTERVAL) {
255255
pb->last_progress_report_time = current_time;
256256

257257
ret = pb->progress_cb(
@@ -922,7 +922,7 @@ static int report_delta_progress(
922922
double current_time = git__timer();
923923
double elapsed = current_time - pb->last_progress_report_time;
924924

925-
if (force || elapsed >= MIN_PROGRESS_UPDATE_INTERVAL) {
925+
if (force || elapsed < 0 || elapsed >= MIN_PROGRESS_UPDATE_INTERVAL) {
926926
pb->last_progress_report_time = current_time;
927927

928928
ret = pb->progress_cb(

src/transports/smart_protocol.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -975,9 +975,10 @@ static int stream_thunk(void *buf, size_t size, void *data)
975975

976976
if (payload->cb) {
977977
double current_time = git__timer();
978+
double elapsed = current_time - payload->last_progress_report_time;
978979
payload->last_bytes += size;
979980

980-
if ((current_time - payload->last_progress_report_time) >= MIN_PROGRESS_UPDATE_INTERVAL) {
981+
if (elapsed < 0 || elapsed >= MIN_PROGRESS_UPDATE_INTERVAL) {
981982
payload->last_progress_report_time = current_time;
982983
error = payload->cb(payload->pb->nr_written, payload->pb->nr_objects, payload->last_bytes, payload->cb_payload);
983984
}

src/util.h

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -376,17 +376,17 @@ GIT_INLINE(double) git__timer(void)
376376

377377
GIT_INLINE(double) git__timer(void)
378378
{
379-
struct timespec tp;
379+
struct timeval tv;
380380

381-
if (clock_gettime(CLOCK_MONOTONIC, &tp) == 0) {
381+
#ifdef CLOCK_MONOTONIC
382+
struct timespec tp;
383+
if (clock_gettime(CLOCK_MONOTONIC, &tp) == 0)
382384
return (double) tp.tv_sec + (double) tp.tv_nsec / 1.0E9;
383-
} else {
384-
/* Fall back to using gettimeofday */
385-
struct timeval tv;
386-
struct timezone tz;
387-
gettimeofday(&tv, &tz);
388-
return (double)tv.tv_sec + (double)tv.tv_usec / 1.0E6;
389-
}
385+
#endif
386+
387+
/* Fall back to using gettimeofday */
388+
gettimeofday(&tv, NULL);
389+
return (double)tv.tv_sec + (double)tv.tv_usec / 1.0E6;
390390
}
391391

392392
#endif

0 commit comments

Comments
 (0)