Move threading calls into a basic user space library.
This commit is contained in:
parent
b0c2a6732b
commit
174d4b10fb
|
@ -10,6 +10,7 @@ set(CMAKE_CXX_STANDARD_REQUIRED True)
|
|||
set(CMAKE_EXPORT_COMPILE_COMMANDS True)
|
||||
|
||||
add_subdirectory(zion)
|
||||
add_subdirectory(lib)
|
||||
add_subdirectory(sys)
|
||||
|
||||
set(QEMU_CMD qemu-system-x86_64 -d guest_errors -m 1G -serial stdio -hda disk.img)
|
||||
|
|
|
@ -0,0 +1 @@
|
|||
add_subdirectory(mammoth)
|
|
@ -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}")
|
|
@ -0,0 +1,3 @@
|
|||
#pragma once
|
||||
|
||||
void dbgln(const char*);
|
|
@ -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_;
|
||||
};
|
|
@ -0,0 +1,5 @@
|
|||
#include "include/mammoth/debug.h"
|
||||
|
||||
#include "zcall.h"
|
||||
|
||||
void dbgln(const char* str) { ZDebug(str); }
|
|
@ -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));
|
||||
}
|
|
@ -20,7 +20,7 @@ add_executable(test2
|
|||
test2.cpp)
|
||||
|
||||
target_link_libraries(test2
|
||||
zion_lib)
|
||||
mammoth_lib)
|
||||
|
||||
set_target_properties(test2
|
||||
PROPERTIES
|
||||
|
|
|
@ -1,7 +1,5 @@
|
|||
|
||||
|
||||
#include "zcall.h"
|
||||
#include "zerrors.h"
|
||||
#include "mammoth/debug.h"
|
||||
#include "mammoth/thread.h"
|
||||
|
||||
#define CHECK(expr) \
|
||||
{ \
|
||||
|
@ -12,29 +10,19 @@
|
|||
} \
|
||||
}
|
||||
|
||||
void thread_entry(char* a, char* b) {
|
||||
ZDebug("In thread");
|
||||
ZDebug(a);
|
||||
ZDebug(b);
|
||||
|
||||
ZThreadExit();
|
||||
void thread_entry(void* a) {
|
||||
dbgln("In thread");
|
||||
dbgln(static_cast<const char*>(a));
|
||||
}
|
||||
|
||||
int main() {
|
||||
ZDebug("Testing");
|
||||
uint64_t t1, t2;
|
||||
CHECK(ZThreadCreate(Z_INIT_PROC_SELF, &t1));
|
||||
CHECK(ZThreadCreate(Z_INIT_PROC_SELF, &t2));
|
||||
dbgln("Main thread");
|
||||
|
||||
const char* a = "a";
|
||||
const char* b = "bee";
|
||||
const char* c = "cee";
|
||||
const char* d = "dee";
|
||||
CHECK(ZThreadStart(t1, reinterpret_cast<uint64_t>(thread_entry),
|
||||
reinterpret_cast<uint64_t>(a),
|
||||
reinterpret_cast<uint64_t>(b)));
|
||||
CHECK(ZThreadStart(t2, reinterpret_cast<uint64_t>(thread_entry),
|
||||
reinterpret_cast<uint64_t>(c),
|
||||
reinterpret_cast<uint64_t>(d)));
|
||||
Thread t1(thread_entry, a);
|
||||
Thread t2(thread_entry, b);
|
||||
return 0;
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue