1 #ifndef MEMCACHE_H
 2 #define MEMCACHE_H
 3 
 4 #include <sys/time.h>
 5 #include "queue.h"
 6 
 7 typedef struct memcache_entry   memcache_entry_t;
 8 typedef struct memcache_base    memcache_t;
 9 
10 TAILQ_HEAD(memcache_entry_list, memcache_entry);
11 
12 /*
13  * struct size: <= 40 byte 
14  *
15  */
16 struct memcache_entry {
17         size_t                          size;
18         time_t                          atime;
19         TAILQ_ENTRY(memcache_entry)     buckets;
20         TAILQ_ENTRY(memcache_entry)     timeout;
21 };
22 
23 struct memcache_base {
24         
25         /* pointer to the current time. */
26         time_t                          *time;
27 
28         time_t                          last_timeout_test;
29 
30         time_t                          last_reset;
31 
32         size_t                          limit;
33         size_t                          usage;
34 
35         /* linked list hash of memcache_entry
36          *
37          * add at tail
38          * rem at head
39          * 
40          */
41 
42         /* the list head */
43         struct memcache_entry_list      *buckets;
44 
45         /* element count of buckets */
46         size_t                          nbuckets;
47 
48         /* number of currently stored elements */
49         size_t                          nelements;
50         
51         /* timeout list, every element is also stored here */
52         struct memcache_entry_list      timeout;
53 };
54 
55 void memcache_init    (memcache_t *cache, time_t *current_time);
56 void memcache_destroy (memcache_t *cache);
57 
58 void * memcache_pop  (memcache_t *cache, size_t size);
59 void   memcache_push (memcache_t *cache, void *ptr, size_t size);
60 
61 #endif /* MEMCACHE_H */


syntax highlighted by Code2HTML, v. 0.9.1