add casts

This commit is contained in:
Rusty Sears 2013-01-30 14:50:28 -08:00
parent 54b0a14b2d
commit 2504600f3b

View file

@ -10,13 +10,14 @@
out, or forcing the log too early?
*/
static void phWrite(stasis_page_handle_t * ph, Page * ret) {
stasis_handle_t* impl = (stasis_handle_t*) (ph->impl);
DEBUG("\nPAGEWRITE %lld\n", ret->id);
// The caller guarantees that we have exclusive access to the page, so
// no further latching is necessary.
if(!ret->dirty) { return; }
stasis_page_flushed(ret);
if(ph->log) { stasis_log_force(ph->log, ret->LSN, LOG_FORCE_WAL); }
int err = ((stasis_handle_t*)ph->impl)->write(ph->impl, PAGE_SIZE * ret->id, ret->memAddr, PAGE_SIZE);
int err = impl->write(impl, PAGE_SIZE * ret->id, ret->memAddr, PAGE_SIZE);
if(err) {
printf("Couldn't write to page file: %s\n", strerror(err));
fflush(stdout);
@ -25,9 +26,10 @@ static void phWrite(stasis_page_handle_t * ph, Page * ret) {
stasis_dirty_page_table_set_clean(ph->dirtyPages, ret);
}
static void phRead(stasis_page_handle_t * ph, Page * ret, pagetype_t type) {
stasis_handle_t* impl = (stasis_handle_t*) (ph->impl);
// The caller guarantees that we have exclusive access to the page, so
// no further latching is necessary.
int err = ((stasis_handle_t*)ph->impl)->read(ph->impl, PAGE_SIZE * ret->id, ret->memAddr, PAGE_SIZE);
int err = impl->read(impl, PAGE_SIZE * ret->id, ret->memAddr, PAGE_SIZE);
if(err) {
if(err == EDOM) {
// tried to read off end of file...
@ -42,36 +44,42 @@ static void phRead(stasis_page_handle_t * ph, Page * ret, pagetype_t type) {
stasis_page_loaded(ret, type);
}
static void phPrefetchRange(stasis_page_handle_t *ph, pageid_t pageid, pageid_t count) {
stasis_handle_t* impl = (stasis_handle_t*) (ph->impl);
// TODO RTFM and see if Linux provides a decent API for prefetch hints.
lsn_t off = pageid * PAGE_SIZE;
lsn_t len = count * PAGE_SIZE;
byte * buf = stasis_malloc(len, byte);
((stasis_handle_t*)ph->impl)->read(ph->impl, off, buf, len);
impl->read(impl, off, buf, len);
free(buf);
}
static int phPreallocateRange(stasis_page_handle_t * ph, pageid_t pageid, pageid_t count) {
stasis_handle_t* impl = (stasis_handle_t*) (ph->impl);
lsn_t off = pageid * PAGE_SIZE;
lsn_t len = count * PAGE_SIZE;
return ((stasis_handle_t*)ph->impl)->fallocate(ph->impl, off, len);
return impl->fallocate(impl, off, len);
}
static void phForce(stasis_page_handle_t * ph) {
int err = ((stasis_handle_t*)ph->impl)->force(ph->impl);
stasis_handle_t* impl = (stasis_handle_t*) (ph->impl);
int err = impl->force(impl);
assert(!err);
}
static void phAsyncForce(stasis_page_handle_t * ph) {
int err = ((stasis_handle_t*)ph->impl)->async_force(ph->impl);
stasis_handle_t* impl = (stasis_handle_t*) (ph->impl);
int err = impl->async_force(impl);
assert(!err);
}
static void phForceRange(stasis_page_handle_t * ph, lsn_t start, lsn_t stop) {
int err = ((stasis_handle_t*)ph->impl)->force_range(ph->impl,start*PAGE_SIZE,stop*PAGE_SIZE);
stasis_handle_t* impl = (stasis_handle_t*) (ph->impl);
int err = impl->force_range(impl,start*PAGE_SIZE,stop*PAGE_SIZE);
assert(!err);
}
static void phClose(stasis_page_handle_t * ph) {
int err = ((stasis_handle_t*)ph->impl)->close(ph->impl);
stasis_handle_t* impl = (stasis_handle_t*) (ph->impl);
int err = impl->close(impl);
DEBUG("Closing pageHandle\n");
if(err) {
printf("Couldn't close page file: %s\n", strerror(err));
@ -82,15 +90,17 @@ static void phClose(stasis_page_handle_t * ph) {
}
static stasis_page_handle_t * phDup(stasis_page_handle_t * ph, int is_sequential) {
stasis_page_handle_t * ret = stasis_alloc(stasis_page_handle_t);
stasis_handle_t* impl = (stasis_handle_t*) (ph->impl);
memcpy(ret, ph, sizeof(*ret));
ret->impl = ((stasis_handle_t*)ret->impl)->dup(ret->impl);
if(((stasis_handle_t*)ret->impl)->error != 0) {
fprintf(stderr, "Could not dup file handle: %s\n", strerror(((stasis_handle_t*)ret->impl)->error));
ret->impl = impl->dup(impl);
stasis_handle_t* retimpl = (stasis_handle_t*)ret->impl;
if(retimpl->error != 0) {
fprintf(stderr, "Could not dup file handle: %s\n", strerror(retimpl->error));
ret->close(ret);
return 0;
}
if(is_sequential) {
((stasis_handle_t*)ret->impl)->enable_sequential_optimizations(ret->impl);
retimpl->enable_sequential_optimizations(retimpl);
}
return ret;
}