From: mquinson Date: Tue, 21 Nov 2006 16:53:26 +0000 (+0000) Subject: Mallocator on the message contextes X-Git-Tag: v3.3~2421 X-Git-Url: http://info.iut-bm.univ-fcomte.fr/pub/gitweb/simgrid.git/commitdiff_plain/5ce5e2ee7fd0dd8344be0823d7bd7c4abb16b284 Mallocator on the message contextes git-svn-id: svn+ssh://scm.gforge.inria.fr/svn/simgrid/simgrid/trunk@2938 48e7efb5-ca39-0410-a469-dd3cf9ba447f --- diff --git a/src/gras/Msg/msg.c b/src/gras/Msg/msg.c index c669fbdf4d..a041dba75b 100644 --- a/src/gras/Msg/msg.c +++ b/src/gras/Msg/msg.c @@ -79,6 +79,12 @@ void gras_msg_init(void) { memcpy(_GRAS_header,"GRAS", 4); _GRAS_header[4]=GRAS_PROTOCOL_VERSION; _GRAS_header[5]=(char)GRAS_THISARCH; + + gras_msg_ctx_mallocator = + xbt_mallocator_new(1000, + gras_msg_ctx_mallocator_new_f, + gras_msg_ctx_mallocator_free_f, + gras_msg_ctx_mallocator_reset_f); } /* @@ -88,6 +94,8 @@ void gras_msg_exit(void) { VERB0("Exiting Msg"); xbt_set_free(&_gras_msgtype_set); + + xbt_mallocator_free(gras_msg_ctx_mallocator); } /* diff --git a/src/gras/Msg/msg_private.h b/src/gras/Msg/msg_private.h index 7b03a7ae15..69fd2dc414 100644 --- a/src/gras/Msg/msg_private.h +++ b/src/gras/Msg/msg_private.h @@ -121,4 +121,12 @@ XBT_PUBLIC gras_msg_cb_ctx_t gras_msg_cb_ctx_new(gras_socket_t expe, double timeout); +/* We deploy a mallocator on the RPC contextes */ +#include "xbt/mallocator.h" +extern xbt_mallocator_t gras_msg_ctx_mallocator; +XBT_PUBLIC void* gras_msg_ctx_mallocator_new_f(void); +XBT_PUBLIC void gras_msg_ctx_mallocator_free_f(void* dict); +XBT_PUBLIC void gras_msg_ctx_mallocator_reset_f(void* dict); + + #endif /* GRAS_MESSAGE_PRIVATE_H */ diff --git a/src/gras/Msg/rpc.c b/src/gras/Msg/rpc.c index 5c34d0a080..fe462de15e 100644 --- a/src/gras/Msg/rpc.c +++ b/src/gras/Msg/rpc.c @@ -91,13 +91,25 @@ static int msgfilter_rpcID(gras_msg_t msg, void* ctx) { return res; } +/* Mallocator cruft */ +xbt_mallocator_t gras_msg_ctx_mallocator = NULL; +void* gras_msg_ctx_mallocator_new_f(void) { + return xbt_new0(s_gras_msg_cb_ctx_t,1); +} +void gras_msg_ctx_mallocator_free_f(void* ctx) { + xbt_free(ctx); +} +void gras_msg_ctx_mallocator_reset_f(void* ctx) { + memset(ctx, sizeof(s_gras_msg_cb_ctx_t),0); +} + /** @brief Launch a RPC call, but do not block for the answer */ gras_msg_cb_ctx_t gras_msg_rpc_async_call(gras_socket_t server, double timeOut, gras_msgtype_t msgtype, void *request) { - gras_msg_cb_ctx_t ctx = xbt_new0(s_gras_msg_cb_ctx_t,1); + gras_msg_cb_ctx_t ctx = xbt_mallocator_get(gras_msg_ctx_mallocator); if (msgtype->ctn_type) { xbt_assert1(request, @@ -159,7 +171,7 @@ void gras_msg_rpc_async_wait(gras_msg_cb_ctx_t ctx, RETHROW; } - free(ctx); + xbt_mallocator_release(gras_msg_ctx_mallocator, ctx); if (received.kind == e_gras_msg_kind_rpcerror) { xbt_ex_t e; memcpy(&e,received.payl,received.payl_size);