Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
d813e7364b1119d4002e5e543eaaee4127b3987e
[simgrid.git] / src / mc / mcer_ignore.cpp
1 /* Copyright (c) 2008-2015. The SimGrid Team.
2  * All rights reserved.                                                     */
3
4 /* This program is free software; you can redistribute it and/or modify it
5  * under the terms of the license (GNU LGPL) which comes with this package. */
6
7 #include "internal_config.h"
8 #include "mc_object_info.h"
9 #include "mc/mc_private.h"
10 #include "smpi/private.h"
11 #include "mc/mc_snapshot.h"
12 #include "mc/mc_ignore.h"
13 #include "mc/mc_protocol.h"
14 #include "mc/mc_client.h"
15
16 extern "C" {
17
18 XBT_LOG_NEW_DEFAULT_SUBCATEGORY(mcer_ignore, mc,
19                                 "Logging specific to MC ignore mechanism");
20
21 extern xbt_dynar_t mc_heap_comparison_ignore;
22
23 void MC_heap_region_ignore_insert(mc_heap_ignore_region_t region)
24 {
25   if (mc_heap_comparison_ignore == NULL) {
26     mc_heap_comparison_ignore =
27         xbt_dynar_new(sizeof(mc_heap_ignore_region_t),
28                       heap_ignore_region_free_voidp);
29     xbt_dynar_push(mc_heap_comparison_ignore, &region);
30     return;
31   }
32
33   unsigned int cursor = 0;
34   mc_heap_ignore_region_t current_region = NULL;
35   int start = 0;
36   int end = xbt_dynar_length(mc_heap_comparison_ignore) - 1;
37
38   // Find the position where we want to insert the mc_heap_ignore_region_t:
39   while (start <= end) {
40     cursor = (start + end) / 2;
41     current_region =
42         (mc_heap_ignore_region_t) xbt_dynar_get_as(mc_heap_comparison_ignore,
43                                                    cursor,
44                                                    mc_heap_ignore_region_t);
45     if (current_region->address == region->address) {
46       heap_ignore_region_free(region);
47       return;
48     } else if (current_region->address < region->address) {
49       start = cursor + 1;
50     } else {
51       end = cursor - 1;
52     }
53   }
54
55   // Insert it mc_heap_ignore_region_t:
56   if (current_region->address < region->address)
57     xbt_dynar_insert_at(mc_heap_comparison_ignore, cursor + 1, &region);
58   else
59     xbt_dynar_insert_at(mc_heap_comparison_ignore, cursor, &region);
60 }
61
62 void MC_heap_region_ignore_remove(void *address, size_t size)
63 {
64   unsigned int cursor = 0;
65   int start = 0;
66   int end = xbt_dynar_length(mc_heap_comparison_ignore) - 1;
67   mc_heap_ignore_region_t region;
68   int ignore_found = 0;
69
70   while (start <= end) {
71     cursor = (start + end) / 2;
72     region =
73         (mc_heap_ignore_region_t) xbt_dynar_get_as(mc_heap_comparison_ignore,
74                                                    cursor,
75                                                    mc_heap_ignore_region_t);
76     if (region->address == address) {
77       ignore_found = 1;
78       break;
79     } else if (region->address < address) {
80       start = cursor + 1;
81     } else {
82       if ((char *) region->address <= ((char *) address + size)) {
83         ignore_found = 1;
84         break;
85       } else {
86         end = cursor - 1;
87       }
88     }
89   }
90
91   if (ignore_found == 1) {
92     xbt_dynar_remove_at(mc_heap_comparison_ignore, cursor, NULL);
93     MC_remove_ignore_heap(address, size);
94   }
95 }
96
97 }