Move threading calls into a basic user space library.
This commit is contained in:
parent
b0c2a6732b
commit
174d4b10fb
9 changed files with 67 additions and 21 deletions
16
lib/mammoth/CMakeLists.txt
Normal file
16
lib/mammoth/CMakeLists.txt
Normal file
|
|
@ -0,0 +1,16 @@
|
|||
add_library(mammoth_lib STATIC
|
||||
src/debug.cpp
|
||||
src/thread.cpp
|
||||
)
|
||||
|
||||
target_include_directories(mammoth_lib
|
||||
PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}
|
||||
PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}/include)
|
||||
|
||||
target_link_libraries(mammoth_lib
|
||||
zion_lib)
|
||||
|
||||
set(_COMPILE_FLAGS "${CMAKE_CXX_FLAGS} -c -ffreestanding -fno-rtti -fno-exceptions -nostdlib -mabi=sysv -mgeneral-regs-only")
|
||||
|
||||
set_target_properties(mammoth_lib PROPERTIES
|
||||
COMPILE_FLAGS "${_COMPILE_FLAGS}")
|
||||
3
lib/mammoth/include/mammoth/debug.h
Normal file
3
lib/mammoth/include/mammoth/debug.h
Normal file
|
|
@ -0,0 +1,3 @@
|
|||
#pragma once
|
||||
|
||||
void dbgln(const char*);
|
||||
13
lib/mammoth/include/mammoth/thread.h
Normal file
13
lib/mammoth/include/mammoth/thread.h
Normal file
|
|
@ -0,0 +1,13 @@
|
|||
#pragma once
|
||||
|
||||
#include <stdint.h>
|
||||
|
||||
class Thread {
|
||||
public:
|
||||
typedef void (*Entry)(void*);
|
||||
|
||||
Thread(Entry e, const void* arg1);
|
||||
|
||||
private:
|
||||
uint64_t thread_cap_;
|
||||
};
|
||||
5
lib/mammoth/src/debug.cpp
Normal file
5
lib/mammoth/src/debug.cpp
Normal file
|
|
@ -0,0 +1,5 @@
|
|||
#include "include/mammoth/debug.h"
|
||||
|
||||
#include "zcall.h"
|
||||
|
||||
void dbgln(const char* str) { ZDebug(str); }
|
||||
19
lib/mammoth/src/thread.cpp
Normal file
19
lib/mammoth/src/thread.cpp
Normal file
|
|
@ -0,0 +1,19 @@
|
|||
#include "include/mammoth/thread.h"
|
||||
|
||||
#include "zcall.h"
|
||||
|
||||
namespace {
|
||||
|
||||
extern "C" void thread_entry(Thread::Entry entry, void* arg1) {
|
||||
entry(arg1);
|
||||
|
||||
ZThreadExit();
|
||||
}
|
||||
|
||||
} // namespace
|
||||
|
||||
Thread::Thread(Entry e, const void* arg1) {
|
||||
ZThreadCreate(Z_INIT_PROC_SELF, &thread_cap_);
|
||||
ZThreadStart(thread_cap_, reinterpret_cast<uint64_t>(thread_entry),
|
||||
reinterpret_cast<uint64_t>(e), reinterpret_cast<uint64_t>(arg1));
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue