]>
Commit | Line | Data |
---|---|---|
d614a753 | 1 | /* Copyright (C) 2000-2020 Free Software Foundation, Inc. |
76a50749 UD |
2 | This file is part of the GNU C Library. |
3 | ||
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. | |
8 | ||
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. | |
13 | ||
14 | You should have received a copy of the GNU Lesser General Public | |
59ba27a6 | 15 | License along with the GNU C Library; see the file COPYING.LIB. If |
5a82c748 | 16 | not, see <https://www.gnu.org/licenses/>. */ |
76a50749 UD |
17 | |
18 | #include <errno.h> | |
8c2e9a29 | 19 | #include <pthreadP.h> |
76a50749 UD |
20 | #include <sys/time.h> |
21 | #include <tls.h> | |
22 | ||
23 | ||
24 | int | |
9d46370c | 25 | pthread_getcpuclockid (pthread_t threadid, clockid_t *clockid) |
76a50749 | 26 | { |
8c2e9a29 UD |
27 | struct pthread *pd = (struct pthread *) threadid; |
28 | ||
29 | /* Make sure the descriptor is valid. */ | |
30 | if (INVALID_TD_P (pd)) | |
31 | /* Not a valid thread handle. */ | |
32 | return ESRCH; | |
33 | ||
76a50749 | 34 | #ifdef CLOCK_THREAD_CPUTIME_ID |
4165d44d UD |
35 | /* We need to store the thread ID in the CLOCKID variable together |
36 | with a number identifying the clock. We reserve the low 3 bits | |
37 | for the clock ID and the rest for the thread ID. This is | |
38 | problematic if the thread ID is too large. But 29 bits should be | |
39 | fine. | |
40 | ||
41 | If some day more clock IDs are needed the ID part can be | |
42 | enlarged. The IDs are entirely internal. */ | |
43 | if (pd->tid >= 1 << (8 * sizeof (*clockid) - CLOCK_IDFIELD_SIZE)) | |
44 | return ERANGE; | |
45 | ||
76a50749 | 46 | /* Store the number. */ |
4165d44d | 47 | *clockid = CLOCK_THREAD_CPUTIME_ID | (pd->tid << CLOCK_IDFIELD_SIZE); |
76a50749 UD |
48 | |
49 | return 0; | |
50 | #else | |
51 | /* We don't have a timer for that. */ | |
52 | return ENOENT; | |
53 | #endif | |
54 | } |