|
Packit Service |
3b0880 |
/* Copyright (C) 2001-2018 Free Software Foundation, Inc.
|
|
Packit Service |
3b0880 |
This file is part of the GNU C Library.
|
|
Packit Service |
3b0880 |
|
|
Packit Service |
3b0880 |
The GNU C Library is free software; you can redistribute it and/or
|
|
Packit Service |
3b0880 |
modify it under the terms of the GNU Lesser General Public License as
|
|
Packit Service |
3b0880 |
published by the Free Software Foundation; either version 2.1 of the
|
|
Packit Service |
3b0880 |
License, or (at your option) any later version.
|
|
Packit Service |
3b0880 |
|
|
Packit Service |
3b0880 |
The GNU C Library is distributed in the hope that it will be useful,
|
|
Packit Service |
3b0880 |
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
Packit Service |
3b0880 |
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
Packit Service |
3b0880 |
Lesser General Public License for more details.
|
|
Packit Service |
3b0880 |
|
|
Packit Service |
3b0880 |
You should have received a copy of the GNU Lesser General Public
|
|
Packit Service |
3b0880 |
License along with the GNU C Library; see the file COPYING.LIB. If
|
|
Packit Service |
3b0880 |
not, see <http://www.gnu.org/licenses/>. */
|
|
Packit Service |
3b0880 |
|
|
Packit Service |
3b0880 |
#include <errno.h>
|
|
Packit Service |
3b0880 |
#include <stdlib.h>
|
|
Packit Service |
3b0880 |
#include <time.h>
|
|
Packit Service |
3b0880 |
#include "pthreadP.h"
|
|
Packit Service |
3b0880 |
|
|
Packit Service |
3b0880 |
|
|
Packit Service |
3b0880 |
#if HP_TIMING_AVAIL
|
|
Packit Service |
3b0880 |
int
|
|
Packit Service |
3b0880 |
__pthread_clock_settime (clockid_t clock_id, hp_timing_t offset)
|
|
Packit Service |
3b0880 |
{
|
|
Packit Service |
3b0880 |
/* This is the ID of the thread we are looking for. */
|
|
Packit Service |
3b0880 |
pid_t tid = ((unsigned int) clock_id) >> CLOCK_IDFIELD_SIZE;
|
|
Packit Service |
3b0880 |
|
|
Packit Service |
3b0880 |
/* Compute the offset since the start time of the process. */
|
|
Packit Service |
3b0880 |
if (tid == 0 || tid == THREAD_GETMEM (THREAD_SELF, tid))
|
|
Packit Service |
3b0880 |
/* Our own clock. */
|
|
Packit Service |
3b0880 |
THREAD_SETMEM (THREAD_SELF, cpuclock_offset, offset);
|
|
Packit Service |
3b0880 |
else
|
|
Packit Service |
3b0880 |
{
|
|
Packit Service |
3b0880 |
/* This is more complicated. We have to locate the thread based
|
|
Packit Service |
3b0880 |
on the ID. This means walking the list of existing
|
|
Packit Service |
3b0880 |
threads. */
|
|
Packit Service |
3b0880 |
struct pthread *thread = __find_thread_by_id (tid);
|
|
Packit Service |
3b0880 |
if (thread == NULL)
|
|
Packit Service |
3b0880 |
{
|
|
Packit Service |
3b0880 |
__set_errno (EINVAL);
|
|
Packit Service |
3b0880 |
return -1;
|
|
Packit Service |
3b0880 |
}
|
|
Packit Service |
3b0880 |
|
|
Packit Service |
3b0880 |
/* There is a race here. The thread might terminate and the stack
|
|
Packit Service |
3b0880 |
become unusable. But this is the user's problem. */
|
|
Packit Service |
3b0880 |
thread->cpuclock_offset = offset;
|
|
Packit Service |
3b0880 |
}
|
|
Packit Service |
3b0880 |
|
|
Packit Service |
3b0880 |
return 0;
|
|
Packit Service |
3b0880 |
}
|
|
Packit Service |
3b0880 |
#endif
|