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:
2025-05-31 23:34:26 +03:00
parent 423386a052
commit c957f1ddca
17 changed files with 368 additions and 146 deletions

View File

@@ -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

View File

@@ -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

View 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

View 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

View 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

View 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

View File

@@ -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>