OpenCores
URL https://opencores.org/ocsvn/c0or1k/c0or1k/trunk

Subversion Repositories c0or1k

[/] [c0or1k/] [trunk/] [include/] [l4/] [lib/] [memcache.h] - Blame information for rev 2

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 2 drasko
/*
2
 * Bitmap-based link-listable fixed-size memory cache.
3
 *
4
 * Copyright (C) 2007 Bahadir Balban
5
 */
6
 
7
#ifndef __MEMCACHE_H__
8
#define __MEMCACHE_H__
9
 
10
#include <l4/config.h>
11
#include <l4/macros.h>
12
#include <l4/types.h>
13
#include <l4/lib/list.h>
14
#include <l4/lib/mutex.h>
15
 
16
/*
17
 * Very basic cache structure. All it does is, keep an internal bitmap of
18
 * items of struct_size. (Note bitmap is fairly efficient and simple for a
19
 * fixed-size memory cache) Keeps track of free/occupied items within its
20
 * start/end boundaries. Does not grow/shrink but you can link-list it.
21
 */
22
struct mem_cache {
23
        struct link list;
24
        struct mutex mutex;
25
        int total;
26
        int free;
27
        unsigned int start;
28
        unsigned int end;
29
        unsigned int struct_size;
30
        unsigned int *bitmap;
31
};
32
 
33
int mem_cache_bufsize(void *start, int struct_size, int nstructs, int aligned);
34
void *mem_cache_zalloc(struct mem_cache *cache);
35
void *mem_cache_alloc(struct mem_cache *cache);
36
int mem_cache_free(struct mem_cache *cache, void *addr);
37
struct mem_cache *mem_cache_init(void *start, int cache_size,
38
                                 int struct_size, unsigned int alignment);
39
static inline int mem_cache_is_full(struct mem_cache *cache)
40
{
41
        return cache->free == 0;
42
}
43
static inline int mem_cache_is_empty(struct mem_cache *cache)
44
{
45
        return cache->free == cache->total;
46
}
47
static inline int mem_cache_is_last_free(struct mem_cache *cache)
48
{
49
        return cache->free == 1;
50
}
51
static inline int mem_cache_total_empty(struct mem_cache *cache)
52
{
53
        return cache->free;
54
}
55
#endif /* __MEMCACHE_H__ */

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.