Back to index

avfs  1.0.1
Classes | Functions | Variables
filecache.c File Reference
#include "filecache.h"
#include "internal.h"
#include "exit.h"

Go to the source code of this file.

Classes

struct  filecache

Functions

static AV_LOCK_DECL (fclock)
static void filecache_remove (struct filecache *fc)
static void filecache_insert (struct filecache *fc)
static void filecache_delete (struct filecache *fc)
static struct filecachefilecache_find (const char *key)
void * av_filecache_get (const char *key)
void av_filecache_set (const char *key, void *obj)
static void destroy_filecache ()
void av_init_filecache ()
int av_filecache_getkey (ventry *ve, char **resp)

Variables

static struct filecache

Class Documentation

struct filecache

Definition at line 13 of file filecache.c.

Collaboration diagram for filecache:
Class Members
char * key
struct filecache * next
void * obj
struct filecache * prev

Function Documentation

void* av_filecache_get ( const char *  key)

Definition at line 69 of file filecache.c.

{
    struct filecache *fc;
    void *obj = NULL;
    
    AV_LOCK(fclock);
    fc = filecache_find(key);
    if(fc != NULL) {
        filecache_remove(fc);
        filecache_insert(fc);
        obj = fc->obj;
        av_ref_obj(obj);
    }
    AV_UNLOCK(fclock);

    return obj;
}

Here is the call graph for this function:

Here is the caller graph for this function:

int av_filecache_getkey ( ventry *  ve,
char **  resp 
)

Definition at line 131 of file filecache.c.

{
    int res;
    char *key;

    res = av_generate_path(ve->mnt->base, &key);
    if(res < 0)
        return res;

    key = av_stradd(key, AVFS_SEP_STR, ve->mnt->avfs->name, NULL);

    *resp = key;
    return 0;
}

Here is the call graph for this function:

Here is the caller graph for this function:

void av_filecache_set ( const char *  key,
void *  obj 
)

Definition at line 87 of file filecache.c.

{
    struct filecache *oldfc;
    struct filecache *fc;

    if(obj != NULL) {
        AV_NEW(fc);
        fc->key = av_strdup(key);
        fc->obj = obj;
        av_ref_obj(obj);
    }
    else
        fc = NULL;

    AV_LOCK(fclock);
    oldfc = filecache_find(key);
    if(oldfc != NULL)
        filecache_delete(oldfc);
    if(fc != NULL) {
        av_log(AVLOG_DEBUG, "FILECACHE: insert <%s>", key);
        filecache_insert(fc);
    }
    AV_UNLOCK(fclock);
}

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 120 of file filecache.c.

{
    fclist.next = &fclist;
    fclist.prev = &fclist;
    fclist.obj = NULL;
    fclist.key = NULL;
    
    av_add_exithandler(destroy_filecache);
}

Here is the call graph for this function:

Here is the caller graph for this function:

static AV_LOCK_DECL ( fclock  ) [static]
static void destroy_filecache ( ) [static]

Definition at line 112 of file filecache.c.

{
    AV_LOCK(fclock);
    while(fclist.next != &fclist)
        filecache_delete(fclist.next);
    AV_UNLOCK(fclock);
}

Here is the call graph for this function:

Here is the caller graph for this function:

static void filecache_delete ( struct filecache fc) [static]

Definition at line 44 of file filecache.c.

{
    av_log(AVLOG_DEBUG, "FILECACHE: delete <%s>", fc->key);
    filecache_remove(fc);

    av_unref_obj(fc->obj);
    av_free(fc->key);
    av_free(fc);
}

Here is the call graph for this function:

Here is the caller graph for this function:

static struct filecache* filecache_find ( const char *  key) [static, read]

Definition at line 54 of file filecache.c.

{
    struct filecache *fc;
    
    for(fc = fclist.next; fc != &fclist; fc = fc->next) {
        if(strcmp(fc->key, key) == 0)
            break;
    }

    if(fc->obj == NULL)
        return NULL;

    return fc;
}

Here is the caller graph for this function:

static void filecache_insert ( struct filecache fc) [static]

Definition at line 33 of file filecache.c.

{
    struct filecache *prev = &fclist;
    struct filecache *next = fclist.next;
    
    prev->next = fc;
    next->prev = fc;
    fc->prev = prev;
    fc->next = next;
}

Here is the caller graph for this function:

static void filecache_remove ( struct filecache fc) [static]

Definition at line 24 of file filecache.c.

{
    struct filecache *prev = fc->prev;
    struct filecache *next = fc->next;

    prev->next = next;
    next->prev = prev;
}

Here is the caller graph for this function:


Variable Documentation

struct filecache [static]

Definition at line 21 of file filecache.c.