X-Git-Url: http://git.vrable.net/?a=blobdiff_plain;f=bluesky%2Futil.c;h=d292634731b662827dc8c0dfbeec0f566ab5a32a;hb=8ab9f6acce5bbc6e56d2f3fa1833be06faf46770;hp=c4bac1972df323bad0b5d192a494f7a1401e8ffd;hpb=a8a9f2181e2e16d24d812ea1e7a7c8af42f0d2f1;p=bluesky.git diff --git a/bluesky/util.c b/bluesky/util.c index c4bac19..d292634 100644 --- a/bluesky/util.c +++ b/bluesky/util.c @@ -53,17 +53,6 @@ gboolean bluesky_inode_is_ready(BlueSkyInode *inode) /**** Reference-counted strings. ****/ -void bluesky_mmap_unref(BlueSkyMmap *mmap) -{ - if (mmap == NULL) - return; - - if (g_atomic_int_dec_and_test(&mmap->refcount)) { - munmap((void *)mmap->addr, mmap->len); - g_free(mmap); - } -} - /* Create and return a new reference-counted string. The reference count is * initially one. The newly-returned string takes ownership of the memory * pointed at by data, and will call g_free on it when the reference count @@ -86,12 +75,14 @@ BlueSkyRCStr *bluesky_string_new_from_gstring(GString *s) } /* Create a new BlueSkyRCStr from a memory-mapped buffer. */ -BlueSkyRCStr *bluesky_string_new_from_mmap(BlueSkyMmap *mmap, +BlueSkyRCStr *bluesky_string_new_from_mmap(BlueSkyCacheFile *mmap, int offset, gsize len) { + g_assert(offset + len <= mmap->len); + BlueSkyRCStr *string = g_new(BlueSkyRCStr, 1); string->mmap = mmap; - g_atomic_int_inc(&mmap->refcount); + g_atomic_int_inc(&mmap->mapcount); string->data = (char *)mmap->addr + offset; string->len = len; g_atomic_int_set(&string->refcount, 1);