[PATCH] pthreadgetcpuclockid.c: Implement pthread_getcpuclockid to return thread Id

Joel Sherrill joel at rtems.org
Thu Mar 12 20:00:08 UTC 2020


---
 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/cpukit/posix/src/pthreadgetcpuclockid.c
+++ b/cpukit/posix/src/pthreadgetcpuclockid.c
@@ -7,8 +7,10 @@
 
 /*
  *  20.1.6 Accessing a Thread CPU-time Clock, P1003.4b/Draft 8, p. 58
- *
- *  COPYRIGHT (c) 1989-2007.
+ */
+
+/*
+ *  COPYRIGHT (c) 1989-2007,2020.
  *  On-Line Applications Research Corporation (OAR).
  *
  *  The license and distribution terms for this file may be
@@ -23,12 +25,31 @@
 #include <pthread.h>
 #include <errno.h>
 
-#include <rtems/seterr.h>
+#include <rtems/score/threadimpl.h>
 
 int pthread_getcpuclockid(
-  pthread_t    pid,
+  pthread_t    thread,
   clockid_t   *clock_id
 )
 {
-  rtems_set_errno_and_return_minus_one( ENOSYS );
+  Thread_Control               *the_thread;
+  ISR_lock_Context              lock_context;
+
+  if ( clock_id == NULL ) {
+    return EINVAL;
+  }
+
+  the_thread = _Thread_Get( thread, &lock_context );
+
+  if ( the_thread == NULL ) {
+    return ESRCH;
+  }
+
+  _Thread_State_acquire_critical( the_thread, &lock_context );
+
+  *clock_id = the_thread->Object.id;
+
+  _Thread_State_release( the_thread, &lock_context );
+
+  return 0;
 }
-- 
1.8.3.1



More information about the devel mailing list