Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Mallocator on the message contextes
authormquinson <mquinson@48e7efb5-ca39-0410-a469-dd3cf9ba447f>
Tue, 21 Nov 2006 16:53:26 +0000 (16:53 +0000)
committermquinson <mquinson@48e7efb5-ca39-0410-a469-dd3cf9ba447f>
Tue, 21 Nov 2006 16:53:26 +0000 (16:53 +0000)
git-svn-id: svn+ssh://scm.gforge.inria.fr/svn/simgrid/simgrid/trunk@2938 48e7efb5-ca39-0410-a469-dd3cf9ba447f

src/gras/Msg/msg.c
src/gras/Msg/msg_private.h
src/gras/Msg/rpc.c

index c669fbd..a041dba 100644 (file)
@@ -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);
 }
 
 /*
index 7b03a7a..69fd2dc 100644 (file)
@@ -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 */
index 5c34d0a..fe462de 100644 (file)
@@ -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);