annotate audioDB-internals.h @ 401:a8a5f2ca5380 api-inversion

Invert audioDB::l2norm / audiodb_l2norm() We now have some functions that shouldn't be exported to the user of the library, but are used in more than one source file; case in point: audiodb_sync_header(). Make a new audioDB-internals.h file for them, and while we're at it put the scary mmap()-related macros in there too. We can't delete audioDB::unitNormAndInsertL2() quite yet, because it's used in insertion too, but we can delete the non-append branches. That's not very much code to lose, but every little helps.
author mas01cr
date Wed, 03 Dec 2008 14:53:20 +0000
parents
children 58b88ab69424
rev   line source
mas01cr@401 1 /* We could go gcc-specific here and use typeof() instead of passing
mas01cr@401 2 * in an explicit type. Answers on a postcard as to whether that's a
mas01cr@401 3 * good plan or not. */
mas01cr@401 4 #define mmap_or_goto_error(type, var, start, length) \
mas01cr@401 5 { void *tmp = mmap(0, length, PROT_READ, MAP_SHARED, adb->fd, (start)); \
mas01cr@401 6 if(tmp == (void *) -1) { \
mas01cr@401 7 goto error; \
mas01cr@401 8 } \
mas01cr@401 9 var = (type) tmp; \
mas01cr@401 10 }
mas01cr@401 11
mas01cr@401 12 #define maybe_munmap(table, length) \
mas01cr@401 13 { if(table) { \
mas01cr@401 14 munmap(table, length); \
mas01cr@401 15 } \
mas01cr@401 16 }
mas01cr@401 17
mas01cr@401 18 static inline int audiodb_sync_header(adb_t *adb) {
mas01cr@401 19 off_t pos;
mas01cr@401 20 pos = lseek(adb->fd, (off_t) 0, SEEK_CUR);
mas01cr@401 21 if(pos == (off_t) -1) {
mas01cr@401 22 goto error;
mas01cr@401 23 }
mas01cr@401 24 if(lseek(adb->fd, (off_t) 0, SEEK_SET) == (off_t) -1) {
mas01cr@401 25 goto error;
mas01cr@401 26 }
mas01cr@401 27 if(write(adb->fd, adb->header, O2_HEADERSIZE) != O2_HEADERSIZE) {
mas01cr@401 28 goto error;
mas01cr@401 29 }
mas01cr@401 30
mas01cr@401 31 /* can be fsync() if fdatasync() is racily exciting and new */
mas01cr@401 32 fdatasync(adb->fd);
mas01cr@401 33 if(lseek(adb->fd, pos, SEEK_SET) == (off_t) -1) {
mas01cr@401 34 goto error;
mas01cr@401 35 }
mas01cr@401 36 return 0;
mas01cr@401 37
mas01cr@401 38 error:
mas01cr@401 39 return 1;
mas01cr@401 40 }