annotate lock.cpp @ 505:216b55457009

Remove all those "with library" in the libtests/ short-descriptions Instead, make the driver run-tests.sh file be clear about what test is being run.
author mas01cr
date Tue, 13 Jan 2009 21:26:33 +0000
parents 342822c2d49a
children cc2b97d020b1
rev   line source
mas01cr@498 1 #include "audioDB.h"
mas01cr@498 2
mas01cr@498 3 int acquire_lock(int fd, bool exclusive) {
mas01cr@498 4 struct flock lock;
mas01cr@498 5 int status;
mas01cr@498 6
mas01cr@498 7 lock.l_type = exclusive ? F_WRLCK : F_RDLCK;
mas01cr@498 8 lock.l_whence = SEEK_SET;
mas01cr@498 9 lock.l_start = 0;
mas01cr@498 10 lock.l_len = 0; /* "the whole file" */
mas01cr@498 11
mas01cr@498 12 retry:
mas01cr@498 13 do {
mas01cr@498 14 status = fcntl(fd, F_SETLKW, &lock);
mas01cr@498 15 } while (status != 0 && errno == EINTR);
mas01cr@498 16
mas01cr@498 17 if (status) {
mas01cr@498 18 if (errno == EAGAIN) {
mas01cr@498 19 sleep(1);
mas01cr@498 20 goto retry;
mas01cr@498 21 } else {
mas01cr@498 22 return status;
mas01cr@498 23 }
mas01cr@498 24 }
mas01cr@498 25 return 0;
mas01cr@498 26 }
mas01cr@498 27
mas01cr@498 28 int divest_lock(int fd) {
mas01cr@498 29 struct flock lock;
mas01cr@498 30
mas01cr@498 31 lock.l_type = F_UNLCK;
mas01cr@498 32 lock.l_whence = SEEK_SET;
mas01cr@498 33 lock.l_start = 0;
mas01cr@498 34 lock.l_len = 0;
mas01cr@498 35
mas01cr@498 36 return fcntl(fd, F_SETLKW, &lock);
mas01cr@498 37 }