Mercurial > hg > audiodb
comparison lock.cpp @ 498:342822c2d49a
Merge api-inversion branch (-r656:771, but I don't expect to return to
that branch) into the trunk.
I expect there to be minor performance regressions (e.g. in the SOAP
server index cacheing, which I have forcibly removed) and minor
unplugged memory leaks (e.g. in audioDB::query(), where I don't free up
the datum). I hope that these leaks and performance regressions can be
plugged in short order. I also expect that some (but maybe not all) of
the issues currently addressed in the memory-leaks branch are superseded
or fixed by this merge.
There remains much work to be done; go forth and do it.
author | mas01cr |
---|---|
date | Sat, 10 Jan 2009 16:47:57 +0000 |
parents | |
children | cc2b97d020b1 |
comparison
equal
deleted
inserted
replaced
476:a7193678280b | 498:342822c2d49a |
---|---|
1 #include "audioDB.h" | |
2 | |
3 int acquire_lock(int fd, bool exclusive) { | |
4 struct flock lock; | |
5 int status; | |
6 | |
7 lock.l_type = exclusive ? F_WRLCK : F_RDLCK; | |
8 lock.l_whence = SEEK_SET; | |
9 lock.l_start = 0; | |
10 lock.l_len = 0; /* "the whole file" */ | |
11 | |
12 retry: | |
13 do { | |
14 status = fcntl(fd, F_SETLKW, &lock); | |
15 } while (status != 0 && errno == EINTR); | |
16 | |
17 if (status) { | |
18 if (errno == EAGAIN) { | |
19 sleep(1); | |
20 goto retry; | |
21 } else { | |
22 return status; | |
23 } | |
24 } | |
25 return 0; | |
26 } | |
27 | |
28 int divest_lock(int fd) { | |
29 struct flock lock; | |
30 | |
31 lock.l_type = F_UNLCK; | |
32 lock.l_whence = SEEK_SET; | |
33 lock.l_start = 0; | |
34 lock.l_len = 0; | |
35 | |
36 return fcntl(fd, F_SETLKW, &lock); | |
37 } |