libc: more pthread stubs

This commit is contained in:
K. Lange 2018-12-19 14:38:08 +09:00
parent fd382f2627
commit bdd407f29c
2 changed files with 76 additions and 0 deletions

View File

@ -19,4 +19,24 @@ extern int pthread_kill(pthread_t thread, int sig);
extern int clone(uintptr_t,uintptr_t,void*);
extern int gettid();
extern void pthread_cleanup_push(void (*routine)(void *), void *arg);
extern void pthread_cleanup_pop(int execute);
typedef int volatile pthread_mutex_t;
typedef int pthread_mutexattr_t;
extern int pthread_join(pthread_t thread, void **retval);
#define PTHREAD_MUTEX_INITIALIZER 0
extern int pthread_mutex_lock(pthread_mutex_t *mutex);
extern int pthread_mutex_trylock(pthread_mutex_t *mutex);
extern int pthread_mutex_unlock(pthread_mutex_t *mutex);
extern int pthread_mutex_init(pthread_mutex_t *mutex, const pthread_mutexattr_t *attr);
extern int pthread_mutex_destroy(pthread_mutex_t *mutex);
extern int pthread_attr_init(pthread_attr_t *attr);
extern int pthread_attr_destroy(pthread_attr_t *attr);
_End_C_Header

View File

@ -10,6 +10,8 @@
#include <pthread.h>
#include <errno.h>
#include <sys/wait.h>
DEFN_SYSCALL3(clone, SYS_CLONE, uintptr_t, uintptr_t, void *);
DEFN_SYSCALL0(gettid, SYS_GETTID);
@ -45,3 +47,57 @@ void pthread_exit(void * value) {
void (*magic_exit_func)(void) = (void *)magic_exit_target;
magic_exit_func();
}
void pthread_cleanup_push(void (*routine)(void *), void *arg) {
/* do nothing */
}
void pthread_cleanup_pop(int execute) {
/* do nothing */
}
int pthread_mutex_lock(pthread_mutex_t *mutex) {
while (__sync_lock_test_and_set(mutex, 0x01)) {
syscall_yield();
}
return 0;
}
int pthread_mutex_trylock(pthread_mutex_t *mutex) {
if (__sync_lock_test_and_set(mutex, 0x01)) {
return EBUSY;
}
return 0;
}
int pthread_mutex_unlock(pthread_mutex_t *mutex) {
__sync_lock_release(mutex);
return 0;
}
int pthread_mutex_init(pthread_mutex_t *mutex, const pthread_mutexattr_t *attr) {
*mutex = 0;
return 0;
}
int pthread_mutex_destroy(pthread_mutex_t *mutex) {
return 0;
}
int pthread_attr_init(pthread_attr_t *attr) {
*attr = 0;
return 0;
}
int pthread_attr_destroy(pthread_attr_t *attr) {
return 0;
}
int pthread_join(pthread_t thread, void **retval) {
int status;
int result = waitpid(thread.id, &status, 0);
if (retval) {
*retval = (void*)status;
}
return result;
}