|
| 1 | +#ifndef BAREMETAL_SRC_INCLUDE_EBBRT_PTHREAD_H_ |
| 2 | +#define BAREMETAL_SRC_INCLUDE_EBBRT_PTHREAD_H_ |
| 3 | + |
| 4 | +#include "sched.h" |
| 5 | +#include <ebbrt/Debug.h> |
| 6 | +#include <ebbrt/EventManager.h> |
| 7 | +#include <ebbrt/SpinLock.h> |
| 8 | + |
| 9 | +extern "C" { |
| 10 | +typedef unsigned long pthread_t; |
| 11 | +typedef unsigned int pthread_key_t; |
| 12 | +typedef struct { |
| 13 | + int is_initialized; |
| 14 | + void* stackaddr; |
| 15 | + int stacksize; |
| 16 | + int contentionscope; |
| 17 | + int inheritsched; |
| 18 | + int schedpolicy; |
| 19 | + sched_param schedparam; |
| 20 | + int detachstate; |
| 21 | +} pthread_attr_t; |
| 22 | + |
| 23 | +typedef struct { |
| 24 | +} pthread_barrier_t; |
| 25 | +typedef struct { |
| 26 | +} pthread_barrierattr_t; |
| 27 | +typedef struct { |
| 28 | +} pthread_cond_t; |
| 29 | +typedef struct { |
| 30 | +} pthread_condattr_t; |
| 31 | +typedef struct { |
| 32 | +} pthread_mutexattr_t; |
| 33 | +typedef struct { |
| 34 | +} pthread_rwlock_t; |
| 35 | +typedef struct { |
| 36 | +} pthread_rwlockattr_t; |
| 37 | +typedef struct { |
| 38 | +} pthread_spinlock_t; |
| 39 | + |
| 40 | +typedef struct { ebbrt::SpinLock spinlock; } pthread_mutex_t; |
| 41 | + |
| 42 | +void pthread_attr_init(pthread_attr_t* attr); |
| 43 | +int pthread_cond_broadcast(pthread_cond_t* cond); |
| 44 | +int pthread_cond_signal(pthread_cond_t* cond); |
| 45 | +int pthread_cond_timedwait(pthread_cond_t* cond, pthread_mutex_t* mutex, |
| 46 | + const struct timespec* abstime); |
| 47 | +int pthread_cond_wait(pthread_cond_t* cond, pthread_mutex_t* mutex); |
| 48 | +int pthread_cond_destroy(pthread_cond_t* cond); |
| 49 | +int pthread_cond_init(pthread_cond_t* __restrict cond, |
| 50 | + const pthread_condattr_t* __restrict attr); |
| 51 | + |
| 52 | +pthread_t pthread_self(); |
| 53 | +int pthread_create(pthread_t*, pthread_attr_t*, void* (*)(void*), void*); |
| 54 | +int pthread_join(pthread_t, void**); |
| 55 | +int pthread_detach(pthread_t thread); |
| 56 | +int pthread_equal(pthread_t t1, pthread_t t2); |
| 57 | + |
| 58 | +void* pthread_getspecific(pthread_key_t key); |
| 59 | +int pthread_setspecific(pthread_key_t key, const void* value); |
| 60 | +int pthread_key_create(pthread_key_t* key, void (*destructor)(void*)); |
| 61 | +int pthread_mutexattr_destroy(pthread_mutexattr_t* attr); |
| 62 | +int pthread_mutexattr_init(pthread_mutexattr_t* attr); |
| 63 | +int pthread_mutexattr_gettype(const pthread_mutexattr_t* __restrict attr, |
| 64 | + int* __restrict type); |
| 65 | +int pthread_mutexattr_settype(pthread_mutexattr_t* attr, int type); |
| 66 | + |
| 67 | +typedef struct { |
| 68 | +} pthread_once_t; |
| 69 | +int pthread_once(pthread_once_t* once_control, void (*init_routine)(void)); |
| 70 | + |
| 71 | +#define PTHREAD_MUTEX_INITIALIZER \ |
| 72 | + { 0 } |
| 73 | +#define PTHREAD_COND_INITIALIZER \ |
| 74 | + {} |
| 75 | +#define PTHREAD_ONCE_INIT \ |
| 76 | + {} |
| 77 | + |
| 78 | +#define PTHREAD_MUTEX_RECURSIVE 33 |
| 79 | + |
| 80 | +int pthread_mutex_init(pthread_mutex_t* mutex, const pthread_mutexattr_t* attr); |
| 81 | +int pthread_mutex_lock(pthread_mutex_t* mutex); |
| 82 | +int pthread_mutex_trylock(pthread_mutex_t* mutex); |
| 83 | +int pthread_mutex_unlock(pthread_mutex_t* mutex); |
| 84 | +int pthread_mutex_destroy(pthread_mutex_t* mutex); |
| 85 | + |
| 86 | +} // "C" |
| 87 | + |
| 88 | +#endif |
0 commit comments