lockfile: wait using sleep_millisec() instead of select()
Use the new function sleep_millisec() to delay execution for a short time. This avoids the invocation of select() with just a timeout, but no file descriptors. Such a use of select() is quit with EINVAL on Windows, leading to no delay at all. Signed-off-by: Johannes Sixt <j6t@kdbg.org> Reviewed-by: Michael Haggerty <mhagger@alum.mit.edu> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Johannes Sixt committed
Jun 5, 2015 at 21:45 UTC
30f8160d26f11156a6792565fe694c813406b929
1 file changed
+1
-9
lockfile.c
+1
-9
@@ -157,14 +157,6 @@ static int lock_file(struct lock_file *lk, const char *path, int flags)
157
return lk->fd;
158
}
159
160
-static int sleep_microseconds(long us)
161
-{
162
- struct timeval tv;
163
- tv.tv_sec = 0;
164
- tv.tv_usec = us;
165
- return select(0, NULL, NULL, NULL, &tv);
166
-}
167
-
160
/*
161
* Constants defining the gaps between attempts to lock a file. The
162
* first backoff period is approximately INITIAL_BACKOFF_MS
@@ -214,7 +206,7 @@ static int lock_file_timeout(struct lock_file *lk, const char *path,
206
backoff_ms = multiplier * INITIAL_BACKOFF_MS;
207
/* back off for between 0.75*backoff_ms and 1.25*backoff_ms */
208
wait_ms = (750 + rand() % 500) * backoff_ms / 1000;
217
- sleep_microseconds(wait_ms*1000);
209
+ sleep_millisec(wait_ms);
210
remaining_ms -= wait_ms;
211
212
/* Recursion: (n+1)^2 = n^2 + 2n + 1 */