(CFLAGS-tst-align.c): Add -mpreferred-stack-boundary=4.
[glibc.git] / linuxthreads / sysdeps / pthread / getcpuclockid.c
blob032caeb081f05b4138218ddce8aed6dfbf657496
1 /* Copyright (C) 2000, 2001, 2004 Free Software Foundation, Inc.
2 This file is part of the GNU C Library.
4 The GNU C Library is free software; you can redistribute it and/or
5 modify it under the terms of the GNU Lesser General Public License as
6 published by the Free Software Foundation; either version 2.1 of the
7 License, or (at your option) any later version.
9 The GNU C Library is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 Lesser General Public License for more details.
14 You should have received a copy of the GNU Lesser General Public
15 License along with the GNU C Library; see the file COPYING.LIB. If not,
16 write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
17 Boston, MA 02111-1307, USA. */
19 #include <errno.h>
20 #include <pthread.h>
21 #include <sys/time.h>
22 #include <time.h>
23 #include <internals.h>
25 int
26 pthread_getcpuclockid (pthread_t thread_id, clockid_t *clock_id)
28 #ifdef CLOCK_THREAD_CPUTIME_ID
29 /* We need to store the thread ID in the CLOCKID variable together
30 with a number identifying the clock. We reserve the low 3 bits
31 for the clock ID and the rest for the thread ID. This is
32 problematic if the thread ID is too large. But 29 bits should be
33 fine.
35 If some day more clock IDs are needed the ID part can be
36 enlarged. The IDs are entirely internal. */
37 if (2 * PTHREAD_THREADS_MAX
38 >= 1 << (8 * sizeof (*clock_id) - CLOCK_IDFIELD_SIZE))
39 return ERANGE;
41 /* Store the number. */
42 *clock_id = CLOCK_THREAD_CPUTIME_ID | (thread_id << CLOCK_IDFIELD_SIZE);
44 return 0;
45 #else
46 /* We don't have a timer for that. */
47 return ENOENT;
48 #endif