Objectcache

Offers a simple cache mechanism for objects needed in submodules which are costly to construct or deconstruct.

Implements <initthread_objectcacheimpl> and <freethread_objectcacheimpl> to allocate storage for cached objects before a new thread is created and frees all storage before the thread exits.

Summary
ObjectcacheOffers a simple cache mechanism for objects needed in submodules which are costly to construct or deconstruct.
CopyrightThis program is free software.
Files
C-kern/api/cache/objectcache_impl.hHeader file of Objectcache.
C-kern/cache/objectcache_impl.cImplementation file Objectcache impl.
Types
struct objectcache_impl_tExport objectcache_impl_t.
Functions
init
unittest_cache_objectcacheimplTest allocation and free works.
objectcache_impl_tHolds pointers to all cached objects.
iobufferUsed in ALLOC_PAGECACHE.
initthread
interface_objectcacheimplThis function is called from <init_threadcontext>.
lifetime
objectcache_impl_FREEStatic initializer.
init_objectcacheimplInits objectcache_impl_t and all contained objects.
free_objectcacheimplFrees objectcache_impl_t and all contained objects.
access
lockiobuffer_objectcacheimplLocks the io buffer and returns a pointer to it in iobuffer.
unlockiobuffer_objectcacheimplUnlocks the locked io buffer and sets the pointer to NULL.

Copyright

This program is free software.  You can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version.

This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License for more details.

Author

© 2011 Jörg Seebohn

Files

C-kern/api/cache/objectcache_impl.h

Header file of Objectcache.

C-kern/cache/objectcache_impl.c

Implementation file Objectcache impl.

Types

struct objectcache_impl_t

typedef struct objectcache_impl_t objectcache_impl_t

Export objectcache_impl_t.

Functions

Summary
init
unittest_cache_objectcacheimplTest allocation and free works.

init

unittest_cache_objectcacheimpl

int unittest_cache_objectcacheimpl(void)

Test allocation and free works.

objectcache_impl_t

struct objectcache_impl_t

Holds pointers to all cached objects.  TODO: remove iobuffer and add other types !

Summary
iobufferUsed in ALLOC_PAGECACHE.
initthread
interface_objectcacheimplThis function is called from <init_threadcontext>.
lifetime
objectcache_impl_FREEStatic initializer.
init_objectcacheimplInits objectcache_impl_t and all contained objects.
free_objectcacheimplFrees objectcache_impl_t and all contained objects.
access
lockiobuffer_objectcacheimplLocks the io buffer and returns a pointer to it in iobuffer.
unlockiobuffer_objectcacheimplUnlocks the locked io buffer and sets the pointer to NULL.

iobuffer

struct { uint8_t * addr ; size_t size ; } iobuffer

Used in ALLOC_PAGECACHE.

initthread

interface_objectcacheimpl

struct objectcache_it * interface_objectcacheimpl(void)

This function is called from <init_threadcontext>.  Used to initialize interface of objectcache_t.

lifetime

objectcache_impl_FREE

#define objectcache_impl_FREE { vmpage_FREE }

Static initializer.

init_objectcacheimpl

int init_objectcacheimpl(/*out*/objectcache_impl_t *objectcache)

Inits objectcache_impl_t and all contained objects.

free_objectcacheimpl

int free_objectcacheimpl(objectcache_impl_t *objectcache)

Frees objectcache_impl_t and all contained objects.

access

lockiobuffer_objectcacheimpl

void lockiobuffer_objectcacheimpl(objectcache_impl_t *objectcache,
/*out*/struct memblock_t **iobuffer)

Locks the io buffer and returns a pointer to it in iobuffer.  The buffer is of type vmpage_t (compatible with memblock_t).

unlockiobuffer_objectcacheimpl

void unlockiobuffer_objectcacheimpl(objectcache_impl_t *objectcache,
struct memblock_t **iobuffer)

Unlocks the locked io buffer and sets the pointer to NULL.  The pointer to the buffer must be acquired by a previous call to lockiobuffer_objectcacheimpl.  Calling unlock with a NULL pointer is a no op.

Offers a simple cache mechanism for objects needed in submodules which are costly to construct or deconstruct.
Implements Objectcache.
typedef struct objectcache_impl_t objectcache_impl_t
Export objectcache_impl_t.
struct objectcache_impl_t
Holds pointers to all cached objects.
int unittest_cache_objectcacheimpl(void)
Test allocation and free works.
struct { uint8_t * addr ; size_t size ; } iobuffer
Used in ALLOC_PAGECACHE.
#define ALLOC_PAGECACHE(
   pgsize,
   page
) (allocpage_pagecache(pagecache_maincontext(), (pgsize), (page)))
Allocates a single memory page of size pgsize (see pagesize_e) and returns it in page.
struct objectcache_it * interface_objectcacheimpl(void)
This function is called from init_threadcontext.
#define objectcache_impl_FREE { vmpage_FREE }
Static initializer.
int init_objectcacheimpl(/*out*/objectcache_impl_t *objectcache)
Inits objectcache_impl_t and all contained objects.
int free_objectcacheimpl(objectcache_impl_t *objectcache)
Frees objectcache_impl_t and all contained objects.
void lockiobuffer_objectcacheimpl(objectcache_impl_t *objectcache,
/*out*/struct memblock_t **iobuffer)
Locks the io buffer and returns a pointer to it in iobuffer.
void unlockiobuffer_objectcacheimpl(objectcache_impl_t *objectcache,
struct memblock_t **iobuffer)
Unlocks the locked io buffer and sets the pointer to NULL.
iobj_DECLARE(objectcache_t,
objectcache)
Uses iobj_DECLARE to declare interfaceable object.
struct vmpage_t
Type has same structure as memblock_t.
struct memblock_t
Describes memory block.
Close