1 /* gras message types handling */
3 /* Copyright (c) 2007, 2009, 2010. The SimGrid Team.
4 * All rights reserved. */
6 /* This program is free software; you can redistribute it and/or modify it
7 * under the terms of the license (GNU LGPL) which comes with this package. */
10 #include "gras/Msg/msg_private.h"
11 #include "gras/Virtu/virtu_interface.h"
13 XBT_LOG_EXTERNAL_DEFAULT_CATEGORY(gras_msg);
15 extern xbt_set_t _gras_msgtype_set;
18 * Creating procdata for this module
20 static void *gras_msg_procdata_new(void)
22 gras_msg_procdata_t res = xbt_new(s_gras_msg_procdata_t, 1);
24 res->name = xbt_strdup("gras_msg");
26 res->msg_queue = xbt_dynar_new(sizeof(s_gras_msg_t), NULL);
27 res->msg_waitqueue = xbt_dynar_new(sizeof(s_gras_msg_t), NULL);
28 res->cbl_list = xbt_dynar_new(sizeof(gras_cblist_t *), gras_cbl_free);
29 res->timers = xbt_dynar_new(sizeof(s_gras_timer_t), NULL);
30 res->msg_to_receive_queue = xbt_fifo_new();
31 res->msg_to_receive_queue_meas = xbt_fifo_new();
32 res->msg_received = xbt_queue_new(0, sizeof(s_gras_msg_t));
38 * Freeing procdata for this module
40 static void gras_msg_procdata_free(void *data)
42 gras_msg_procdata_t res = (gras_msg_procdata_t) data;
44 xbt_dynar_free(&(res->msg_queue));
45 xbt_dynar_free(&(res->msg_waitqueue));
46 xbt_dynar_free(&(res->cbl_list));
47 xbt_dynar_free(&(res->timers));
48 xbt_fifo_free(res->msg_to_receive_queue);
49 xbt_fifo_free(res->msg_to_receive_queue_meas);
58 int gras_msg_libdata_id;
59 void gras_msg_register()
62 gras_procdata_add("gras_msg", gras_msg_procdata_new,
63 gras_msg_procdata_free);
67 * Initialize this submodule.
69 void gras_msg_init(void)
71 /* only initialize once */
72 if (_gras_msgtype_set != NULL)
75 XBT_VERB("Initializing Msg");
77 _gras_msgtype_set = xbt_set_new();
79 memcpy(_GRAS_header, "GRAS", 4);
80 _GRAS_header[4] = GRAS_PROTOCOL_VERSION;
81 _GRAS_header[5] = (char) GRAS_THISARCH;
83 gras_msg_ctx_mallocator =
84 xbt_mallocator_new(1000,
85 gras_msg_ctx_mallocator_new_f,
86 gras_msg_ctx_mallocator_free_f,
87 gras_msg_ctx_mallocator_reset_f);
91 * Finalize the msg module
93 void gras_msg_exit(void)
95 XBT_VERB("Exiting Msg");
96 xbt_set_free(&_gras_msgtype_set);
98 xbt_mallocator_free(gras_msg_ctx_mallocator);