Skip to content

Commit a45544e

Browse files
committed
Revert "map: add support for persistent storage"
This reverts commit 0e6333d.
1 parent d1fbd99 commit a45544e

File tree

2 files changed

+29
-33
lines changed

2 files changed

+29
-33
lines changed

map.c

Lines changed: 28 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -28,11 +28,27 @@
2828
#include <stdlib.h>
2929
#include <string.h>
3030
#include "str.h"
31+
#include "map.h"
3132

3233
#include "mem/mem.h"
3334
#include "mem/shm_mem.h"
34-
#include "mem/rpm_mem.h"
35-
#include "map.h"
35+
36+
#define avl_malloc(dest,size,flags) do \
37+
{ \
38+
if(flags & AVLMAP_SHARED) \
39+
(dest) = shm_malloc(size); \
40+
else \
41+
(dest) = pkg_malloc(size); \
42+
} while(0)
43+
44+
#define avl_free(dest,flags) do \
45+
{ \
46+
if(flags & AVLMAP_SHARED) \
47+
shm_free(dest); \
48+
else \
49+
pkg_free(dest); \
50+
} while(0)
51+
3652

3753
#define min(a,b) ((a)<(b))?(a):(b)
3854

@@ -59,24 +75,11 @@ static int str_cmp(str s1, str s2)
5975
map_t map_create(enum map_flags flags)
6076
{
6177
map_t tree;
62-
osips_malloc_f m;
63-
osips_free_f f;
64-
65-
if (flags & AVLMAP_PERSISTENT) {
66-
m = rpm_malloc_func;
67-
f = rpm_free_func;
68-
} else if (flags & AVLMAP_SHARED) {
69-
m = shm_malloc_func;
70-
f = shm_free_func;
71-
} else {
72-
m = pkg_malloc_func;
73-
f = pkg_free_func;
74-
}
75-
tree = func_malloc(m, sizeof *tree);
78+
79+
avl_malloc(tree, sizeof *tree, flags);
80+
7681
if (tree == NULL)
7782
return NULL;
78-
tree->malloc = m;
79-
tree->free = f;
8083

8184
tree->avl_root = NULL;
8285
tree->flags = flags;
@@ -133,7 +136,7 @@ void ** map_get( map_t tree, str key)
133136
y = p;
134137
}
135138

136-
n = func_malloc(tree->malloc, sizeof *n);
139+
avl_malloc( n, sizeof *n, tree->flags );
137140

138141
if (n == NULL)
139142
return NULL;
@@ -144,7 +147,7 @@ void ** map_get( map_t tree, str key)
144147

145148
if( !( tree->flags & AVLMAP_NO_DUPLICATE ) )
146149
{
147-
key_copy.s = func_malloc(tree->malloc, key.len);
150+
avl_malloc(key_copy.s, key.len, tree->flags );
148151
if (!key_copy.s)
149152
return NULL;
150153

@@ -327,9 +330,9 @@ void * delete_node(map_t tree, struct avl_node * p)
327330
}
328331

329332
if(!( tree->flags & AVLMAP_NO_DUPLICATE ) )
330-
func_free(tree->free, p->key.s);
333+
avl_free(p->key.s,tree->flags);
331334

332-
func_free(tree->free, p);
335+
avl_free(p,tree->flags);
333336

334337
while (q != (struct avl_node *) & tree->avl_root) {
335338
struct avl_node *y = q;
@@ -481,15 +484,15 @@ void map_destroy( map_t tree, value_destroy_func destroy)
481484
if (destroy != NULL && p->val != NULL)
482485
destroy(p->val);
483486
if( !(tree->flags & AVLMAP_NO_DUPLICATE ) )
484-
func_free(tree->free, p->key.s);
485-
func_free(tree->free, p);
487+
avl_free( p->key.s,tree->flags);
488+
avl_free( p, tree->flags );
486489
} else {
487490
q = p->avl_link[0];
488491
p->avl_link[0] = q->avl_link[1];
489492
q->avl_link[1] = p;
490493
}
491494

492-
func_free(tree->free, tree);
495+
avl_free( tree, tree->flags );
493496
}
494497

495498
int map_size( map_t tree )

map.h

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@
2424
*/
2525

2626
#include "str.h"
27-
#include "mem/mem.h"
2827
#include <stddef.h>
2928

3029
#ifndef AVL_H
@@ -42,9 +41,7 @@ enum map_flags
4241
{
4342
AVLMAP_SHARED = 1, /* determines if the map is to be allocated in
4443
shared or private memory */
45-
AVLMAP_NO_DUPLICATE = 2, /* determines if the map will duplicate added keys*/
46-
AVLMAP_PERSISTENT = 4, /* determines if the map will be stored in
47-
persistent memory */
44+
AVLMAP_NO_DUPLICATE = 2 /* determines if the map will duplicate added keys*/
4845

4946
};
5047

@@ -55,9 +52,6 @@ typedef struct avl_table {
5552
size_t avl_count; /* Number of items in tree. */
5653
int ret_code;
5754

58-
osips_malloc_f malloc;
59-
osips_free_f free;
60-
6155
} *map_t;
6256

6357
/* Iterator data structure. */
@@ -104,7 +98,6 @@ typedef int (* process_each_func )(void * param, str key, void * value);
10498
*
10599
* AVLMAP_SHARED -> flag for shared memory
106100
* AVLMAP_NO_DUPLICATE -> flag for key duplication
107-
* AVLMAP_PERSISTENT -> flag for persistent shared memory
108101
*
109102
*/
110103

0 commit comments

Comments
 (0)