Lumiera  0.pre.03
»edityourfreedom«
filehandlecache.h File Reference

Go to the source code of this file.

Description

Caching and management of filehandles.

The number of filehandles a program can held open is usually limited, since we want to support using a less limited number of files and closing/opening for each operation is expensive, we provide a cache to keep the most frequent used files open and gracefully close/recycle unused filehandles. The filehandle cache defined here protects all operations on the cache with a mutex.

Definition in file filehandlecache.h.

#include "lib/error.h"
#include "lib/mrucache.h"
#include "lib/mutex.h"
#include "backend/filehandle.h"

Classes

struct  lumiera_filehandlecache
 File handle cache manages file handles. More...
 

Typedefs

typedef lumiera_filehandlecache * LumieraFilehandlecache
 

Functions

void lumiera_filehandlecache_checkin (LumieraFilehandle handle)
 Put a filehandle into the cache Filehandles which are checked in are subject of cache aging and might get destroyed and reused. More...
 
LumieraFilehandle lumiera_filehandlecache_checkout (LumieraFilehandle handle)
 Remove a filehandle from cache aging Filehandles which are subject of cache aging must be checked out before they can be used. More...
 
void lumiera_filehandlecache_delete (void)
 Delete the filehandle cache. More...
 
LumieraFilehandle lumiera_filehandlecache_handle_acquire (LumieraFiledescriptor desc)
 Get a fresh filehandle. More...
 
void lumiera_filehandlecache_new (int max_entries)
 Initialises the filehandle cache. More...
 

Typedef Documentation

◆ LumieraFilehandlecache

typedef lumiera_filehandlecache* LumieraFilehandlecache

Definition at line 40 of file filehandlecache.h.


Class Documentation

◆ lumiera_filehandlecache_struct

struct lumiera_filehandlecache_struct
Class Members
lumiera_mrucache cache
int available
int checked_out
lumiera_mutex lock
+ Collaboration diagram for lumiera_filehandlecache:

Function Documentation

◆ lumiera_filehandlecache_new()

void lumiera_filehandlecache_new ( int  max_entries)

Initialises the filehandle cache.

Parameters
max_entriesnumber how much filehandles shall be managed The number of elements the cache can hold is static and should be determined by sysconf (_SC_OPEN_MAX) minus some (big) safety margin.

Definition at line 49 of file filehandlecache.c.

References lumiera_fhcache, lumiera_filehandle_destroy_node(), lumiera_malloc(), lumiera_mrucache_init(), and lumiera_mutex_init().

Referenced by lumiera_backend_init().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ lumiera_filehandlecache_delete()

void lumiera_filehandlecache_delete ( void  )

Delete the filehandle cache.

No filehandles in the cache must be locked, this would be a fatal error. The handles are closed automatically.

Definition at line 62 of file filehandlecache.c.

References lumiera_fhcache, lumiera_free(), lumiera_mrucache_destroy(), lumiera_mutex_destroy(), and NULL.

Referenced by lumiera_backend_destroy().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ lumiera_filehandlecache_handle_acquire()

LumieraFilehandle lumiera_filehandlecache_handle_acquire ( LumieraFiledescriptor  desc)

Get a fresh filehandle.

Parameters
selfpointer to the cache
Returns
the new filehandle

Definition at line 76 of file filehandlecache.c.

References LUMIERA_ERROR_SET_ALERT, lumiera_fhcache, lumiera_filedescriptor_name(), lumiera_filehandle_init(), lumiera_filehandle_new(), lumiera_mrucache_age(), lumiera_mrucache_pop(), LUMIERA_MUTEX_SECTION, NULL, and TRACE().

Referenced by lumiera_filedescriptor_handle_acquire().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ lumiera_filehandlecache_checkout()

LumieraFilehandle lumiera_filehandlecache_checkout ( LumieraFilehandle  handle)

Remove a filehandle from cache aging Filehandles which are subject of cache aging must be checked out before they can be used.

Parameters
selfthe filehandlecache
handlethe filehandle to be checked out

Definition at line 111 of file filehandlecache.c.

References lumiera_fhcache, lumiera_mrucache_checkout(), LUMIERA_MUTEX_SECTION, and TRACE().

Referenced by lumiera_filedescriptor_delete(), and lumiera_filedescriptor_handle_acquire().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ lumiera_filehandlecache_checkin()

void lumiera_filehandlecache_checkin ( LumieraFilehandle  handle)

Put a filehandle into the cache Filehandles which are checked in are subject of cache aging and might get destroyed and reused.

Parameters
handlethe filehandle to be checked in

Definition at line 132 of file filehandlecache.c.

References lumiera_fhcache, lumiera_mrucache_checkin(), LUMIERA_MUTEX_SECTION, and TRACE().

Referenced by lumiera_filedescriptor_delete(), and lumiera_filedescriptor_handle_release().

+ Here is the call graph for this function:
+ Here is the caller graph for this function: