fcntl(2) does not work for synchronization of threads belonging
to the same process. Use flock(2) instead.
http://marc.info/?l=util-linux-ng&m=
129708412829971&w=2
Signed-off-by: Petr Uzel <petr.uzel@suse.cz>
THREAD_LOCAL FILE *state_f;
THREAD_LOCAL uint16_t clock_seq;
struct timeval tv;
- struct flock fl;
uint64_t clock_reg;
mode_t save_umask;
int len;
state_fd = -1;
}
}
- fl.l_type = F_WRLCK;
- fl.l_whence = SEEK_SET;
- fl.l_start = 0;
- fl.l_len = 0;
- fl.l_pid = 0;
if (state_fd >= 0) {
rewind(state_f);
- while (fcntl(state_fd, F_SETLKW, &fl) < 0) {
+ while (flock(state_fd, LOCK_EX) < 0) {
if ((errno == EAGAIN) || (errno == EINTR))
continue;
fclose(state_f);
fflush(state_f);
}
rewind(state_f);
- fl.l_type = F_UNLCK;
- fcntl(state_fd, F_SETLK, &fl);
+ flock(state_fd, LOCK_UN);
}
*clock_high = clock_reg >> 32;