diff --git a/System Abstraction/linux/cdb_thread.c b/System Abstraction/linux/cdb_thread.c new file mode 100644 index 0000000..aeed41f --- /dev/null +++ b/System Abstraction/linux/cdb_thread.c @@ -0,0 +1,38 @@ +#include "../cdb_sustem.h" +#include +#include + +struct sus_thread_args { + sus_threadProc proc; + void *arg; +}; + +typedef struct sus_thread_args sus_thread_args; + +// Linux only uses System V AMD64 ABI calling convention (source: https://en.wikipedia.org/wiki/X86_calling_conventions) +void *uwu_runThread(void *arg) { + sus_thread_args *args = (sus_thread_args *) arg; + sus_threadProc proc = args->proc; + void *arg2 = args->arg; + sus_heapFree(args); + proc(arg2); + return NULL; +} + +sus_Bool sus_threadNew(sus_threadProc proc, void *arg) { + sus_thread_args *args = (sus_thread_args *) sus_heapAlloc(sizeof(sus_thread_args)); + args->proc = proc; + args->arg = arg; + + pthread_t thread; + if(pthread_create(&thread, NULL, uwu_runThread, args)) { + sus_heapFree(args); + return sus_False; + }else { + return sus_True; + } +} + +void sus_threadSleep(unsigned long seconds) { + sleep(seconds); +} \ No newline at end of file diff --git a/tests/System Abstraction/5/.gitignore b/tests/System Abstraction/5/.gitignore new file mode 100644 index 0000000..f5bdd21 --- /dev/null +++ b/tests/System Abstraction/5/.gitignore @@ -0,0 +1 @@ +run diff --git a/tests/System Abstraction/5/compile.sh b/tests/System Abstraction/5/compile.sh new file mode 100755 index 0000000..08de3a7 --- /dev/null +++ b/tests/System Abstraction/5/compile.sh @@ -0,0 +1,5 @@ +#!/bin/sh +if [ ! -d run ]; then + mkdir run +fi +gcc -g threadsTest.c "../../../System Abstraction/linux/cdb_file.c" "../../../System Abstraction/linux/cdb_memroy.c" "../../../System Abstraction/linux/cdb_thread.c" -o run/threadsTest \ No newline at end of file diff --git a/tests/System Abstraction/5/run.sh b/tests/System Abstraction/5/run.sh new file mode 100755 index 0000000..5fb3bd0 --- /dev/null +++ b/tests/System Abstraction/5/run.sh @@ -0,0 +1,10 @@ +#!/bin/sh + +./compile.sh +cd run + +# Test 1 +echo "-- Test 1" +./threadsTest + +cd .. \ No newline at end of file