12
12
13
13
#include < alaska/Runtime.hpp>
14
14
#include < alaska/SizeClass.hpp>
15
+ #include < alaska/BarrierManager.hpp>
15
16
#include " alaska/alaska.hpp"
16
17
#include < stdlib.h>
17
18
18
19
namespace alaska {
20
+ // The default instance of a barrier manager.
21
+ static BarrierManager global_nop_barrier_manager;
22
+ // The current global instance of the runtime, since we can only have one at a time
19
23
static Runtime *g_runtime = nullptr ;
20
24
21
25
22
26
Runtime::Runtime () {
27
+ // Validate that there is not already a runtime (TODO: atomics?)
23
28
ALASKA_ASSERT (g_runtime == nullptr , " Cannot create more than one runtime" );
29
+ // Assign the global runtime to be this instance
24
30
g_runtime = this ;
31
+ // Attach a default barrier manager
32
+ this ->barrier_manager = &global_nop_barrier_manager;
25
33
26
34
log_debug (" Created a new Alaska Runtime @ %p" , this );
27
35
}
28
36
29
37
Runtime::~Runtime () {
30
38
log_debug (" Destroying Alaska Runtime" );
39
+ // Unset the global instance so another runtime can be allocated
31
40
g_runtime = nullptr ;
32
41
}
33
42
@@ -38,69 +47,6 @@ namespace alaska {
38
47
}
39
48
40
49
41
- // void* Runtime::halloc(size_t sz, bool zero) {
42
- // auto& rt = *this;
43
- // log_trace("halloc: allocating %lu bytes (zero=%d)", sz, zero);
44
- // // Just some big number.
45
- // if (sz > (1LLU << (uint64_t)(ALASKA_SIZE_BITS - ALASKA_SQUEEZE_BITS - 1)) - 1) {
46
- // log_debug(
47
- // "Allocation of size %zu deemed too big - using the system allocator instead...", sz);
48
- // return ::malloc(sz);
49
- // }
50
-
51
-
52
-
53
- // int sc = alaska::size_to_class(sz);
54
- // size_t rsz = alaska::class_to_size(sc);
55
- // log_trace("sz = %zu, sc = %d, rsz = %zu\n", sz, sc, rsz);
56
-
57
- // alaska::Mapping* m = rt.handle_table.get();
58
- // if (m == nullptr) {
59
- // log_fatal("halloc: out of handles");
60
- // abort();
61
- // }
62
-
63
- // void* p = rt.page.alloc(*m, sz);
64
-
65
- // if (p == nullptr) {
66
- // log_fatal("halloc: out of memory");
67
- // abort();
68
- // }
69
- // if (zero) {
70
- // memset(p, 0, sz);
71
- // }
72
-
73
- // m->set_pointer(p);
74
-
75
- // void* out = (void*)m->to_handle(0);
76
- // log_trace("halloc handle %p -> %p", out, p);
77
- // return out;
78
- // }
79
-
80
- // void Runtime::hfree(void* ptr) {
81
- // auto* m = alaska::Mapping::from_handle_safe(ptr);
82
-
83
- // log_trace("hfree: freeing %p (%p)", ptr, m->get_pointer());
84
- // this->page.release(*m, m->get_pointer());
85
- // }
86
-
87
-
88
-
89
- // void* Runtime::hrealloc(void* ptr, size_t size) {
90
- // log_trace("hrealloc(%p, %zu)", ptr, size);
91
- // if (size == 0) {
92
- // hfree(ptr);
93
- // return nullptr;
94
- // }
95
-
96
- // // TODO: Implement hrealloc function
97
- // log_fatal("hrealloc: not implemented");
98
- // abort();
99
- // return nullptr;
100
- // }
101
-
102
-
103
-
104
50
void Runtime::dump (FILE *stream) {
105
51
//
106
52
fprintf (stream, " Alaska Runtime Information:\n " );
0 commit comments