diff --git a/headers/compatibility/gnu/pthread.h b/headers/compatibility/gnu/pthread.h new file mode 100644 index 0000000000..b1699125cd --- /dev/null +++ b/headers/compatibility/gnu/pthread.h @@ -0,0 +1,32 @@ +/* + * Copyright 2019 Haiku, Inc. All Rights Reserved. + * Distributed under the terms of the Haiku License. + */ +#ifndef _GNU_PTHREAD_H_ +#define _GNU_PTHREAD_H_ + + +#include_next + + +#ifdef _GNU_SOURCE + + +#ifdef __cplusplus +extern "C" { +#endif + + +extern int pthread_getattr_np(pthread_t thread, pthread_attr_t* attr); + + +#ifdef __cplusplus +} +#endif + + +#endif + + +#endif /* _GNU_PTHREAD_H_ */ + diff --git a/src/system/libroot/posix/pthread/pthread_attr.c b/src/system/libroot/posix/pthread/pthread_attr.c index 9ae6a3e8c4..ac6894508b 100644 --- a/src/system/libroot/posix/pthread/pthread_attr.c +++ b/src/system/libroot/posix/pthread/pthread_attr.c @@ -14,9 +14,13 @@ #include +#include #include +int __pthread_getattr_np(pthread_t thread, pthread_attr_t *_attr); + + int pthread_attr_init(pthread_attr_t *_attr) { @@ -235,3 +239,35 @@ pthread_attr_setstack(pthread_attr_t *_attr, void *stackaddr, return 0; } + +int +__pthread_getattr_np(pthread_t thread, pthread_attr_t *_attr) +{ + pthread_attr *attr; + status_t status; + thread_info info; + + if (_attr == NULL || (attr = *_attr) == NULL) + return B_BAD_VALUE; + + status = _kern_get_thread_info(thread->id, &info); + if (status == B_BAD_THREAD_ID) + return ESRCH; + + if ((thread->flags & THREAD_DETACHED) != 0) + attr->detach_state = PTHREAD_CREATE_DETACHED; + else + attr->detach_state = PTHREAD_CREATE_JOINABLE; + attr->sched_priority = info.priority; + attr->stack_address = info.stack_base; + attr->stack_size = (size_t)info.stack_end - (size_t)info.stack_base; + // not in thread_info + attr->guard_size = 0; + + return 0; +} + + +B_DEFINE_WEAK_ALIAS(__pthread_getattr_np, pthread_getattr_np); +B_DEFINE_WEAK_ALIAS(__pthread_getattr_np, pthread_attr_get_np); +