LibC: Implement basic pthread mutexes
This implementation is just calling sched_yield if it could not get mutex. This is not optimal as it does not allow the CPU to idle, but it works for now :) Also I did not test this code at all, but it feels correct :D
This commit is contained in:
@@ -40,18 +40,24 @@ __BEGIN_DECLS
|
||||
#endif
|
||||
#undef __need_pthread_key_t
|
||||
|
||||
#if !defined(__pthread_mutex_t_defined) && (defined(__need_all_types) || defined(__need_pthread_mutex_t))
|
||||
#define __pthread_mutex_t_defined 1
|
||||
typedef int pthread_mutex_t;
|
||||
#if !defined(__pthread_t_defined) && (defined(__need_all_types) || defined(__need_pthread_t))
|
||||
#define __pthread_t_defined 1
|
||||
typedef pid_t pthread_t;
|
||||
#endif
|
||||
#undef __need_pthread_mutex_t
|
||||
#undef __need_pthread_t
|
||||
|
||||
#if !defined(__pthread_mutexattr_t_defined) && (defined(__need_all_types) || defined(__need_pthread_mutexattr_t))
|
||||
#define __pthread_mutexattr_t_defined 1
|
||||
typedef int pthread_mutexattr_t;
|
||||
typedef struct { int type; bool shared; } pthread_mutexattr_t;
|
||||
#endif
|
||||
#undef __need_pthread_mutexattr_t
|
||||
|
||||
#if !defined(__pthread_mutex_t_defined) && (defined(__need_all_types) || defined(__need_pthread_mutex_t))
|
||||
#define __pthread_mutex_t_defined 1
|
||||
typedef struct { pthread_mutexattr_t attr; pthread_t locker; unsigned lock_depth; } pthread_mutex_t;
|
||||
#endif
|
||||
#undef __need_pthread_mutex_t
|
||||
|
||||
#if !defined(__pthread_once_t_defined) && (defined(__need_all_types) || defined(__need_pthread_once_t))
|
||||
#define __pthread_once_t_defined 1
|
||||
typedef int pthread_once_t;
|
||||
@@ -70,12 +76,6 @@ __BEGIN_DECLS
|
||||
#endif
|
||||
#undef __need_pthread_rwlockattr_t
|
||||
|
||||
#if !defined(__pthread_t_defined) && (defined(__need_all_types) || defined(__need_pthread_t))
|
||||
#define __pthread_t_defined 1
|
||||
typedef pid_t pthread_t;
|
||||
#endif
|
||||
#undef __need_pthread_t
|
||||
|
||||
#if !defined(__pthread_spinlock_t_defined) && (defined(__need_all_types) || defined(__need_pthread_spinlock_t))
|
||||
#define __pthread_spinlock_t_defined 1
|
||||
typedef pthread_t pthread_spinlock_t;
|
||||
|
||||
Reference in New Issue
Block a user