SST/macro
key.h
Go to the documentation of this file.
1 /*
2  * This file is part of SST/macroscale:
3  * The macroscale architecture simulator from the SST suite.
4  * Copyright (c) 2009 Sandia Corporation.
5  * This software is distributed under the BSD License.
6  * Under the terms of Contract DE-AC04-94AL85000 with Sandia Corporation,
7  * the U.S. Government retains certain rights in this software.
8  * For more information, see the LICENSE file in the top
9  * SST/macroscale directory.
10  */
11 
12 #ifndef SSTMAC_SOFTWARE_PROCESS_KEY_H_INCLUDED
13 #define SSTMAC_SOFTWARE_PROCESS_KEY_H_INCLUDED
14 
17 #include <sprockit/unordered.h>
18 #include <stdint.h>
19 
20 #include <cstring>
21 #include <set>
22 
23 namespace sstmac {
24 namespace sw {
25 
26 /**
27  * A base type and default (empty) implementation of a handle
28  * to block and unblock processes.
29  */
30 class key {
31 
32  /**
33  Global identifier for all keys of a given type.
34  This should be a STATIC object that gets passed
35  into every key when selecting type.
36  */
37  public:
38  typedef std::set<thread_data_t> blocking_t;
39 
40  class category
41  {
42  private:
43  friend class library;
44 
45  int id_;
46 
47  //only callable by library
48  category();
49 
50  public:
51  category(const std::string& name);
52 
53 
54  std::string
55  name() const {
56  return key::name(id_);
57  }
58 
59  int id() const {
60  return id_;
61  }
62  };
63 
64 
65  public:
66  static category general;
67 
68  public:
69  virtual std::string
70  to_string() const {
71  return "key";
72  }
73 
74  static key*
75  construct();
76 
77  static key*
78  construct(const category& name);
79 
80  static std::string
81  name(int keyname_id) {
82  return (*category_id_to_name_)[keyname_id];
83  }
84 
85  static int
86  allocate_category_id(const std::string& name);
87 
88  static int
89  event_typeid(const std::string& event_name);
90 
91  static int
93  return category_name_to_id_->size();
94  }
95 
96  std::string
97  name() const {
98  return name(keyname_id_);
99  }
100 
101  int
102  event_typeid() const {
103  return keyname_id_;
104  }
105 
106  virtual ~key();
107 
108  void*
109  operator new(size_t size);
110 
111  void
112  operator delete(void* ptr);
113 
114  void
116  blocked_thread_ = t;
117  }
118 
119  bool
121  return blocked_thread_.second;
122  }
123 
124  bool
125  timed_out() const {
126  return timed_out_;
127  }
128 
129  void
131  timed_out_ = true;
132  }
133 
134  void
135  clear() {
136  blocked_thread_.first = 0;
137  blocked_thread_.second = 0;
138  }
139 
140  static void
141  delete_statics();
142 
143  private:
144  friend class operating_system;
145 
146  key();
147 
148  key(const category& name);
149 
150  private:
151  static spkt_unordered_map<std::string, int>* category_name_to_id_;
152  static spkt_unordered_map<int, std::string>* category_id_to_name_;
153  static uint64_t key_storage_size_;
154 
158 
159 };
160 
161 }
162 } // end of namespace sstmac
163 
164 #endif
165 
static spkt_unordered_map< int, std::string > * category_id_to_name_
Definition: key.h:152
std::set< thread_data_t > blocking_t
Global identifier for all keys of a given type.
Definition: key.h:38
std::string name() const
Definition: key.h:97
static void delete_statics()
int keyname_id_
Definition: key.h:157
static uint64_t key_storage_size_
Definition: key.h:153
static std::string name(int keyname_id)
Definition: key.h:81
void block_thread(thread_data_t t)
Definition: key.h:115
static spkt_unordered_map< std::string, int > * category_name_to_id_
Definition: key.h:151
thread_data_t blocked_thread_
Definition: key.h:155
int event_typeid() const
Definition: key.h:102
virtual ~key()
static category general
Definition: key.h:66
static int num_categories()
Definition: key.h:92
static key * construct()
SUMI = Simulator unified messagine interface It is also the name for a solid ink in Japanese - i...
A base type and default (empty) implementation of a handle to block and unblock processes.
Definition: key.h:30
virtual std::string to_string() const
Definition: key.h:70
int id() const
Definition: key.h:59
bool timed_out() const
Definition: key.h:125
static int allocate_category_id(const std::string &name)
std::string name() const
Definition: key.h:55
std::pair< threading_interface *, thread * > thread_data_t
Definition: thread_data.h:14
bool timed_out_
Definition: key.h:156
void set_timed_out()
Definition: key.h:130
void clear()
Definition: key.h:135
bool still_blocked()
Definition: key.h:120