FIX: small refcounter glitch on mmap

freshly created mmaps have a refcounter set to 1 now, acquire a new
mmap only increments the refcounter when its checked out from cache.
This commit is contained in:
Christian Thaeter 2010-03-05 15:45:49 +01:00
parent cd0cd341c0
commit 84ec2b6a77
2 changed files with 7 additions and 7 deletions

View file

@ -192,7 +192,7 @@ lumiera_mmap_init (LumieraMMap self, LumieraFile file, off_t start, size_t size)
self->size = length;
self->address = addr;
self->refmap = lumiera_calloc ((length-1)/chunksize+1, sizeof (unsigned short));
self->refcnt = 0;
self->refcnt = 1;
lumiera_mmapcache_announce (self);
lumiera_file_handle_release (file);
@ -228,7 +228,7 @@ lumiera_mmap_delete (LumieraMMap self)
TRACE (mmap_dbg);
if (self)
{
REQUIRE (!self->refcnt);
REQUIRE (self->refcnt <= 1);
lumiera_mmapcache_forget (self);
/* The matching mappings->lock must be hold or being irrelevant (mappings destructor) here, we can't asset this from here, good luck */

View file

@ -59,8 +59,9 @@ lumiera_mmapings_destroy (LumieraMMapings self)
LLIST_WHILE_TAIL (&self->mmaps, node)
{
LumieraMMap mmap = LLIST_TO_STRUCTP (node, lumiera_mmap, searchnode);
lumiera_mmap_delete (mmap);
LumieraMMap map = LLIST_TO_STRUCTP (node, lumiera_mmap, searchnode);
REQUIRE (map->refcnt == 0, "map still in use: %p", map);
lumiera_mmap_delete (map);
}
lumiera_mutex_destroy (&self->lock, &NOBUG_FLAG(mutex_dbg), NOBUG_CONTEXT);
@ -114,8 +115,9 @@ lumiera_mmapings_mmap_acquire (LumieraMMapings self, LumieraFile file, off_t sta
if (ret)
{
if (!ret->refcnt)
/* in cache, needs to me checked out */
/* in cache, needs to be checked out */
lumiera_mmapcache_checkout (ret);
++ret->refcnt;
}
else
{
@ -128,8 +130,6 @@ lumiera_mmapings_mmap_acquire (LumieraMMapings self, LumieraFile file, off_t sta
TODO ("sort search list?");
}
++ret->refcnt;
PLANNED ("use refmap for finer grained refcounting");
ENSURE (llist_is_empty(&ret->cachenode));