Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Fix copyright headers
[simgrid.git] / src / gras / Msg / gras_msg_mod.c
1 /* gras message types handling                                              */
2
3 /* Copyright (c) 2007, 2009, 2010. The SimGrid Team.
4  * All rights reserved.                                                     */
5
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. */
8
9 #include "xbt/ex.h"
10 #include "gras/Msg/msg_private.h"
11 #include "gras/Virtu/virtu_interface.h"
12
13 XBT_LOG_EXTERNAL_DEFAULT_CATEGORY(gras_msg);
14
15 extern xbt_set_t _gras_msgtype_set;
16
17 /*
18  * Creating procdata for this module
19  */
20 static void *gras_msg_procdata_new(void)
21 {
22   gras_msg_procdata_t res = xbt_new(s_gras_msg_procdata_t, 1);
23
24   res->name = xbt_strdup("gras_msg");
25   res->name_len = 0;
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));
33
34   return (void *) res;
35 }
36
37 /*
38  * Freeing procdata for this module
39  */
40 static void gras_msg_procdata_free(void *data)
41 {
42   gras_msg_procdata_t res = (gras_msg_procdata_t) data;
43
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);
50
51   free(res->name);
52   free(res);
53 }
54
55 /*
56  * Module registration
57  */
58 int gras_msg_libdata_id;
59 void gras_msg_register()
60 {
61   gras_msg_libdata_id =
62     gras_procdata_add("gras_msg", gras_msg_procdata_new,
63                       gras_msg_procdata_free);
64 }
65
66 /*
67  * Initialize this submodule.
68  */
69 void gras_msg_init(void)
70 {
71   /* only initialize once */
72   if (_gras_msgtype_set != NULL)
73     return;
74
75   VERB0("Initializing Msg");
76
77   _gras_msgtype_set = xbt_set_new();
78
79   memcpy(_GRAS_header, "GRAS", 4);
80   _GRAS_header[4] = GRAS_PROTOCOL_VERSION;
81   _GRAS_header[5] = (char) GRAS_THISARCH;
82
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);
88 }
89
90 /*
91  * Finalize the msg module
92  */
93 void gras_msg_exit(void)
94 {
95   VERB0("Exiting Msg");
96   xbt_set_free(&_gras_msgtype_set);
97
98   xbt_mallocator_free(gras_msg_ctx_mallocator);
99 }