Notice: We have migrated to GitLab launching 2024-05-01 see here: https://gitlab.rtems.org/

Ticket #3891: 0001-pthreadgetcpuclockid.c-Implement-pthread_getcpuclock.patch

File 0001-pthreadgetcpuclockid.c-Implement-pthread_getcpuclock.patch, 1.6 KB (added by Joel Sherrill, on 04/03/20 at 17:41:53)

Untested implementation of pthread_getcpuclockid() assuming thread ID is used as the per thread cpu clock id. Needs clock_gettime/clock_settime capabilities added and tests

  • cpukit/posix/src/pthreadgetcpuclockid.c

    From d2427f7091dbf6e50ee8d4cf21c5c7cb08467ce8 Mon Sep 17 00:00:00 2001
    From: Joel Sherrill <joel@rtems.org>
    Date: Thu, 12 Mar 2020 14:59:51 -0500
    Subject: [PATCH] pthreadgetcpuclockid.c: Implement pthread_getcpuclockid to
     return thread Id
    
    Updates #3891.
    ---
     cpukit/posix/src/pthreadgetcpuclockid.c | 31 ++++++++++++++++++++++++++-----
     1 file changed, 26 insertions(+), 5 deletions(-)
    
    diff --git a/cpukit/posix/src/pthreadgetcpuclockid.c b/cpukit/posix/src/pthreadgetcpuclockid.c
    index cd7814b..c15962e 100644
    a b  
    77
    88/*
    99 *  20.1.6 Accessing a Thread CPU-time Clock, P1003.4b/Draft 8, p. 58
    10  *
    11  *  COPYRIGHT (c) 1989-2007.
     10 */
     11
     12/*
     13 *  COPYRIGHT (c) 1989-2007,2020.
    1214 *  On-Line Applications Research Corporation (OAR).
    1315 *
    1416 *  The license and distribution terms for this file may be
     
    2325#include <pthread.h>
    2426#include <errno.h>
    2527
    26 #include <rtems/seterr.h>
     28#include <rtems/score/threadimpl.h>
    2729
    2830int pthread_getcpuclockid(
    29   pthread_t    pid,
     31  pthread_t    thread,
    3032  clockid_t   *clock_id
    3133)
    3234{
    33   rtems_set_errno_and_return_minus_one( ENOSYS );
     35  Thread_Control               *the_thread;
     36  ISR_lock_Context              lock_context;
     37
     38  if ( clock_id == NULL ) {
     39    return EINVAL;
     40  }
     41
     42  the_thread = _Thread_Get( thread, &lock_context );
     43
     44  if ( the_thread == NULL ) {
     45    return ESRCH;
     46  }
     47
     48  _Thread_State_acquire_critical( the_thread, &lock_context );
     49
     50  *clock_id = the_thread->Object.id;
     51
     52  _Thread_State_release( the_thread, &lock_context );
     53
     54  return 0;
    3455}