Skip to content

Commit 6d5e980

Browse files
committed
runtime: adjust some things to compile w/ barriers easier
1 parent e44409c commit 6d5e980

File tree

8 files changed

+46
-27
lines changed

8 files changed

+46
-27
lines changed

CMakeLists.txt

+20-6
Original file line numberDiff line numberDiff line change
@@ -26,12 +26,19 @@ function(alaska_option OPT DEFAULT)
2626
message(STATUS "${Purple}OPTION${ColorReset} ${OPT} ${Green}${${OPT}}${ColorReset}")
2727
endfunction()
2828

29+
function(alaska_option_nodef OPT DEFAULT)
30+
set(${OPT} ${DEFAULT} CACHE STRING "")
31+
message(STATUS "${Purple}OPTION${ColorReset} ${OPT} ${Green}${${OPT}}${ColorReset}")
32+
endfunction()
33+
2934

3035
alaska_switch(ALASKA_ENABLE_COMPILER ON)
3136
alaska_switch(ALASKA_ENABLE_TESTING ON)
37+
alaska_switch(ALASKA_CORE_ONLY OFF)
3238

3339
alaska_option(ALASKA_SIZE_BITS 24)
3440
alaska_option(CMAKE_BUILD_TYPE Release)
41+
alaska_option_nodef(ALASKA_ENABLE_COMPONENTS "compiler;compiler-rts")
3542

3643
set(ALASKA_VERSION 2)
3744

@@ -46,6 +53,19 @@ if(CMAKE_BUILD_TYPE STREQUAL "Debug")
4653
endif()
4754

4855

56+
57+
list(FIND ALASKA_ENABLE_COMPONENTS "compiler" INDEX)
58+
if (NOT INDEX EQUAL -1)
59+
message(STATUS "compiler")
60+
endif()
61+
62+
63+
list(FIND ALASKA_ENABLE_COMPONENTS "compiler-rts" INDEX)
64+
if (NOT INDEX EQUAL -1)
65+
message(STATUS "compiler-rts")
66+
endif()
67+
68+
4969
# -------------------------------------------------------------------------------------------
5070

5171
cmake_minimum_required(VERSION 3.13)
@@ -59,12 +79,6 @@ else()
5979
set(ALASKA_ENABLE_COMPILER FALSE)
6080
endif()
6181

62-
63-
# If we are building the core only, don't enable the compiler!
64-
if(ALASKA_CORE_ONLY)
65-
set(ALASKA_ENABLE_COMPILER FALSE)
66-
endif()
67-
6882
add_compile_definitions("ALASKA_INSTALL_PREFIX=\"${CMAKE_INSTALL_PREFIX}\"")
6983
add_definitions(-include "${CMAKE_CURRENT_SOURCE_DIR}/runtime/include/alaska/config.h")
7084

Makefile

+5-1
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ sanity: alaska
3333
test: alaska
3434
@build/runtime/alaska_test
3535

36-
.PHONY: alaska all
36+
.PHONY: alaska all
3737

3838
# Run compilation unit tests to validate that the compiler can
3939
# handle all the funky control flow in the GCC test suite
@@ -49,6 +49,10 @@ clean:
4949
[ -d $(BUILD) ] && make -C $(BUILD) clean
5050
rm -f .*.o*
5151

52+
mrproper:
53+
rm -rf $(BUILD) .*.o*
54+
55+
5256
docker:
5357
docker build -t alaska .
5458
docker run -it --rm alaska bash

runtime/CMakeLists.txt

+4-4
Original file line numberDiff line numberDiff line change
@@ -66,16 +66,14 @@ set(CORE_SOURCES
6666
)
6767

6868

69-
find_library(LIBUNWIND_LIBRARIES NAMES unwind )
70-
message(STATUS "UNWIND: ${LIBUNWIND_LIBRARIES}")
7169

72-
add_library(alaska_core STATIC ${CORE_SOURCES})
70+
add_library(alaska_core SHARED ${CORE_SOURCES})
7371

7472
target_compile_options(alaska_core PRIVATE $<$<COMPILE_LANGUAGE:CXX>:-nostdlib++ -nostdinc++>)
7573

