Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
[mc] C++ class ModelChecker
[simgrid.git] / src / mc / ModelChecker.cpp
1 /* Copyright (c) 2008-2014. 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 <cassert>
8
9 #include "ModelChecker.hpp"
10 #include "mc_page_store.h"
11
12 ::simgrid::mc::ModelChecker* mc_model_checker = NULL;
13
14 namespace simgrid {
15 namespace mc {
16
17 ModelChecker::ModelChecker(pid_t pid, int socket)
18 {
19   this->page_store_ = mc_pages_store_new();
20   this->fd_clear_refs_ = -1;
21   this->hostnames_ = xbt_dict_new();
22   MC_process_init(&this->process(), pid, socket);
23 }
24
25 ModelChecker::~ModelChecker()
26 {
27   mc_pages_store_delete(this->page_store_);
28   if(this->record_)
29     xbt_dynar_free(&this->record_);
30   MC_process_clear(&this->process_);
31   xbt_dict_free(&this->hostnames_);
32 }
33
34 const char* ModelChecker::get_host_name(const char* hostname)
35 {
36   // Lookup the host name in the dictionary (or create it):
37   xbt_dictelm_t elt = xbt_dict_get_elm_or_null(this->hostnames_, hostname);
38   if (!elt) {
39     xbt_mheap_t heap = mmalloc_set_current_heap(mc_heap);
40     xbt_dict_set(this->hostnames_, hostname, NULL, NULL);
41     elt = xbt_dict_get_elm_or_null(this->hostnames_, hostname);
42     assert(elt);
43     mmalloc_set_current_heap(heap);
44   }
45   return elt->key;
46 }
47
48 }
49 }