pthread: add pthread_getattr_np.

non standard extension, but widely available to obtain attributes for a thread.
also provides an alias for pthread_getattr_np which is the bsd equivalent.

Change-Id: I26ef8245ed2537186f48c8b8bdf3e42b03e70892
Reviewed-on: https://review.haiku-os.org/c/1172
Reviewed-by: Adrien Destugues <pulkomandy@gmail.com>
This commit is contained in:
Jérôme Duval 2019-03-07 21:09:56 +01:00 committed by waddlesplash
parent 901c3d44b0
commit ba56d0a513
2 changed files with 68 additions and 0 deletions

View File

@ -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 <pthread.h>
#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_ */

View File

@ -14,9 +14,13 @@
#include <Debug.h>
#include <syscalls.h>
#include <thread_defs.h>
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);