XBT_PUBLIC(int) xbt_lib_add_level(xbt_lib_t lib, void_f_pvoid_t free_f);
XBT_PUBLIC(void) xbt_lib_set(xbt_lib_t lib, const char *name, int level,
void *obj);
+XBT_PUBLIC(void) xbt_lib_unset(xbt_lib_t lib, const char *key, int level);
XBT_PUBLIC(void *) xbt_lib_get_or_null(xbt_lib_t lib, const char *name,
int level);
XBT_PUBLIC(xbt_dictelm_t) xbt_lib_get_elm_or_null(xbt_lib_t lib, const char *key);
// start does not appear here as it corresponds to turn the state from created to running (see smx_vm.c)
int (*get_state) (void *workstation);
void (*set_state) (void *workstation, int state);
- void (*destroy) (const char *name); // destory the vm-specific data
+ void (*destroy) (smx_host_t *host); // destory the vm-specific data
} s_surf_model_extension_vm_workstation_t;
/** \ingroup SURF_models
vm_ws->current_state=msg_vm_state_created,
xbt_lib_set(host_lib, name, SURF_WKS_LEVEL, vm_ws);
}
+
+
/*
* A physical host does not disapper in the current SimGrid code, but a VM may
* disapper during a simulation.
*/
-static void vm_ws_destroy(const char *name)
-{
- workstation_VM2013_t workstation = xbt_lib_get_or_null(host_lib, name, SURF_WKS_LEVEL);
- xbt_assert(workstation);
- xbt_assert(workstation->generic_resource.model == surf_vm_workstation_model);
-
- xbt_free(workstation->generic_resource.name);
+static void vm_ws_destroy(smx_host_t host)
+{
+ workstation_VM2013_t vm_ws = surf_workstation_resource_priv(host);
+ xbt_assert(vm_ws);
+ xbt_assert(vm_ws->generic_resource.model == surf_vm_workstation_model);
+ const char *name = vm_ws->generic_resource.name;
/* not defined yet, but we should have */
/* this will call surf_resource_free() */
xbt_lib_unset(host_lib, name, SURF_WKS_LEVEL);
- xbt_free(workstation);
+ xbt_free(vm_ws->generic_resource.name);
+ xbt_free(vm_ws);
}
static int vm_ws_get_state(void *ind_vm_ws){
elts[level] = obj;
}
+/* for vm */
+void xbt_lib_unset(xbt_lib_t lib, const char *key, int level)
+{
+ void **elts = xbt_dict_get_or_null(lib->dict, key);
+ if (!elts) {
+ XBT_WARN("no key %s", key);
+ return;
+ }
+
+ void *obj = elts[level];
+
+ 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 */
+ int i;
+ for (i = 0; i < lib->levels; i++) {
+ if (elts[i] != NULL)
+ return;
+ }
+
+ /* there is no element at any level, so delete the key */
+ xbt_dict_remove(lib->dict, key)
+}
+
void *xbt_lib_get_or_null(xbt_lib_t lib, const char *key, int level)
{
void **elts = xbt_dict_get_or_null(lib->dict, key);