21
21
#include < stdio.h>
22
22
#include < signal.h>
23
23
24
+
25
+
24
26
static alaska::Runtime *the_runtime = nullptr ;
25
27
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
+
26
37
extern " C" void alaska_dump (void ) { the_runtime->dump (stderr); }
27
38
28
39
29
40
static pthread_t barrier_thread;
30
41
static void *barrier_thread_func (void *) {
31
-
32
42
// while (1) {
33
43
// usleep(250 * 1000);
34
44
// alaska::barrier::begin();
@@ -40,17 +50,17 @@ static void *barrier_thread_func(void *) {
40
50
}
41
51
42
52
void __attribute__ ((constructor(102 ))) alaska_init(void ) {
43
-
44
53
alaska::barrier::add_self_thread ();
45
54
// Allocate the runtime simply by creating a new instance of it. Everywhere
46
55
// we use it, we will use alaska::Runtime::get() to get the singleton instance.
47
56
the_runtime = new alaska::Runtime ();
57
+ // Attach the runtime's barrier manager
58
+ the_runtime->barrier_manager = &the_barrier_manager;
48
59
49
60
pthread_create (&barrier_thread, NULL , barrier_thread_func, NULL );
50
61
}
51
62
52
63
void __attribute__ ((destructor)) alaska_deinit(void ) {
53
-
54
64
pthread_kill (barrier_thread, SIGKILL);
55
65
pthread_join (barrier_thread, NULL );
56
66
0 commit comments