Compare commits
10 Commits
a77346cc5a
...
c863bab412
Author | SHA1 | Date | |
---|---|---|---|
c863bab412 | |||
0e8c09daed | |||
d89e14153e | |||
![]() |
1469de4156 | ||
6d416a117d | |||
![]() |
4aaba4edff | ||
![]() |
2b236c9659 | ||
![]() |
9f0f4aa085 | ||
6eca5c2af5 | |||
![]() |
cc070b0598 |
@ -41,6 +41,6 @@ void sus_heapFree(void * memroy); // what should this function do, if an error o
|
||||
// Networking API -- coming soon, cuz idk
|
||||
|
||||
//Threads
|
||||
typedef __attribute__ ((sysv_abi)) int (*sus_threadProc)(void * arg);
|
||||
typedef __attribute__ ((sysv_abi)) void (*sus_threadProc)(void * arg);
|
||||
sus_Bool sus_threadNew(sus_threadProc proc, void * arg);
|
||||
void sus_threadSleep(unsigned long seconds);
|
38
System Abstraction/linux/cdb_thread.c
Normal file
38
System Abstraction/linux/cdb_thread.c
Normal file
@ -0,0 +1,38 @@
|
||||
#include "../cdb_sustem.h"
|
||||
#include <pthread.h>
|
||||
#include <unistd.h>
|
||||
|
||||
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);
|
||||
}
|
@ -10,7 +10,8 @@ DWORD WINAPI threadProc(void * tiarg){
|
||||
struct threadInfo * ti = tiarg;
|
||||
struct threadInfo currentTI = {.args = ti->args, .proc = ti->proc};
|
||||
sus_heapFree(ti);
|
||||
return currentTI.proc(currentTI.args);
|
||||
currentTI.proc(currentTI.args);
|
||||
return 0;
|
||||
}
|
||||
|
||||
sus_Bool sus_threadNew(sus_threadProc proc, void * arg){
|
||||
@ -18,6 +19,7 @@ sus_Bool sus_threadNew(sus_threadProc proc, void * arg){
|
||||
ti->proc = proc;
|
||||
ti->args = arg;
|
||||
if(CreateThread(NULL, 0, threadProc, ti, 0, NULL) == NULL){
|
||||
sus_heapFree(ti);
|
||||
return sus_False;
|
||||
}else{
|
||||
return sus_True;
|
||||
|
1
tests/System Abstraction/5/.gitignore
vendored
Normal file
1
tests/System Abstraction/5/.gitignore
vendored
Normal file
@ -0,0 +1 @@
|
||||
run
|
5
tests/System Abstraction/5/compile.sh
Executable file
5
tests/System Abstraction/5/compile.sh
Executable file
@ -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
|
10
tests/System Abstraction/5/run.sh
Executable file
10
tests/System Abstraction/5/run.sh
Executable file
@ -0,0 +1,10 @@
|
||||
#!/bin/sh
|
||||
|
||||
./compile.sh
|
||||
cd run
|
||||
|
||||
# Test 1
|
||||
echo "-- Test 1"
|
||||
./threadsTest
|
||||
|
||||
cd ..
|
Binary file not shown.
Loading…
x
Reference in New Issue
Block a user