From a411c76cd686864a2dc3116d8ff16f3d26786c56 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Axel=20D=C3=B6rfler?= Date: Fri, 23 May 2008 11:24:40 +0000 Subject: [PATCH] * Added pthread_attr_setscope(), and pthread_attr_getscope(). We only support PTHREAD_SCOPE_SYSTEM which makes the implementation rather simple. * This closed ticket #2242. git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@25628 a95241bf-73f2-0310-859d-f6bbb57e9c96 --- headers/posix/pthread.h | 6 ++-- .../libroot/posix/pthread/pthread_attr.c | 33 ++++++++++++++++--- 2 files changed, 32 insertions(+), 7 deletions(-) diff --git a/headers/posix/pthread.h b/headers/posix/pthread.h index 3b0ef6cf46..0b063784f8 100644 --- a/headers/posix/pthread.h +++ b/headers/posix/pthread.h @@ -224,6 +224,9 @@ extern int pthread_attr_setdetachstate(pthread_attr_t *attr, int detachstate); extern int pthread_attr_getstacksize(const pthread_attr_t *attr, size_t *stacksize); extern int pthread_attr_setstacksize(pthread_attr_t *attr, size_t stacksize); +extern int pthread_attr_getscope(const pthread_attr_t *attr, + int *contentionScope); +extern int pthread_attr_setscope(pthread_attr_t *attr, int contentionScope); #if 0 /* Unimplemented attribute functions: */ @@ -241,9 +244,6 @@ extern int pthread_attr_setinheritsched(pthread_attr_t *attr, int inheritsched); extern int pthread_attr_getschedpolicy(const pthread_attr_t *attr, int *policy); extern int pthread_attr_setschedpolicy(pthread_attr_t *attr, int policy); -extern int pthread_attr_getscope(const pthread_attr_t *attr, - int *contentionscope); -extern int pthread_attr_setscope(pthread_attr_t *attr, int contentionscope); /* [XSI] */ extern int pthread_attr_getguardsize(const pthread_attr_t *attr, diff --git a/src/system/libroot/posix/pthread/pthread_attr.c b/src/system/libroot/posix/pthread/pthread_attr.c index e488da8ec7..3c73190d43 100644 --- a/src/system/libroot/posix/pthread/pthread_attr.c +++ b/src/system/libroot/posix/pthread/pthread_attr.c @@ -1,5 +1,6 @@ -/* +/* * Copyright 2008, Ingo Weinhold, ingo_weinhold@gmx.de. + * Copyright 2008, Axel Dörfler, axeld@pinc-software.de. * Copyright 2006, Jérôme Duval. All rights reserved. * Distributed under the terms of the MIT License. */ @@ -12,7 +13,7 @@ #include -int +int pthread_attr_init(pthread_attr_t *_attr) { pthread_attr *attr; @@ -33,7 +34,7 @@ pthread_attr_init(pthread_attr_t *_attr) } -int +int pthread_attr_destroy(pthread_attr_t *_attr) { pthread_attr *attr; @@ -52,7 +53,7 @@ int pthread_attr_getdetachstate(const pthread_attr_t *_attr, int *state) { pthread_attr *attr; - + if (_attr == NULL || (attr = *_attr) == NULL || state == NULL) return B_BAD_VALUE; @@ -108,3 +109,27 @@ pthread_attr_setstacksize(pthread_attr_t *_attr, size_t stacksize) return 0; } + + +int +pthread_attr_getscope(const pthread_attr_t *attr, int *contentionScope) +{ + if (attr == NULL || contentionScope == NULL) + return EINVAL; + + *contentionScope = PTHREAD_SCOPE_SYSTEM; + return 0; +} + + +int +pthread_attr_setscope(pthread_attr_t *attr, int contentionScope) +{ + if (attr == NULL) + return EINVAL; + + if (contentionScope != PTHREAD_SCOPE_SYSTEM) + return ENOTSUP; + + return 0; +}