7674
set_target_properties(alaska_core PROPERTIES LINKER_LANGUAGE C)
7775
set_target_properties(alaska_core PROPERTIES SOVERSION ${ALASKA_VERSION})
78-
target_link_libraries(alaska_core ${LIBUNWIND_LIBRARIES})
76+
# target_link_libraries(alaska_core ${LIBUNWIND_LIBRARIES})
7977

8078
set_property(TARGET alaska_core PROPERTY POSITION_INDEPENDENT_CODE ON)
8179
target_link_libraries(alaska_core dl pthread)
@@ -99,6 +97,8 @@ install(
9997
# This defines the runtime that compiled code is linked against
10098
if(NOT ALASKA_CORE_ONLY) # -----------------------------------------------------------------------------------
10199

100+
find_library(LIBUNWIND_LIBRARIES NAMES unwind )
101+
message(STATUS "UNWIND: ${LIBUNWIND_LIBRARIES}")
102102

103103
add_library(alaska SHARED
104104
rt/init.cpp

runtime/core/HandleTable.cpp

+3
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,9 @@
88
* This is free software. You are permitted to use, redistribute,
99
* and modify it as specified in the file "LICENSE".
1010
*/
11+
#ifndef _GNU_SOURCE
12+
#define _GNU_SOURCE
13+
#endif
1114

1215

1316
#include <alaska/HandleTable.hpp>

runtime/core/Runtime.cpp

+6-10
Original file line numberDiff line numberDiff line change
@@ -17,21 +17,16 @@
1717
#include <stdlib.h>
1818

1919
namespace alaska {
20-
21-
22-
struct NopBarrierManager final : public alaska::BarrierManager {
23-
~NopBarrierManager() override = default;
24-
void begin(void) override {}
25-
void end(void) override {}
26-
};
27-
28-
static NopBarrierManager global_nop_barrier_manager;
29-
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
3023
static Runtime *g_runtime = nullptr;
3124

3225

3326
Runtime::Runtime() {
27+
// Validate that there is not already a runtime (TODO: atomics?)
3428
ALASKA_ASSERT(g_runtime == nullptr, "Cannot create more than one runtime");
29+
// Assign the global runtime to be this instance
3530
g_runtime = this;
3631
// Attach a default barrier manager
3732
this->barrier_manager = &global_nop_barrier_manager;
@@ -41,6 +36,7 @@ namespace alaska {
4136

4237
Runtime::~Runtime() {
4338
log_debug("Destroying Alaska Runtime");
39+
// Unset the global instance so another runtime can be allocated
4440
g_runtime = nullptr;
4541
}
4642

runtime/include/alaska/BarrierManager.hpp

+6-5
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
#pragma once
22

3+
#include <alaska/alaska.hpp>
34

45

56
namespace alaska {
@@ -16,12 +17,12 @@ namespace alaska {
1617
// The only requirement of this class is that when `::begin()` returns, all pinned handles must
1718
// be marked as such, and when `::end()` returns they should be released. The core runtime relies
1819
// on this to be the case for safe operation. If the user of the core runtime does not need to
19-
// pin any handles, the barrier does not need to do anything.
20-
struct BarrierManager {
20+
// pin any handles, the barrier does not need to do anything.
21+
struct BarrierManager : public alaska::InternalHeapAllocated {
2122
virtual ~BarrierManager() = default;
22-
virtual void begin(void) = 0;
23-
virtual void end(void) = 0;
23+
virtual void begin(void){};
24+
virtual void end(void){};
2425

2526
unsigned long barrier_count = 0;
2627
};
27-
}
28+
} // namespace alaska

runtime/include/alaska/alaska.hpp

+1
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
#include <stdio.h>
1515
#include <stdlib.h>
1616
#include <stdint.h>
17+
#include <sys/types.h>
1718
#include <alaska/utils.h>
1819
#include <alaska/list_head.h>
1920
#include <alaska/liballoc.h>

runtime/rt/init.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626
static alaska::Runtime *the_runtime = nullptr;
2727

2828

29-
struct CompilerRuntimeBarrierManager final : public alaska::BarrierManager {
29+
struct CompilerRuntimeBarrierManager : public alaska::BarrierManager {
3030
~CompilerRuntimeBarrierManager() override = default;
3131
void begin(void) override { alaska::barrier::begin(); }
3232
void end(void) override { alaska::barrier::end(); }

0 commit comments

Comments
 (0)