Remove 'self' parameter from mmapcache calls, make it proper singleton

This commit is contained in:
Christian Thaeter 2010-03-05 09:39:31 +01:00
parent 4fee3d85cf
commit cd0cd341c0
4 changed files with 34 additions and 42 deletions

View file

@ -193,7 +193,7 @@ lumiera_mmap_init (LumieraMMap self, LumieraFile file, off_t start, size_t size)
self->address = addr;
self->refmap = lumiera_calloc ((length-1)/chunksize+1, sizeof (unsigned short));
self->refcnt = 0;
lumiera_mmapcache_announce (lumiera_mcache, self);
lumiera_mmapcache_announce (self);
lumiera_file_handle_release (file);
return self;
@ -210,7 +210,7 @@ lumiera_mmap_new (LumieraFile file, off_t start, size_t size)
{
TRACE (mmap_dbg);
LumieraMMap self = lumiera_mmapcache_mmap_acquire (lumiera_mcache);
LumieraMMap self = lumiera_mmapcache_mmap_acquire ();
if (lumiera_mmap_init (self, file, start, size))
return self;
@ -229,7 +229,7 @@ lumiera_mmap_delete (LumieraMMap self)
if (self)
{
REQUIRE (!self->refcnt);
lumiera_mmapcache_forget (lumiera_mcache, self);
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 */
llist_unlink (&self->searchnode);
@ -249,9 +249,9 @@ lumiera_mmap_destroy_node (LList node)
REQUIRE (llist_is_empty (node));
LumieraMMap self = (LumieraMMap)node;
lumiera_mmapcache_forget (lumiera_mcache, self);
lumiera_mmapcache_forget (self);
llist_unlink (&self->searchnode); TODO ("must lock mmappings -> deadlock");
llist_unlink (&self->searchnode); FIXME ("must lock mmappings -> deadlock");
munmap (self->address, self->size);
lumiera_free (self->refmap);

View file

@ -66,19 +66,19 @@ lumiera_mmapcache_delete (void)
void*
lumiera_mmapcache_mmap_acquire (LumieraMMapcache self)
lumiera_mmapcache_mmap_acquire (void)
{
TRACE (mmapcache_dbg);
void* map = NULL;
LUMIERA_MUTEX_SECTION (mutex_sync, &self->lock)
LUMIERA_MUTEX_SECTION (mutex_sync, &lumiera_mcache->lock)
{
map = lumiera_mrucache_pop (&self->cache);
map = lumiera_mrucache_pop (&lumiera_mcache->cache);
}
if (!map)
{
map = lumiera_malloc (sizeof (*self));
map = lumiera_malloc (sizeof (lumiera_mmap));
TRACE (mmapcache_dbg, "allocated new mmap");
}
else
@ -91,42 +91,42 @@ lumiera_mmapcache_mmap_acquire (LumieraMMapcache self)
void
lumiera_mmapcache_announce (LumieraMMapcache self, LumieraMMap map)
lumiera_mmapcache_announce (LumieraMMap map)
{
TRACE (mmapcache_dbg);
LUMIERA_MUTEX_SECTION (mutex_sync, &self->lock)
LUMIERA_MUTEX_SECTION (mutex_sync, &lumiera_mcache->lock)
{
self->total += map->size;
lumiera_mcache->total += map->size;
}
}
void
lumiera_mmapcache_forget (LumieraMMapcache self, LumieraMMap map)
lumiera_mmapcache_forget (LumieraMMap map)
{
TRACE (mmapcache_dbg);
LUMIERA_MUTEX_SECTION (mutex_sync, &self->lock)
LUMIERA_MUTEX_SECTION (mutex_sync, &lumiera_mcache->lock)
{
if (!llist_is_empty (&map->cachenode))
{
TODO ("cached stats");
REQUIRE (llist_is_member (&self->cache.cache_list, &map->cachenode), "Map object not in cache");
REQUIRE (llist_is_member (&lumiera_mcache->cache.cache_list, &map->cachenode), "Map object not in cache");
llist_unlink (&map->cachenode);
}
self->total -= map->size;
lumiera_mcache->total -= map->size;
}
}
#if 0
int
lumiera_mmapcache_age (LumieraMMapcache self)
lumiera_mmapcache_age (void)
{
TRACE (mmapcache_dbg);
int ret = 0;
LUMIERA_MUTEX_SECTION (mmapcache, &self->lock)
LUMIERA_MUTEX_SECTION (mmapcache, &lumiera_mcache->lock)
{
ret = lumiera_mrucache_age (&self->cache, 10); TODO ("age nelem == 20%(configureable) of the cache");
ret = lumiera_mrucache_age (&lumiera_mcache->cache, 10); TODO ("age nelem == 20%(configureable) of the cache");
}
return ret;
@ -134,15 +134,15 @@ lumiera_mmapcache_age (LumieraMMapcache self)
#endif
LumieraMMap
lumiera_mmapcache_checkout (LumieraMMapcache self, LumieraMMap handle)
lumiera_mmapcache_checkout (LumieraMMap handle)
{
TRACE (mmapcache_dbg);
REQUIRE (handle->refcnt == 0);
LUMIERA_MUTEX_SECTION (mutex_sync, &self->lock)
LUMIERA_MUTEX_SECTION (mutex_sync, &lumiera_mcache->lock)
{
TODO ("cached stats");
lumiera_mrucache_checkout (&self->cache, &handle->cachenode);
lumiera_mrucache_checkout (&lumiera_mcache->cache, &handle->cachenode);
}
return handle;
@ -150,15 +150,15 @@ lumiera_mmapcache_checkout (LumieraMMapcache self, LumieraMMap handle)
void
lumiera_mmapcache_checkin (LumieraMMapcache self, LumieraMMap handle)
lumiera_mmapcache_checkin (LumieraMMap handle)
{
TRACE (mmapcache_dbg);
REQUIRE (handle->refcnt == 0);
LUMIERA_MUTEX_SECTION (mutex_sync, &self->lock)
LUMIERA_MUTEX_SECTION (mutex_sync, &lumiera_mcache->lock)
{
TODO ("cached stats");
lumiera_mrucache_checkin (&self->cache, &handle->cachenode);
lumiera_mrucache_checkin (&lumiera_mcache->cache, &handle->cachenode);
}
}

View file

@ -49,8 +49,6 @@ struct lumiera_mmapcache_struct
lumiera_mutex lock;
};
extern LumieraMMapcache lumiera_mcache;
/**
* Initializes the mmapcache.
@ -71,58 +69,52 @@ lumiera_mmapcache_delete (void);
* Get a fresh mmap object.
* when mmaped_limit is reached, the oldest mmap object gets dropped else a new allocated object
* is returned
* @param self pointer to the cache
* @return the new uninitialized mmap
* @return the new uninitialized mmap (void* because this is uninitialized)
*/
void*
lumiera_mmapcache_mmap_acquire (LumieraMMapcache self);
lumiera_mmapcache_mmap_acquire (void);
/**
* Announce a new mmap object to the cache quotas.
* Update the statistics kept in the cache,
* the map object is still considered to be checked out
* @param self pointer to the cache
* @param map object to be announced
*/
void
lumiera_mmapcache_announce (LumieraMMapcache self, LumieraMMap map);
lumiera_mmapcache_announce (LumieraMMap map);
/**
* Remove a mmap object from the cache quotas.
* Update the statistics kept in the cache, remove it from the cache.
* @param self pointer to the cache
* @param map object to be removed
*/
void
lumiera_mmapcache_forget (LumieraMMapcache self, LumieraMMap map);
lumiera_mmapcache_forget (LumieraMMap map);
/**
* Destroy and free the nelem oldest elements.
* Used to free up resources and memory.
* @param self cache where to free elements.
* @return nelem-(numer of elements which got freed), that is 0 if all requested elements got freed
*/
int
lumiera_mmapcache_age (LumieraMMapcache self);
lumiera_mmapcache_age (void);
/**
* Remove a mmap from cache aging
* Mmaps which are subject of cache aging must be checked out before they can be used.
* @param self the mmapcache
* @param handle the mmap to be checked out
*/
LumieraMMap
lumiera_mmapcache_checkout (LumieraMMapcache self, LumieraMMap handle);
lumiera_mmapcache_checkout (LumieraMMap handle);
/**
* Put a mmap into the cache
* Mmaps which are checked in are subject of cache aging and might get destroyed and reused.
* @param self the mmapcache
* @param handle the mmap to be checked in
*/
void
lumiera_mmapcache_checkin (LumieraMMapcache self, LumieraMMap handle);
lumiera_mmapcache_checkin (LumieraMMap handle);
#endif
/*

View file

@ -115,7 +115,7 @@ lumiera_mmapings_mmap_acquire (LumieraMMapings self, LumieraFile file, off_t sta
{
if (!ret->refcnt)
/* in cache, needs to me checked out */
lumiera_mmapcache_checkout (lumiera_mcache, ret);
lumiera_mmapcache_checkout (ret);
}
else
{
@ -149,7 +149,7 @@ lumiera_mmapings_release_mmap (LumieraMMapings self, LumieraMMap map)
if (!--map->refcnt)
{
TRACE (mmapcache_dbg, "checkin");
lumiera_mmapcache_checkin (lumiera_mcache, map);
lumiera_mmapcache_checkin (map);
}
}
}