1 /* -*- Mode: C; tab-width: 2; c-basic-offset: 2; indent-tabs-mode: nil -*- */
2 #include "mem_config.h"
12 struct list_entry
*next
;
13 struct list_entry
*prev
;
16 static struct list_entry
*root
;
19 bool initialize_storage(void)
24 void shutdown_storage(void)
29 void put_item(struct item
* item
)
31 struct list_entry
* entry
= (struct list_entry
*)item
;
37 entry
->next
= entry
->prev
= entry
;
41 entry
->prev
= root
->prev
;
43 entry
->prev
->next
= entry
;
44 entry
->next
->prev
= entry
;
50 struct item
* get_item(const void* key
, size_t nkey
)
52 struct list_entry
*walker
= root
;
61 if (((struct item
*)walker
)->nkey
== nkey
&&
62 memcmp(((struct item
*)walker
)->key
, key
, nkey
) == 0)
64 return (struct item
*)walker
;
67 } while (walker
!= root
);
72 struct item
* create_item(const void* key
, size_t nkey
, const void* data
,
73 size_t size
, uint32_t flags
, time_t exp
)
75 struct item
* ret
= (struct item
*)calloc(1, sizeof(struct list_entry
));
79 ret
->key
= malloc(nkey
);
82 ret
->data
= malloc(size
);
85 if (ret
->key
== NULL
|| (size
> 0 && ret
->data
== NULL
))
93 memcpy(ret
->key
, key
, nkey
);
96 memcpy(ret
->data
, data
, size
);
108 bool delete_item(const void* key
, size_t nkey
)
110 struct item
* item
= get_item(key
, nkey
);
115 /* remove from linked list */
116 struct list_entry
*entry
= (struct list_entry
*)item
;
118 if (entry
->next
== entry
)
120 /* Only one object in the list */
125 /* ensure that we don't loose track of the root, and this will
126 * change the start position for the next search ;-) */
128 entry
->prev
->next
= entry
->next
;
129 entry
->next
->prev
= entry
->prev
;
141 void flush(uint32_t /* when */)
143 /* remove the complete linked list */
149 root
->prev
->next
= NULL
;
152 struct item
* tmp
= (struct item
*)root
;
161 void update_cas(struct item
* item
)
166 void release_item(struct item
* /* item */)