A
lgorithmique
N
umérique
D
istribuée
Public GIT Repository
projects
/
simgrid.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
this is C++
[simgrid.git]
/
src
/
xbt
/
lib.c
diff --git
a/src/xbt/lib.c
b/src/xbt/lib.c
index
e8f6a21
..
8c7c827
100644
(file)
--- a/
src/xbt/lib.c
+++ b/
src/xbt/lib.c
@@
-1,6
+1,6
@@
/* lib - a generic library, variation over dictionary */
/* lib - a generic library, variation over dictionary */
-/* Copyright (c) 2011. The SimGrid Team.
+/* Copyright (c) 2011
, 2013-2015
. The SimGrid Team.
* All rights reserved. */
/* This program is free software; you can redistribute it and/or modify it
* All rights reserved. */
/* This program is free software; you can redistribute it and/or modify it
@@
-17,7
+17,7
@@
xbt_lib_t xbt_lib_new(void)
{
xbt_lib_t lib;
lib = xbt_new(s_xbt_lib_t, 1);
{
xbt_lib_t lib;
lib = xbt_new(s_xbt_lib_t, 1);
- lib->dict = xbt_dict_new_homogeneous(xbt_free);
+ lib->dict = xbt_dict_new_homogeneous(xbt_free
_f
);
lib->levels = 0;
lib->free_f = NULL;
return lib;
lib->levels = 0;
lib->free_f = NULL;
return lib;
@@
-33,7
+33,7
@@
void xbt_lib_free(xbt_lib_t *plib)
xbt_dict_foreach (lib->dict, cursor, key, elts) {
int i;
for (i = 0 ; i < lib->levels ; i++)
xbt_dict_foreach (lib->dict, cursor, key, elts) {
int i;
for (i = 0 ; i < lib->levels ; i++)
- if (elts[i])
+ if (elts[i]
&& lib->free_f[i]
)
lib->free_f[i](elts[i]);
}
xbt_dict_free(&lib->dict);
lib->free_f[i](elts[i]);
}
xbt_dict_free(&lib->dict);
@@
-65,13
+65,13
@@
void xbt_lib_set(xbt_lib_t lib, const char *key, int level, void *obj)
if (elts[level]) {
XBT_DEBUG("Replace %p by %p element under key '%s:%d'",
elts[level], obj, key, level);
if (elts[level]) {
XBT_DEBUG("Replace %p by %p element under key '%s:%d'",
elts[level], obj, key, level);
- lib->free_f[level](elts[level]);
+ if (lib->free_f[level])
+ lib->free_f[level](elts[level]);
}
elts[level] = obj;
}
}
elts[level] = obj;
}
-/* for vm */
-void xbt_lib_unset(xbt_lib_t lib, const char *key, int level)
+void xbt_lib_unset(xbt_lib_t lib, const char *key, int level, int invoke_callback)
{
void **elts = xbt_dict_get_or_null(lib->dict, key);
if (!elts) {
{
void **elts = xbt_dict_get_or_null(lib->dict, key);
if (!elts) {
@@
-80,25
+80,28
@@
void xbt_lib_unset(xbt_lib_t lib, const char *key, int level)
}
void *obj = elts[level];
}
void *obj = elts[level];
-
if (!obj) {
XBT_WARN("no key %s at level %d", key, level);
return;
if (!obj) {
XBT_WARN("no key %s at level %d", key, level);
return;
- } else {
- XBT_DEBUG("Remove %p of key %s at level %d", obj, key, level);
- lib->free_f[level](obj);
- elts[level] = NULL;
}
}
- /* check if there are elements of this key */
+ XBT_DEBUG("Remove %p of key %s at level %d", obj, key, level);
+ elts[level] = NULL;
+
+ /* check if there still remains any elements of this key */
+ int empty = 1;
int i;
int i;
- for (i = 0; i < lib->levels; i++) {
+ for (i = 0; i < lib->levels
&& empty
; i++) {
if (elts[i] != NULL)
if (elts[i] != NULL)
- return;
+ empty = 0;
+ }
+ if (empty) {
+ /* there is no element at any level, so delete the key */
+ xbt_dict_remove(lib->dict, key);
}
}
- /* there is no element at any level, so delete the key */
- xbt_dict_remove(lib->dict, key)
+ if (invoke_callback && lib->free_f[level])
+ lib->free_f[level](obj);
}
void *xbt_lib_get_or_null(xbt_lib_t lib, const char *key, int level)
}
void *xbt_lib_get_or_null(xbt_lib_t lib, const char *key, int level)