123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869 |
- #include <errno.h>
- #include <stdlib.h>
- #include <time.h>
- #include <libc-internal.h>
- #include "pthreadP.h"
- #if HP_TIMING_AVAIL
- int
- __pthread_clock_gettime (clockid_t clock_id, hp_timing_t freq,
- struct timespec *tp)
- {
- hp_timing_t tsc;
-
- HP_TIMING_NOW (tsc);
-
- pid_t tid = ((unsigned int) clock_id) >> CLOCK_IDFIELD_SIZE;
-
- if (tid == 0 || tid == THREAD_GETMEM (THREAD_SELF, tid))
-
- tsc -= THREAD_GETMEM (THREAD_SELF, cpuclock_offset);
- else
- {
-
- struct pthread *thread = __find_thread_by_id (tid);
- if (thread == NULL)
- {
- __set_errno (EINVAL);
- return -1;
- }
-
- tsc -= thread->cpuclock_offset;
- }
-
- tp->tv_sec = tsc / freq;
-
- tp->tv_nsec = ((tsc % freq) * 1000000000ull) / freq;
- return 0;
- }
- #endif
|