Skip to content

Commit 789a09b

Browse files
author
Junio C Hamano
committed
avoid nanosleep(2)
On Solaris nanosleep(2) is not available in libc; you need to link with -lrt to get it. The purpose of the loop is to wait until the next filesystem timestamp granularity, and the code uses subsecond sleep in the hope that it can shorten the delay to 0.5 seconds on average instead of a full second. It is probably not worth depending on an extra library for this. We might want to yank out the whole "racy-git avoidance is costly later at runtime, so let's delay writing the index out" codepath later, but that is a separate issue and needs some testing on large trees to figure it out. After playing with the kernel tree, I have a feeling that the whole thing may not be worth it. Signed-off-by: Junio C Hamano <[email protected]>
1 parent 3cd4f5e commit 789a09b

File tree

1 file changed

+1
-5
lines changed

1 file changed

+1
-5
lines changed

read-cache.c

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
*/
66
#include "cache.h"
77
#include "cache-tree.h"
8-
#include <time.h>
98

109
/* Index extensions.
1110
*
@@ -1033,11 +1032,8 @@ int write_cache(int newfd, struct cache_entry **cache, int entries)
10331032
fprintf(stderr, "now %lu\n", now);
10341033
#endif
10351034
while (!fstat(newfd, &st) && st.st_mtime <= now) {
1036-
struct timespec rq, rm;
10371035
off_t where = lseek(newfd, 0, SEEK_CUR);
1038-
rq.tv_sec = 0;
1039-
rq.tv_nsec = 250000000;
1040-
nanosleep(&rq, &rm);
1036+
sleep(1);
10411037
if ((where == (off_t) -1) ||
10421038
(write(newfd, "", 1) != 1) ||
10431039
(lseek(newfd, -1, SEEK_CUR) != where) ||

0 commit comments

Comments
 (0)