Begin implementing basic pthread functionality.
This commit is contained in:
parent
1160570250
commit
34c637960a
49
include/pthread.h
Normal file
49
include/pthread.h
Normal file
@ -0,0 +1,49 @@
|
||||
|
||||
#ifndef __PTHREAD_H__
|
||||
#define __PTHREAD_H__
|
||||
|
||||
typedef uint64_t pthread_t;
|
||||
typedef uint64_t pthread_attr_t;
|
||||
typedef uint64_t pthread_barrier_t;
|
||||
typedef uint64_t pthread_barrierattr_t;
|
||||
typedef uint64_t pthread_mutex_t;
|
||||
typedef uint64_t pthread_mutexattr_t;
|
||||
|
||||
pthread_t pthread_self(void);
|
||||
int pthread_create(pthread_t *thread, const pthread_attr_t *attr,
|
||||
void *(*start_routine)(void *), void *arg);
|
||||
void pthread_exit(void *value_ptr);
|
||||
int pthread_join(pthread_t thread, void **value_ptr);
|
||||
void pthread_yield(void);
|
||||
|
||||
/*
|
||||
* Barriers
|
||||
*/
|
||||
|
||||
int pthread_barrier_init(pthread_barrier_t *barrier,
|
||||
const pthread_barrierattr_t *attr,
|
||||
unsigned count);
|
||||
int pthread_barrier_destroy(pthread_barrier_t *barrier);
|
||||
int pthread_barrier_wait(pthread_barrier_t *barrier);
|
||||
|
||||
/*
|
||||
* Mutex
|
||||
*/
|
||||
|
||||
int pthread_mutex_init(pthread_mutex_t *mutex,
|
||||
const pthread_mutexattr_t *attr);
|
||||
int pthread_mutex_destroy(pthread_mutex_t *mutex);
|
||||
int pthread_mutex_lock(pthread_mutex_t *mutex);
|
||||
int pthread_mutex_trylock(pthread_mutex_t *mutex);
|
||||
int pthread_mutex_unlock(pthread_mutex_t *mutex);
|
||||
|
||||
/*
|
||||
* Reader/Writer Lock
|
||||
*/
|
||||
|
||||
/*
|
||||
* Condition Variables
|
||||
*/
|
||||
|
||||
#endif /* __PTHREAD_H__ */
|
||||
|
@ -16,6 +16,7 @@ src_common = [
|
||||
"printf.c",
|
||||
"process.c",
|
||||
"posix/mman.c",
|
||||
"posix/pthread.c",
|
||||
"string.c",
|
||||
"syscall.c",
|
||||
"time.c",
|
||||
|
98
lib/libc/posix/pthread.c
Normal file
98
lib/libc/posix/pthread.c
Normal file
@ -0,0 +1,98 @@
|
||||
|
||||
#include <stdint.h>
|
||||
|
||||
#include <unistd.h>
|
||||
#include <pthread.h>
|
||||
|
||||
#include <syscall.h>
|
||||
|
||||
pthread_t
|
||||
pthread_self(void)
|
||||
{
|
||||
}
|
||||
|
||||
int
|
||||
pthread_create(pthread_t *thread, const pthread_attr_t *attr,
|
||||
void *(*start_routine)(void *), void *arg)
|
||||
{
|
||||
}
|
||||
|
||||
void
|
||||
pthread_exit(void *value_ptr)
|
||||
{
|
||||
OSThreadExit(value_ptr);
|
||||
}
|
||||
|
||||
int
|
||||
pthread_join(pthread_t thread, void **value_ptr)
|
||||
{
|
||||
uint64_t value = OSThreadWait(thread);
|
||||
|
||||
*value_ptr = (void *)value;
|
||||
}
|
||||
|
||||
void
|
||||
pthread_yield(void)
|
||||
{
|
||||
OSThreadSleep(0);
|
||||
}
|
||||
|
||||
/*
|
||||
* Barriers
|
||||
*/
|
||||
|
||||
int
|
||||
pthread_barrier_init(pthread_barrier_t *barrier,
|
||||
const pthread_barrierattr_t *attr,
|
||||
unsigned count)
|
||||
{
|
||||
}
|
||||
|
||||
int
|
||||
pthread_barrier_destroy(pthread_barrier_t *barrier)
|
||||
{
|
||||
}
|
||||
|
||||
int
|
||||
pthread_barrier_wait(pthread_barrier_t *barrier)
|
||||
{
|
||||
}
|
||||
|
||||
/*
|
||||
* Mutex
|
||||
*/
|
||||
|
||||
int
|
||||
pthread_mutex_init(pthread_mutex_t *mutex, const pthread_mutexattr_t *attr)
|
||||
{
|
||||
}
|
||||
|
||||
int
|
||||
pthread_mutex_destroy(pthread_mutex_t *mutex)
|
||||
{
|
||||
}
|
||||
|
||||
int
|
||||
pthread_mutex_lock(pthread_mutex_t *mutex)
|
||||
{
|
||||
}
|
||||
|
||||
int
|
||||
pthread_mutex_trylock(pthread_mutex_t *mutex)
|
||||
{
|
||||
}
|
||||
|
||||
int
|
||||
pthread_mutex_unlock(pthread_mutex_t *mutex)
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* Reader/Writer Lock
|
||||
*/
|
||||
|
||||
/*
|
||||
* Condition Variables
|
||||
*/
|
||||
|
Loading…
Reference in New Issue
Block a user