|
34 | 34 |
|
35 | 35 | namespace pmt {
|
36 | 36 |
|
37 |
| -static const int CACHE_LINE_SIZE = 64; // good guess |
38 |
| - |
39 | 37 | # if (PMT_LOCAL_ALLOCATOR)
|
40 | 38 |
|
41 |
| -static pmt_pool global_pmt_pool(sizeof(pmt_pair), CACHE_LINE_SIZE); |
| 39 | +static const int |
| 40 | +get_cache_line_size() |
| 41 | +{ |
| 42 | + static const int CACHE_LINE_SIZE = 64; // good guess |
| 43 | + return CACHE_LINE_SIZE; |
| 44 | +} |
| 45 | + |
| 46 | +static pmt_pool global_pmt_pool(sizeof(pmt_pair), get_cache_line_size()); |
42 | 47 |
|
43 | 48 | void *
|
44 | 49 | pmt_base::operator new(size_t size)
|
45 | 50 | {
|
46 | 51 | void *p = global_pmt_pool.malloc();
|
47 | 52 |
|
48 | 53 | // fprintf(stderr, "pmt_base::new p = %p\n", p);
|
49 |
| - assert((reinterpret_cast<intptr_t>(p) & (CACHE_LINE_SIZE - 1)) == 0); |
| 54 | + assert((reinterpret_cast<intptr_t>(p) & (get_cache_line_size() - 1)) == 0); |
50 | 55 | return p;
|
51 | 56 | }
|
52 | 57 |
|
@@ -158,14 +163,28 @@ _any(pmt_t x)
|
158 | 163 | // Globals
|
159 | 164 | ////////////////////////////////////////////////////////////////////////////
|
160 | 165 |
|
161 |
| -const pmt_t PMT_T = pmt_t(new pmt_bool()); // singleton |
162 |
| -const pmt_t PMT_F = pmt_t(new pmt_bool()); // singleton |
163 |
| -const pmt_t PMT_EOF = cons(PMT_NIL, PMT_NIL); // singleton |
164 |
| - |
165 | 166 | pmt_t get_PMT_NIL()
|
166 | 167 | {
|
167 |
| - static pmt_t NIL = pmt_t(new pmt_null()); |
168 |
| - return NIL; |
| 168 | + static pmt_t _NIL = pmt_t(new pmt_null()); |
| 169 | + return _NIL; |
| 170 | +} |
| 171 | + |
| 172 | +pmt_t get_PMT_T() |
| 173 | +{ |
| 174 | + static const pmt_t _T = pmt_t(new pmt_bool()); |
| 175 | + return _T; |
| 176 | +} |
| 177 | + |
| 178 | +pmt_t get_PMT_F() |
| 179 | +{ |
| 180 | + static const pmt_t _F = pmt_t(new pmt_bool()); |
| 181 | + return _F; |
| 182 | +} |
| 183 | + |
| 184 | +pmt_t get_PMT_EOF() |
| 185 | +{ |
| 186 | + static const pmt_t _EOF = cons(get_PMT_NIL(), get_PMT_NIL()); |
| 187 | + return _EOF; |
169 | 188 | }
|
170 | 189 |
|
171 | 190 | ////////////////////////////////////////////////////////////////////////////
|
@@ -212,8 +231,19 @@ to_bool(pmt_t val)
|
212 | 231 | // Symbols
|
213 | 232 | ////////////////////////////////////////////////////////////////////////////
|
214 | 233 |
|
215 |
| -static const unsigned int SYMBOL_HASH_TABLE_SIZE = 701; |
216 |
| -static std::vector<pmt_t> s_symbol_hash_table(SYMBOL_HASH_TABLE_SIZE); |
| 234 | +static const unsigned int |
| 235 | +get_symbol_hash_table_size() |
| 236 | +{ |
| 237 | + static const unsigned int SYMBOL_HASH_TABLE_SIZE = 701; |
| 238 | + return SYMBOL_HASH_TABLE_SIZE; |
| 239 | +} |
| 240 | + |
| 241 | +static std::vector<pmt_t>* |
| 242 | +get_symbol_hash_table() |
| 243 | +{ |
| 244 | + static std::vector<pmt_t> s_symbol_hash_table(get_symbol_hash_table_size()); |
| 245 | + return &s_symbol_hash_table; |
| 246 | +} |
217 | 247 |
|
218 | 248 | pmt_symbol::pmt_symbol(const std::string &name) : d_name(name){}
|
219 | 249 |
|
@@ -244,18 +274,18 @@ is_symbol(const pmt_t& obj)
|
244 | 274 | pmt_t
|
245 | 275 | string_to_symbol(const std::string &name)
|
246 | 276 | {
|
247 |
| - unsigned hash = hash_string(name) % SYMBOL_HASH_TABLE_SIZE; |
| 277 | + unsigned hash = hash_string(name) % get_symbol_hash_table_size(); |
248 | 278 |
|
249 | 279 | // Does a symbol with this name already exist?
|
250 |
| - for (pmt_t sym = s_symbol_hash_table[hash]; sym; sym = _symbol(sym)->next()){ |
| 280 | + for (pmt_t sym = (*get_symbol_hash_table())[hash]; sym; sym = _symbol(sym)->next()){ |
251 | 281 | if (name == _symbol(sym)->name())
|
252 | 282 | return sym; // Yes. Return it
|
253 | 283 | }
|
254 | 284 |
|
255 | 285 | // Nope. Make a new one.
|
256 | 286 | pmt_t sym = pmt_t(new pmt_symbol(name));
|
257 |
| - _symbol(sym)->set_next(s_symbol_hash_table[hash]); |
258 |
| - s_symbol_hash_table[hash] = sym; |
| 287 | + _symbol(sym)->set_next((*get_symbol_hash_table())[hash]); |
| 288 | + (*get_symbol_hash_table())[hash] = sym; |
259 | 289 | return sym;
|
260 | 290 | }
|
261 | 291 |
|
|
0 commit comments