Skip to content

Commit b9d1298

Browse files
committed
runtime: attach the rt/barrier-manager to the runtime
1 parent 645f67a commit b9d1298

File tree

2 files changed

+14
-3
lines changed

2 files changed

+14
-3
lines changed

runtime/core/Runtime.cpp

+1
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ namespace alaska {
3333
Runtime::Runtime() {
3434
ALASKA_ASSERT(g_runtime == nullptr, "Cannot create more than one runtime");
3535
g_runtime = this;
36+
// Attach a default barrier manager
3637
this->barrier_manager = &global_nop_barrier_manager;
3738

3839
log_debug("Created a new Alaska Runtime @ %p", this);

runtime/rt/init.cpp

+13-3
Original file line numberDiff line numberDiff line change
@@ -21,14 +21,24 @@
2121
#include <stdio.h>
2222
#include <signal.h>
2323

24+
25+
2426
static alaska::Runtime *the_runtime = nullptr;
2527

28+
29+
struct CompilerRuntimeBarrierManager final : public alaska::BarrierManager {
30+
~CompilerRuntimeBarrierManager() override = default;
31+
void begin(void) override { alaska::barrier::begin(); }
32+
void end(void) override { alaska::barrier::end(); }
33+
};
34+
35+
static CompilerRuntimeBarrierManager the_barrier_manager;
36+
2637
extern "C" void alaska_dump(void) { the_runtime->dump(stderr); }
2738

2839

2940
static pthread_t barrier_thread;
3041
static void *barrier_thread_func(void *) {
31-
3242
// while (1) {
3343
// usleep(250 * 1000);
3444
// alaska::barrier::begin();
@@ -40,17 +50,17 @@ static void *barrier_thread_func(void *) {
4050
}
4151

4252
void __attribute__((constructor(102))) alaska_init(void) {
43-
4453
alaska::barrier::add_self_thread();
4554
// Allocate the runtime simply by creating a new instance of it. Everywhere
4655
// we use it, we will use alaska::Runtime::get() to get the singleton instance.
4756
the_runtime = new alaska::Runtime();
57+
// Attach the runtime's barrier manager
58+
the_runtime->barrier_manager = &the_barrier_manager;
4859

4960
pthread_create(&barrier_thread, NULL, barrier_thread_func, NULL);
5061
}
5162

5263
void __attribute__((destructor)) alaska_deinit(void) {
53-
5464
pthread_kill(barrier_thread, SIGKILL);
5565
pthread_join(barrier_thread, NULL);
5666

0 commit comments

Comments
 (0)