- smpi_execute(smpi_stop_timer());
-}
-
-void smpi_do_once_1(const char *file, int line) {
- smpi_do_once_duration_node_t curr, prev;
- smpi_bench_end();
- SIMIX_mutex_lock(smpi_global->do_once_mutex);
- prev = NULL;
- for(curr = smpi_global->do_once_duration_nodes;
- NULL != curr && (strcmp(curr->file, file) || curr->line != line);
- curr = curr->next) {
- prev = curr;
- }
- if (NULL == curr) {
- curr = xbt_new(s_smpi_do_once_duration_node_t, 1);
- curr->file = xbt_strdup(file);
- curr->line = line;
- curr->duration = -1;
- curr->next = NULL;
- if (NULL == prev) {
- smpi_global->do_once_duration_nodes = curr;
- } else {
- prev->next = curr;
- }
- }
- smpi_global->do_once_duration = &curr->duration;
-}
-
-int smpi_do_once_2() {
- double duration = *(smpi_global->do_once_duration);
- if (0 < duration) {
- SIMIX_mutex_unlock(smpi_global->do_once_mutex);
- smpi_execute(duration);
- smpi_bench_begin();
- return 0;
- }
- smpi_start_timer();
- return 1;
-}
-
-void smpi_do_once_3() {
- *(smpi_global->do_once_duration) = smpi_stop_timer();
+ char *loc = bprintf("%s:%d:%zu", file, line, size);
+ shared_data_t *data;
+
+ if (!allocs) {
+ allocs = xbt_dict_new();
+ }
+ data = xbt_dict_get_or_null(allocs, loc);
+ if (!data) {
+ data = (shared_data_t *) xbt_malloc0(sizeof(int) + size);
+ data->count = 1;
+ xbt_dict_set(allocs, loc, data, &free);
+ } else {
+ data->count++;
+ }
+ free(loc);
+ return data->data;
+}
+
+void smpi_shared_free(void *ptr)
+{
+ shared_data_t *data = (shared_data_t *) ((int *) ptr - 1);
+ char *loc;
+
+ if (!allocs) {
+ XBT_WARN("Cannot free: nothing was allocated");
+ return;
+ }
+ loc = xbt_dict_get_key(allocs, data);
+ if (!loc) {
+ XBT_WARN("Cannot free: %p was not shared-allocated by SMPI", ptr);
+ return;
+ }
+ data->count--;
+ if (data->count <= 0) {
+ xbt_dict_remove(allocs, loc);
+ }
+}
+
+int smpi_shared_known_call(const char* func, const char* input) {
+ char* loc = bprintf("%s:%s", func, input);
+ xbt_ex_t ex;
+ int known;
+
+ if(!calls) {
+ calls = xbt_dict_new();
+ }
+ TRY {
+ xbt_dict_get(calls, loc); /* Succeed or throw */
+ known = 1;
+ } CATCH(ex) {
+ if(ex.category == not_found_error) {
+ known = 0;
+ xbt_ex_free(ex);
+ } else {
+ RETHROW;
+ }
+ }
+ free(loc);
+ return known;
+}
+
+void* smpi_shared_get_call(const char* func, const char* input) {
+ char* loc = bprintf("%s:%s", func, input);
+ void* data;
+
+ if(!calls) {
+ calls = xbt_dict_new();
+ }
+ data = xbt_dict_get(calls, loc);
+ free(loc);
+ return data;
+}
+
+void* smpi_shared_set_call(const char* func, const char* input, void* data) {
+ char* loc = bprintf("%s:%s", func, input);
+
+ if(!calls) {
+ calls = xbt_dict_new();
+ }
+ xbt_dict_set(calls, loc, data, NULL);
+ free(loc);
+ return data;