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

Subversion Repositories c0or1k

[/] [c0or1k/] [trunk/] [conts/] [libmem/] [memcache/] [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
 
15
/* Very basic cache structure. All it does is, keep an internal bitmap of
16
 * items of struct_size. (Note bitmap is fairly efficient and simple for a
17
 * fixed-size memory cache) Keeps track of free/occupied items within its
18
 * start/end boundaries. Does not grow/shrink but you can link-list it. */
19
struct mem_cache {
20
        struct link list;
21
        int total;
22
        int free;
23
        unsigned int start;
24
        unsigned int end;
25
        unsigned int struct_size;
26
        unsigned int *bitmap;
27
};
28
 
29
void *mem_cache_zalloc(struct mem_cache *cache);
30
void *mem_cache_alloc(struct mem_cache *cache);
31
int mem_cache_free(struct mem_cache *cache, void *addr);
32
struct mem_cache *mem_cache_init(void *start, int cache_size,
33
                                 int struct_size, unsigned int alignment);
34
static inline int mem_cache_is_full(struct mem_cache *cache)
35
{
36
        return cache->free == 0;
37
}
38
static inline int mem_cache_is_empty(struct mem_cache *cache)
39
{
40
        return cache->free == cache->total;
41
}
42
static inline int mem_cache_is_last_free(struct mem_cache *cache)
43
{
44
        return cache->free == 1;
45
}
46
static inline int mem_cache_total_empty(struct mem_cache *cache)
47
{
48
        return cache->free;
49
}
50
#endif /* __MEMCACHE_H__ */

powered by: WebSVN 2.1.0

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