2003-05-16 Roland McGrath <roland@redhat.com>
[glibc.git] / nptl / pthread_getattr_np.c
blob4e580437cfdf582a7cc0b6e63c5d4b4cf8d4ae96
1 /* Copyright (C) 2002 Free Software Foundation, Inc.
2 This file is part of the GNU C Library.
3 Contributed by Ulrich Drepper <drepper@redhat.com>, 2002.
5 The GNU C Library is free software; you can redistribute it and/or
6 modify it under the terms of the GNU Lesser General Public
7 License as published by the Free Software Foundation; either
8 version 2.1 of the License, or (at your option) any later version.
10 The GNU C Library is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Lesser General Public License for more details.
15 You should have received a copy of the GNU Lesser General Public
16 License along with the GNU C Library; if not, write to the Free
17 Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
18 02111-1307 USA. */
20 #include <string.h>
21 #include "pthreadP.h"
22 #include <lowlevellock.h>
25 int
26 pthread_getattr_np (thread_id, attr)
27 pthread_t thread_id;
28 pthread_attr_t *attr;
30 struct pthread *thread = (struct pthread *) thread_id;
31 struct pthread_attr *iattr = (struct pthread_attr *) attr;
33 /* We have to handle cancellation in the following code since we are
34 locking another threads desriptor. */
35 pthread_cleanup_push ((void (*) (void *)) lll_unlock_wake_cb, &thread->lock);
37 lll_lock (thread->lock);
39 /* The thread library is responsible for keeping the values in the
40 thread desriptor up-to-date in case the user changes them. */
41 memcpy (&iattr->schedparam, &thread->schedparam,
42 sizeof (struct sched_param));
43 iattr->schedpolicy = thread->schedpolicy;
45 /* Clear the flags work. */
46 iattr->flags = thread->flags;
48 /* The thread might be detached by now. */
49 if (IS_DETACHED (thread))
50 iattr->flags |= ATTR_FLAG_DETACHSTATE;
52 /* This is the guardsize after adjusting it. */
53 iattr->guardsize = thread->guardsize;
55 /* The sizes are subject to alignment. */
56 iattr->stacksize = thread->stackblock_size;
57 iattr->stackaddr = (char *) thread->stackblock + iattr->stacksize;
58 iattr->flags |= ATTR_FLAG_STACKADDR;
60 lll_unlock (thread->lock);
62 pthread_cleanup_pop (0);
64 return 0;