LibC: Cleanup pthread code and add some pthread_attr functions
errno, pthread cleanup and pthread id are now stored in uthread. This allows using these without TLS
This commit is contained in:
@@ -12,11 +12,12 @@ __BEGIN_DECLS
|
||||
#include <signal.h>
|
||||
|
||||
#define __need_off_t
|
||||
#define __need_pthread_attr_t
|
||||
#define __need_size_t
|
||||
#define __need_ssize_t
|
||||
#include <sys/types.h>
|
||||
|
||||
#include <bits/types/pthread_attr_t.h>
|
||||
|
||||
struct aiocb
|
||||
{
|
||||
int aio_fildes; /* File descriptor. */
|
||||
|
||||
@@ -1,44 +0,0 @@
|
||||
// https://pubs.opengroup.org/onlinepubs/9699919799/basedefs/sys_types.h.html
|
||||
|
||||
#include <sys/cdefs.h>
|
||||
|
||||
__BEGIN_DECLS
|
||||
|
||||
#if !defined(__pthread_attr_t_defined) && (defined(__need_all_types) || defined(__need_pthread_attr_t) || defined(__need_pthread_types))
|
||||
#define __pthread_attr_t_defined 1
|
||||
typedef int pthread_attr_t;
|
||||
#endif
|
||||
#undef __need_pthread_attr_t
|
||||
|
||||
#if !defined(__pthread_t_defined) && (defined(__need_all_types) || defined(__need_pthread_t) || defined(__need_pthread_types))
|
||||
#define __pthread_t_defined 1
|
||||
typedef pid_t pthread_t;
|
||||
#endif
|
||||
#undef __need_pthread_t
|
||||
|
||||
#if !defined(__pthread_types_defined) && (defined(__need_all_types) || defined(__need_pthread_types))
|
||||
#define __pthread_types_defined 1
|
||||
|
||||
typedef int pthread_once_t;
|
||||
|
||||
typedef unsigned pthread_key_t;
|
||||
|
||||
typedef pthread_t pthread_spinlock_t;
|
||||
|
||||
typedef struct { int type; int shared; } pthread_mutexattr_t;
|
||||
typedef struct { pthread_mutexattr_t attr; pthread_t locker; unsigned lock_depth; } pthread_mutex_t;
|
||||
|
||||
typedef struct { int shared; } pthread_barrierattr_t;
|
||||
typedef struct { pthread_barrierattr_t attr; unsigned target; unsigned waiting; } pthread_barrier_t;
|
||||
|
||||
typedef struct { int clock; int shared; } pthread_condattr_t;
|
||||
struct _pthread_cond_block { struct _pthread_cond_block* next; int signaled; };
|
||||
typedef struct { pthread_condattr_t attr; pthread_spinlock_t lock; struct _pthread_cond_block* block_list; } pthread_cond_t;
|
||||
|
||||
typedef struct { int shared; } pthread_rwlockattr_t;
|
||||
typedef struct { pthread_rwlockattr_t attr; unsigned lockers; unsigned writers; } pthread_rwlock_t;
|
||||
|
||||
#endif
|
||||
#undef __need_pthread_types
|
||||
|
||||
__END_DECLS
|
||||
@@ -1,5 +1,5 @@
|
||||
#ifndef _BITS_LOCALE_T_H
|
||||
#define _BITS_LOCALE_T_H 1
|
||||
#ifndef _BITS_TYPES_LOCALE_T_H
|
||||
#define _BITS_TYPES_LOCALE_T_H 1
|
||||
|
||||
// https://pubs.opengroup.org/onlinepubs/9699919799/basedefs/locale.h.html
|
||||
|
||||
|
||||
25
userspace/libraries/LibC/include/bits/types/pthread_attr_t.h
Normal file
25
userspace/libraries/LibC/include/bits/types/pthread_attr_t.h
Normal file
@@ -0,0 +1,25 @@
|
||||
#ifndef _BITS_TYPES_PTHREAD_ATTR_T_H
|
||||
#define _BITS_TYPES_PTHREAD_ATTR_T_H 1
|
||||
|
||||
// https://pubs.opengroup.org/onlinepubs/9699919799/basedefs/pthread.h.html
|
||||
|
||||
#include <sys/cdefs.h>
|
||||
|
||||
__BEGIN_DECLS
|
||||
|
||||
#include <bits/types/sched_param.h>
|
||||
|
||||
typedef struct
|
||||
{
|
||||
int inheritsched;
|
||||
struct sched_param schedparam;
|
||||
int schedpolicy;
|
||||
int detachstate;
|
||||
int scope;
|
||||
size_t stacksize;
|
||||
size_t guardsize;
|
||||
} pthread_attr_t;
|
||||
|
||||
__END_DECLS
|
||||
|
||||
#endif
|
||||
17
userspace/libraries/LibC/include/bits/types/pthread_t.h
Normal file
17
userspace/libraries/LibC/include/bits/types/pthread_t.h
Normal file
@@ -0,0 +1,17 @@
|
||||
#ifndef _BITS_TYPES_PTHREAD_T_H
|
||||
#define _BITS_TYPES_PTHREAD_T_H 1
|
||||
|
||||
// https://pubs.opengroup.org/onlinepubs/9699919799/basedefs/pthread.h.html
|
||||
|
||||
#include <sys/cdefs.h>
|
||||
|
||||
__BEGIN_DECLS
|
||||
|
||||
#define __need_pid_t
|
||||
#include <sys/types.h>
|
||||
|
||||
typedef pid_t pthread_t;
|
||||
|
||||
__END_DECLS
|
||||
|
||||
#endif
|
||||
72
userspace/libraries/LibC/include/bits/types/pthread_types.h
Normal file
72
userspace/libraries/LibC/include/bits/types/pthread_types.h
Normal file
@@ -0,0 +1,72 @@
|
||||
#ifndef _BITS_TYPES_PTHREAD_TYPES_H
|
||||
#define _BITS_TYPES_PTHREAD_TYPES_H 1
|
||||
|
||||
// https://pubs.opengroup.org/onlinepubs/9699919799/basedefs/pthread.h.html
|
||||
|
||||
#include <sys/cdefs.h>
|
||||
|
||||
__BEGIN_DECLS
|
||||
|
||||
#include <bits/types/pthread_attr_t.h>
|
||||
#include <bits/types/pthread_t.h>
|
||||
|
||||
typedef int pthread_once_t;
|
||||
|
||||
typedef unsigned pthread_key_t;
|
||||
|
||||
typedef pthread_t pthread_spinlock_t;
|
||||
|
||||
typedef struct
|
||||
{
|
||||
int type;
|
||||
int shared;
|
||||
} pthread_mutexattr_t;
|
||||
typedef struct
|
||||
{
|
||||
pthread_mutexattr_t attr;
|
||||
pthread_t locker;
|
||||
unsigned lock_depth;
|
||||
} pthread_mutex_t;
|
||||
|
||||
typedef struct
|
||||
{
|
||||
int shared;
|
||||
} pthread_barrierattr_t;
|
||||
typedef struct
|
||||
{
|
||||
pthread_barrierattr_t attr;
|
||||
unsigned target;
|
||||
unsigned waiting;
|
||||
} pthread_barrier_t;
|
||||
|
||||
typedef struct
|
||||
{
|
||||
int clock;
|
||||
int shared;
|
||||
} pthread_condattr_t;
|
||||
struct _pthread_cond_block
|
||||
{
|
||||
struct _pthread_cond_block* next;
|
||||
int signaled;
|
||||
};
|
||||
typedef struct
|
||||
{
|
||||
pthread_condattr_t attr;
|
||||
pthread_spinlock_t lock;
|
||||
struct _pthread_cond_block* block_list;
|
||||
} pthread_cond_t;
|
||||
|
||||
typedef struct
|
||||
{
|
||||
int shared;
|
||||
} pthread_rwlockattr_t;
|
||||
typedef struct
|
||||
{
|
||||
pthread_rwlockattr_t attr;
|
||||
unsigned lockers;
|
||||
unsigned writers;
|
||||
} pthread_rwlock_t;
|
||||
|
||||
__END_DECLS
|
||||
|
||||
#endif
|
||||
23
userspace/libraries/LibC/include/bits/types/sched_param.h
Normal file
23
userspace/libraries/LibC/include/bits/types/sched_param.h
Normal file
@@ -0,0 +1,23 @@
|
||||
#ifndef _BITS_TYPES_SCHED_PARAM_H
|
||||
#define _BITS_TYPES_SCHED_PARAM_H 1
|
||||
|
||||
// https://pubs.opengroup.org/onlinepubs/9699919799/basedefs/sched.h.html
|
||||
|
||||
#include <sys/cdefs.h>
|
||||
|
||||
__BEGIN_DECLS
|
||||
|
||||
#include <time.h>
|
||||
|
||||
struct sched_param
|
||||
{
|
||||
int sched_priority; /* Process or thread execution scheduling priority. */
|
||||
int sched_ss_low_priority; /* Low scheduling priority for sporadic server. */
|
||||
struct timespec sched_ss_repl_period; /* Replenishment period for sporadic server. */
|
||||
struct timespec sched_ss_init_budget; /* Initial budget for sporadic server. */
|
||||
int sched_ss_max_repl; /* Maximum pending replenishments for sporadic server. */
|
||||
};
|
||||
|
||||
__END_DECLS
|
||||
|
||||
#endif
|
||||
@@ -1,5 +1,5 @@
|
||||
#ifndef _BITS_TIMEVAL_H
|
||||
#define _BITS_TIMEVAL_H 1
|
||||
#ifndef _BITS_TYPES_TIMEVAL_H
|
||||
#define _BITS_TYPES_TIMEVAL_H 1
|
||||
|
||||
#include <sys/cdefs.h>
|
||||
|
||||
|
||||
@@ -10,11 +10,12 @@ __BEGIN_DECLS
|
||||
#include <time.h>
|
||||
#include <signal.h>
|
||||
|
||||
#define __need_pthread_attr_t
|
||||
#define __need_size_t
|
||||
#define __need_ssize_t
|
||||
#include <sys/types.h>
|
||||
|
||||
#include <bits/types/pthread_attr_t.h>
|
||||
|
||||
typedef int mqd_t;
|
||||
|
||||
struct mq_attr
|
||||
|
||||
@@ -13,29 +13,45 @@ __BEGIN_DECLS
|
||||
|
||||
#define __need_size_t
|
||||
#define __need_clockid_t
|
||||
#define __need_pthread_types
|
||||
#include <sys/types.h>
|
||||
|
||||
#include <bits/types/pthread_types.h>
|
||||
|
||||
struct _pthread_cleanup_t
|
||||
{
|
||||
void (*routine)(void*);
|
||||
void* arg;
|
||||
struct _pthread_cleanup_t* next;
|
||||
};
|
||||
|
||||
struct uthread
|
||||
{
|
||||
struct uthread* self;
|
||||
void* master_tls_addr;
|
||||
size_t master_tls_size;
|
||||
struct _pthread_cleanup_t* cleanup_stack;
|
||||
pthread_t id;
|
||||
int errno_;
|
||||
uintptr_t dtv[];
|
||||
};
|
||||
|
||||
#define PTHREAD_CANCEL_ASYNCHRONOUS 2
|
||||
#define PTHREAD_CANCEL_ENABLE 3
|
||||
#define PTHREAD_CANCEL_DEFERRED 4
|
||||
#define PTHREAD_CANCEL_DISABLE 5
|
||||
#define PTHREAD_CANCELED 6
|
||||
#define PTHREAD_EXPLICIT_SCHED 9
|
||||
#define PTHREAD_INHERIT_SCHED 10
|
||||
#define PTHREAD_PRIO_INHERIT 18
|
||||
#define PTHREAD_PRIO_NONE 19
|
||||
#define PTHREAD_PRIO_PROTECT 20
|
||||
#define PTHREAD_SCOPE_PROCESS 23
|
||||
#define PTHREAD_SCOPE_SYSTEM 24
|
||||
#define PTHREAD_CANCELED 1
|
||||
|
||||
#define PTHREAD_CANCEL_ASYNCHRONOUS 1
|
||||
#define PTHREAD_CANCEL_DEFERRED 0
|
||||
|
||||
#define PTHREAD_CANCEL_DISABLE 0
|
||||
#define PTHREAD_CANCEL_ENABLE 1
|
||||
|
||||
#define PTHREAD_PRIO_INHERIT 1
|
||||
#define PTHREAD_PRIO_NONE 0
|
||||
#define PTHREAD_PRIO_PROTECT 2
|
||||
|
||||
#define PTHREAD_EXPLICIT_SCHED 1
|
||||
#define PTHREAD_INHERIT_SCHED 0
|
||||
|
||||
#define PTHREAD_SCOPE_PROCESS 1
|
||||
#define PTHREAD_SCOPE_SYSTEM 0
|
||||
|
||||
#define PTHREAD_CREATE_DETACHED 1
|
||||
#define PTHREAD_CREATE_JOINABLE 0
|
||||
|
||||
@@ -12,14 +12,7 @@ __BEGIN_DECLS
|
||||
#define __need_pid_t
|
||||
#include <sys/types.h>
|
||||
|
||||
struct sched_param
|
||||
{
|
||||
int sched_priority; /* Process or thread execution scheduling priority. */
|
||||
int sched_ss_low_priority; /* Low scheduling priority for sporadic server. */
|
||||
struct timespec sched_ss_repl_period; /* Replenishment period for sporadic server. */
|
||||
struct timespec sched_ss_init_budget; /* Initial budget for sporadic server. */
|
||||
int sched_ss_max_repl; /* Maximum pending replenishments for sporadic server. */
|
||||
};
|
||||
#include <bits/types/sched_param.h>
|
||||
|
||||
#define SCHED_FIFO 1
|
||||
#define SCHED_RR 2
|
||||
|
||||
@@ -14,13 +14,14 @@ __BEGIN_DECLS
|
||||
#define SIG_HOLD ((void (*)(int))2)
|
||||
#define SIG_IGN ((void (*)(int))3)
|
||||
|
||||
#define __need_pthread_t
|
||||
#define __need_size_t
|
||||
#define __need_uid_t
|
||||
#define __need_pid_t
|
||||
#define __need_pthread_attr_t
|
||||
#include <sys/types.h>
|
||||
|
||||
#include <bits/types/pthread_attr_t.h>
|
||||
#include <bits/types/pthread_t.h>
|
||||
|
||||
typedef int sig_atomic_t;
|
||||
typedef unsigned long long sigset_t;
|
||||
|
||||
|
||||
@@ -21,9 +21,6 @@ __BEGIN_DECLS
|
||||
&& !defined(__need_nlink_t) \
|
||||
&& !defined(__need_off_t) \
|
||||
&& !defined(__need_pid_t) \
|
||||
&& !defined(__need_pthread_attr_t) \
|
||||
&& !defined(__need_pthread_t) \
|
||||
&& !defined(__need_pthread_types) \
|
||||
&& !defined(__need_size_t) \
|
||||
&& !defined(__need_ssize_t) \
|
||||
&& !defined(__need_suseconds_t) \
|
||||
@@ -122,18 +119,12 @@ __BEGIN_DECLS
|
||||
#endif
|
||||
#undef __need_off_t
|
||||
|
||||
#ifdef __need_pthread_t
|
||||
#define __need_pid_t
|
||||
#endif
|
||||
|
||||
#if !defined(__pid_t_defined) && (defined(__need_all_types) || defined(__need_pid_t))
|
||||
#define __pid_t_defined 1
|
||||
typedef int pid_t;
|
||||
#endif
|
||||
#undef __need_pid_t
|
||||
|
||||
#include <bits/pthread_types.h>
|
||||
|
||||
#if !defined(__size_t_defined) && (defined(__need_all_types) || defined(__need_size_t))
|
||||
#define __size_t_defined 1
|
||||
#define __need_size_t
|
||||
|
||||
Reference in New Issue
Block a user