Mercurial > hg > audiodb
view audioDB-internals.h @ 406:c279adeb47f4 api-inversion
Slight rearrangement of insert code.
Move most of audiodb_insert() into a helper function to create an
adb_datum_t from an adb_insert_t. (Most of the rest of it goes into
another helper function for cleaning up).
Now audiodb_insert() is small enough that it's plausible to move the
O2_FLAG_LARGE_ADB into it from audioDB::insert. The plan is to add
support for the LARGE_ADB case in audiodb_insert(), at which point
audiodb_batchinsert() will Just Work, and we'll be able to delete
audioDB::batchinsert_large_adb (which is good, because it's an
almost-but-not-quite-identical copy of audioDB::batchinsert).
author | mas01cr |
---|---|
date | Fri, 05 Dec 2008 22:56:12 +0000 |
parents | 58b88ab69424 |
children | f0a69693eaef |
line wrap: on
line source
struct adb { char *path; int fd; int flags; adb_header_t *header; std::set<std::string> *keys; }; /* We could go gcc-specific here and use typeof() instead of passing * in an explicit type. Answers on a postcard as to whether that's a * good plan or not. */ #define mmap_or_goto_error(type, var, start, length) \ { void *tmp = mmap(0, length, PROT_READ, MAP_SHARED, adb->fd, (start)); \ if(tmp == (void *) -1) { \ goto error; \ } \ var = (type) tmp; \ } #define maybe_munmap(table, length) \ { if(table) { \ munmap(table, length); \ } \ } static inline int audiodb_sync_header(adb_t *adb) { off_t pos; pos = lseek(adb->fd, (off_t) 0, SEEK_CUR); if(pos == (off_t) -1) { goto error; } if(lseek(adb->fd, (off_t) 0, SEEK_SET) == (off_t) -1) { goto error; } if(write(adb->fd, adb->header, O2_HEADERSIZE) != O2_HEADERSIZE) { goto error; } /* can be fsync() if fdatasync() is racily exciting and new */ fdatasync(adb->fd); if(lseek(adb->fd, pos, SEEK_SET) == (off_t) -1) { goto error; } return 0; error: return 1; }