123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117 |
- #include <errno.h>
- #include <pthread.h>
- #include <sys/time.h>
- #include <time.h>
- #include <internals.h>
- #include <spinlock.h>
- #include <kernel-features.h>
- #include <kernel-posix-cpu-timers.h>
- #if !(__ASSUME_POSIX_CPU_TIMERS > 0)
- int __libc_missing_posix_cpu_timers attribute_hidden;
- #endif
- #if !(__ASSUME_POSIX_TIMERS > 0)
- int __libc_missing_posix_timers attribute_hidden;
- #endif
- int
- pthread_getcpuclockid (pthread_t thread_id, clockid_t *clock_id)
- {
- #ifdef __NR_clock_getres
- pthread_handle handle = thread_handle(thread_id);
- int pid;
- __pthread_lock (&handle->h_lock, NULL);
- if (nonexisting_handle (handle, thread_id))
- {
- __pthread_unlock (&handle->h_lock);
- return ESRCH;
- }
- pid = handle->h_descr->p_pid;
- __pthread_unlock (&handle->h_lock);
-
- const clockid_t pidclock = MAKE_PROCESS_CPUCLOCK (pid, CPUCLOCK_SCHED);
- # if !(__ASSUME_POSIX_CPU_TIMERS > 0)
- # if !(__ASSUME_POSIX_TIMERS > 0)
- if (__libc_missing_posix_timers && !__libc_missing_posix_cpu_timers)
- __libc_missing_posix_cpu_timers = 1;
- # endif
- if (!__libc_missing_posix_cpu_timers)
- {
- INTERNAL_SYSCALL_DECL (err);
- int r = INTERNAL_SYSCALL (clock_getres, err, 2, pidclock, NULL);
- if (!INTERNAL_SYSCALL_ERROR_P (r, err))
- # endif
- {
- *clock_id = pidclock;
- return 0;
- }
- # if !(__ASSUME_POSIX_CPU_TIMERS > 0)
- # if !(__ASSUME_POSIX_TIMERS > 0)
- if (INTERNAL_SYSCALL_ERRNO (r, err) == ENOSYS)
- {
-
- __libc_missing_posix_timers = 1;
- __libc_missing_posix_cpu_timers = 1;
- }
- else
- # endif
- if (INTERNAL_SYSCALL_ERRNO (r, err) == EINVAL)
- {
-
- __libc_missing_posix_cpu_timers = 1;
- }
- else
- return INTERNAL_SYSCALL_ERRNO (r, err);
- }
- # endif
- #endif
- #ifdef CLOCK_THREAD_CPUTIME_ID
-
- if (2 * PTHREAD_THREADS_MAX
- >= 1 << (8 * sizeof (*clock_id) - CLOCK_IDFIELD_SIZE))
- return ERANGE;
-
- *clock_id = CLOCK_THREAD_CPUTIME_ID | (thread_id << CLOCK_IDFIELD_SIZE);
- return 0;
- #else
-
- return ENOENT;
- #endif
- }
|