LibC: Implement dummy pthread_attr_{get,set}detachstate

detached threads are not yet supported, but this allows implementation
to make sure threads are joinable.
This commit is contained in:
Bananymous 2025-04-21 19:58:01 +03:00
parent 2a5921b9c9
commit b774f147da
2 changed files with 25 additions and 2 deletions

View File

@ -29,8 +29,6 @@ struct uthread
#define PTHREAD_CANCEL_DEFERRED 4
#define PTHREAD_CANCEL_DISABLE 5
#define PTHREAD_CANCELED 6
#define PTHREAD_CREATE_DETACHED 7
#define PTHREAD_CREATE_JOINABLE 8
#define PTHREAD_EXPLICIT_SCHED 9
#define PTHREAD_INHERIT_SCHED 10
#define PTHREAD_PRIO_INHERIT 18
@ -39,6 +37,9 @@ struct uthread
#define PTHREAD_SCOPE_PROCESS 23
#define PTHREAD_SCOPE_SYSTEM 24
#define PTHREAD_CREATE_DETACHED 1
#define PTHREAD_CREATE_JOINABLE 0
#define PTHREAD_BARRIER_SERIAL_THREAD 1
#define PTHREAD_ONCE_INIT 0

View File

@ -187,6 +187,28 @@ int pthread_attr_setstacksize(pthread_attr_t* attr, size_t stacksize)
return 0;
}
int pthread_attr_getdetachstate(const pthread_attr_t* attr, int* detachstate)
{
(void)attr;
*detachstate = PTHREAD_CREATE_JOINABLE;
return 0;
}
int pthread_attr_setdetachstate(pthread_attr_t* attr, int detachstate)
{
(void)attr;
switch (detachstate)
{
case PTHREAD_CREATE_DETACHED:
dwarnln("TODO: pthread_attr_setdetachstate");
return ENOTSUP;
case PTHREAD_CREATE_JOINABLE:
return 0;
default:
return EINVAL;
}
}
int pthread_create(pthread_t* __restrict thread_id, const pthread_attr_t* __restrict attr, void* (*start_routine)(void*), void* __restrict arg)
{
auto* info = static_cast<pthread_trampoline_info_t*>(malloc(sizeof(pthread_trampoline_info_t)));