X-Git-Url: http://info.iut-bm.univ-fcomte.fr/pub/gitweb/simgrid.git/blobdiff_plain/f22432486ef4631dfc0b19340ae387a0ecf84c20..7d0c4c0adbba2982f29444f00d1e70ad6b6aacdf:/src/gras/DataDesc/ddt_exchange.c diff --git a/src/gras/DataDesc/ddt_exchange.c b/src/gras/DataDesc/ddt_exchange.c index 62873e4ace..3f3015f013 100644 --- a/src/gras/DataDesc/ddt_exchange.c +++ b/src/gras/DataDesc/ddt_exchange.c @@ -23,7 +23,7 @@ const char *gras_datadesc_cat_names[9] = { static gras_datadesc_type_t int_type = NULL; static gras_datadesc_type_t pointer_type = NULL; -static _XBT_INLINE void +static XBT_INLINE void gras_dd_send_int(gras_socket_t sock,int *i, int stable) { if (!int_type) { @@ -35,7 +35,7 @@ gras_dd_send_int(gras_socket_t sock,int *i, int stable) { gras_trp_send(sock, (char*)i, int_type->size[GRAS_THISARCH], stable); } -static _XBT_INLINE void +static XBT_INLINE void gras_dd_recv_int(gras_socket_t sock, int r_arch, int *i) { if (!int_type) { @@ -63,7 +63,7 @@ gras_dd_recv_int(gras_socket_t sock, int r_arch, int *i) { * of 'length' bytes set to 0. * FIXME: Check in configure? */ -static _XBT_INLINE int +static XBT_INLINE int gras_dd_is_r_null(char **r_ptr, long int length) { int i; @@ -76,7 +76,7 @@ gras_dd_is_r_null(char **r_ptr, long int length) { return 1; } -static _XBT_INLINE void +static XBT_INLINE void gras_dd_alloc_ref(xbt_dict_t refs, long int size, char **r_ref, @@ -95,18 +95,17 @@ gras_dd_alloc_ref(xbt_dict_t refs, if (detect_cycle && r_ref && !gras_dd_is_r_null( r_ref, r_len)) { void *ptr = xbt_malloc(sizeof(void *)); - CRITICAL0("Check for cycles"); memcpy(ptr,l_ref, sizeof(void *)); DEBUG2("Insert l_ref=%p under r_ref=%p",*(void**)ptr, *(void**)r_ref); - + if (detect_cycle) - xbt_dict_set_ext(refs,(const char *) r_ref, r_len, ptr, free); + xbt_dict_set_ext(refs,(const char *) r_ref, r_len, ptr, xbt_free_f); } } static int -gras_datadesc_copy_rec(gras_cbps_t state, +gras_datadesc_memcpy_rec(gras_cbps_t state, xbt_dict_t refs, gras_datadesc_type_t type, char *src, @@ -155,24 +154,24 @@ gras_datadesc_copy_rec(gras_cbps_t state, field->send(type,state,field_src); DEBUG1("Copy field %s",field->name); - count += gras_datadesc_copy_rec(state,refs,sub_type, field_src, field_dst, 0, + count += gras_datadesc_memcpy_rec(state,refs,sub_type, field_src, field_dst, 0, detect_cycle || sub_type->cycle); if (XBT_LOG_ISENABLED(gras_ddt_exchange,xbt_log_priority_verbose)) { if (sub_type == gras_datadesc_by_name("unsigned int")) { - VERB2("Copied value for field %s: %d (type: unsigned int)",field->name, *(unsigned int*)field_dst); + VERB2("Copied value for field '%s': %d (type: unsigned int)",field->name, *(unsigned int*)field_dst); } else if (sub_type == gras_datadesc_by_name("int")) { - VERB2("Copied value for field %s: %d (type: int)",field->name, *(int*)field_dst); + VERB2("Copied value for field '%s': %d (type: int)",field->name, *(int*)field_dst); } else if (sub_type == gras_datadesc_by_name("unsigned long int")) { - VERB2("Copied value for field %s: %ld (type: unsigned long int)",field->name, *(unsigned long int*)field_dst); + VERB2("Copied value for field '%s': %ld (type: unsigned long int)",field->name, *(unsigned long int*)field_dst); } else if (sub_type == gras_datadesc_by_name("long int")) { - VERB2("Copied value for field %s: %ld (type: long int)",field->name, *(long int*)field_dst); + VERB2("Copied value for field '%s': %ld (type: long int)",field->name, *(long int*)field_dst); } else if (sub_type == gras_datadesc_by_name("string")) { - VERB2("Copied value for field %s: '%s' (type: string)", field->name, *(char**)field_dst); + VERB2("Copied value for field '%s': '%s' (type: string)", field->name, *(char**)field_dst); } else { - VERB1("Copied a value for field %s (type not scalar?)", field->name); + VERB1("Copied a value for field '%s' (type not scalar?)", field->name); } } @@ -199,7 +198,7 @@ gras_datadesc_copy_rec(gras_cbps_t state, "union field selector of %s gave a negative value", type->name); - xbt_assert3(field_num < xbt_dynar_length(union_data.fields), + xbt_assert3(field_num < (int)xbt_dynar_length(union_data.fields), "union field selector of %s returned %d but there is only %lu fields", type->name, field_num, xbt_dynar_length(union_data.fields)); @@ -210,7 +209,7 @@ gras_datadesc_copy_rec(gras_cbps_t state, if (field->send) field->send(type,state,src); - count += gras_datadesc_copy_rec(state,refs, sub_type, src, dst,0, + count += gras_datadesc_memcpy_rec(state,refs, sub_type, src, dst,0, detect_cycle || sub_type->cycle); break; @@ -240,11 +239,12 @@ gras_datadesc_copy_rec(gras_cbps_t state, reference_is_to_cpy = 0; TRY { - if (detect_cycle) + if (detect_cycle) { /* return ignored. Just checking whether it's known or not */ n_ref=xbt_dict_get_ext(refs,(char*)o_ref, sizeof(char*)); - else + } else { reference_is_to_cpy = 1; + } } CATCH(e) { if (e.category != not_found_error) RETHROW; @@ -285,7 +285,7 @@ gras_datadesc_copy_rec(gras_cbps_t state, detect_cycle); } - count += gras_datadesc_copy_rec(state,refs, sub_type, + count += gras_datadesc_memcpy_rec(state,refs, sub_type, *o_ref,(char*)l_referenced, subsubcount, detect_cycle || sub_type->cycle); @@ -344,7 +344,7 @@ gras_datadesc_copy_rec(gras_cbps_t state, VERB1("Array of %ld stuff, copy it in one after the other",array_count); for (cpt=0; cptcycle); src_ptr += elm_size; dst_ptr += elm_size; @@ -360,30 +360,32 @@ gras_datadesc_copy_rec(gras_cbps_t state, return count; } /** - * gras_datadesc_copy: + * gras_datadesc_memcpy: * * Copy the data pointed by src and described by type * to a new location, and store a pointer to it in dst. * */ -int gras_datadesc_copy(gras_datadesc_type_t type, +int gras_datadesc_memcpy(gras_datadesc_type_t type, void *src, void *dst) { xbt_ex_t e; - gras_cbps_t state; - xbt_dict_t refs; /* all references already sent */ + static gras_cbps_t state=NULL; + static xbt_dict_t refs=NULL; /* all references already sent */ int size=0; xbt_assert0(type,"called with NULL type descriptor"); - refs = xbt_dict_new(); - state = gras_cbps_new(); + if (!state) { + state = gras_cbps_new(); + refs = xbt_dict_new(); + } TRY { - size = gras_datadesc_copy_rec(state,refs,type,(char*)src,(char*)dst,0, - type->cycle); + size = gras_datadesc_memcpy_rec(state,refs,type,(char*)src,(char*)dst,0, + type->cycle); } CLEANUP { - xbt_dict_free(&refs); - gras_cbps_free(&state); + xbt_dict_reset(refs); + gras_cbps_reset(state); } CATCH(e) { RETHROW; } @@ -470,7 +472,7 @@ gras_datadesc_send_rec(gras_socket_t sock, "union field selector of %s gave a negative value", type->name); - xbt_assert3(field_num < xbt_dynar_length(union_data.fields), + xbt_assert3(field_num < (int)xbt_dynar_length(union_data.fields), "union field selector of %s returned %d but there is only %lu fields", type->name, field_num, xbt_dynar_length(union_data.fields)); @@ -609,18 +611,19 @@ void gras_datadesc_send(gras_socket_t sock, xbt_ex_t e; static gras_cbps_t state=NULL; - xbt_dict_t refs; /* all references already sent */ + static xbt_dict_t refs=NULL; /* all references already sent */ xbt_assert0(type,"called with NULL type descriptor"); - refs = xbt_dict_new(); - if (!state) + if (!state) { state = gras_cbps_new(); - + refs = xbt_dict_new(); + } + TRY { gras_datadesc_send_rec(sock,state,refs,type,(char*)src, type->cycle); } CLEANUP { - xbt_dict_free(&refs); + xbt_dict_reset(refs); gras_cbps_reset(state); } CATCH(e) { RETHROW; @@ -720,7 +723,7 @@ gras_datadesc_recv_rec(gras_socket_t sock, if (field_num < 0) THROW1(mismatch_error,0, "Received union field for %s is negative", type->name); - if (field_num > xbt_dynar_length(union_data.fields)) + if (field_num > (int)xbt_dynar_length(union_data.fields)) THROW3(mismatch_error,0, "Received union field for %s is said to be #%d but there is only %lu fields", type->name, field_num, xbt_dynar_length(union_data.fields)); @@ -777,16 +780,18 @@ gras_datadesc_recv_rec(gras_socket_t sock, reference_is_to_recv = 0; TRY { - if (detect_cycle) + if (detect_cycle) { l_ref = xbt_dict_get_ext(refs, (char*)r_ref, pointer_type->size[r_arch]); - else + } else { reference_is_to_recv = 1; + } } CATCH(e) { if (e.category != not_found_error) RETHROW; reference_is_to_recv = 1; xbt_ex_free(e); } + if (reference_is_to_recv) { int subsubcount = 0; void *l_referenced=NULL; @@ -944,12 +949,13 @@ gras_datadesc_recv(gras_socket_t sock, xbt_ex_t e; static gras_cbps_t state=NULL; /* callback persistent state */ - xbt_dict_t refs; /* all references already sent */ + static xbt_dict_t refs=NULL; /* all references already sent */ - refs = xbt_dict_new(); - if (!state) + if (!state) { state = gras_cbps_new(); - + refs = xbt_dict_new(); + } + xbt_assert0(type,"called with NULL type descriptor"); TRY { gras_datadesc_recv_rec(sock, state, refs, type, @@ -957,7 +963,7 @@ gras_datadesc_recv(gras_socket_t sock, (char *) dst,-1, type->cycle); } CLEANUP { - xbt_dict_free(&refs); + xbt_dict_reset(refs); gras_cbps_reset(state); } CATCH(e) { RETHROW;