Mercurial > hg > audiodb
annotate lock.cpp @ 580:633614461994
API for retrieving a track's data.
A new function, audiodb_retrieve_datum() fills a provided adb_datum_t
structure with the data corresponding to a given database key; the
companion audiodb_free_datum() function frees the data in a given datum
appropriately.
Just in case, I continue to require passing in the adb_t * as the first
argument to audiodb_free_datum(), even though it's not currently used:
I couldn't convince myself that _all_ possible implementations could
free a datum without reference to the adb_t.
This meant rewriting the internal code to use a new internal
audiodb_really_free_datum() function, which audiodb_free_datum() also
calls.
Sanity-checked by implementing a binding in sb-alien to this function,
lightly-tested.
All this fixes ticket:20 in Trac.
author | mas01cr |
---|---|
date | Tue, 14 Jul 2009 15:35:36 +0000 |
parents | cc2b97d020b1 |
children | 4eedc18634f5 |
rev | line source |
---|---|
mas01cr@509 | 1 extern "C" { |
mas01cr@509 | 2 #include "audioDB_API.h" |
mas01cr@509 | 3 } |
mas01cr@509 | 4 #include "audioDB-internals.h" |
mas01cr@498 | 5 |
mas01cr@498 | 6 int acquire_lock(int fd, bool exclusive) { |
mas01cr@498 | 7 struct flock lock; |
mas01cr@498 | 8 int status; |
mas01cr@498 | 9 |
mas01cr@498 | 10 lock.l_type = exclusive ? F_WRLCK : F_RDLCK; |
mas01cr@498 | 11 lock.l_whence = SEEK_SET; |
mas01cr@498 | 12 lock.l_start = 0; |
mas01cr@498 | 13 lock.l_len = 0; /* "the whole file" */ |
mas01cr@498 | 14 |
mas01cr@498 | 15 retry: |
mas01cr@498 | 16 do { |
mas01cr@498 | 17 status = fcntl(fd, F_SETLKW, &lock); |
mas01cr@498 | 18 } while (status != 0 && errno == EINTR); |
mas01cr@498 | 19 |
mas01cr@498 | 20 if (status) { |
mas01cr@498 | 21 if (errno == EAGAIN) { |
mas01cr@498 | 22 sleep(1); |
mas01cr@498 | 23 goto retry; |
mas01cr@498 | 24 } else { |
mas01cr@498 | 25 return status; |
mas01cr@498 | 26 } |
mas01cr@498 | 27 } |
mas01cr@498 | 28 return 0; |
mas01cr@498 | 29 } |
mas01cr@498 | 30 |
mas01cr@498 | 31 int divest_lock(int fd) { |
mas01cr@498 | 32 struct flock lock; |
mas01cr@498 | 33 |
mas01cr@498 | 34 lock.l_type = F_UNLCK; |
mas01cr@498 | 35 lock.l_whence = SEEK_SET; |
mas01cr@498 | 36 lock.l_start = 0; |
mas01cr@498 | 37 lock.l_len = 0; |
mas01cr@498 | 38 |
mas01cr@498 | 39 return fcntl(fd, F_SETLKW, &lock); |
mas01cr@498 | 40 } |