From 771f55af9fffb9209c0a26ca41322e03850d11d8 Mon Sep 17 00:00:00 2001 From: p9ya4sf57 <2573478641@qq.com> Date: Mon, 4 Jul 2022 10:00:24 +0800 Subject: [PATCH] =?UTF-8?q?=E5=88=9B=E5=BB=BA=E7=BA=BF=E7=A8=8B=E5=BA=93?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- pthread.c | 53 +++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 53 insertions(+) create mode 100644 pthread.c diff --git a/pthread.c b/pthread.c new file mode 100644 index 0000000..58e3549 --- /dev/null +++ b/pthread.c @@ -0,0 +1,53 @@ +#include "pthread.h" + +_syscall2(int, create_thread, unsigned long, start, void*, arg); +_syscall2(int, syspthread_join, pthread_t, thread, void*, value_ptr); +_syscall1(int, endthread, int, value); + +int pthread_attr_init(pthread_attr_t* attr) +{ + ;;;;; + return 0; +} +int pthread_create(pthread_t* thread, const pthread_attr_t* attr, void* (*start)(void*), void* arg) +{ + int id = 0; + if (!thread) return EINVAL; + + id = create_thread((unsigned long)start, (int*)arg); + + if (id < 0) return errno; + *thread = id; + return id; +} + +void pthread_exit(void* value_ptr) +{ + endthread((int)value_ptr); +} +int pthread_join(pthread_t thread, void** value_ptr) +{ + syspthread_join(thread, value_ptr); + return 0; +} + + + + + + + + + + + + + + + + + + + + +