Hello,
While trying to use realtime tests (included in ltp:Linux Test Project package), on a mips based board, I found that some functions, used by tests, are not in uClibc. I try to add them, and I don't know if my work is enough and even good. My work is nothing else than copying missing functions from glibc-2.7 souces. It seems that, to run tests, I need to add another function clock_nanosleep (for the moment :-) ). Before I continue, can somebody tell me if my way of adding missing functions is good and if not what is wrong? I can compile modified uClibc (see attached patch) without errors (is it enough?).
Thanks
Regards


diff -Naur uClibc/libpthread/linuxthreads/condvar.c uClibc.patch/libpthread/linuxthreads/condvar.c
--- uClibc/libpthread/linuxthreads/condvar.c	2008-06-19 09:21:47.000000000 +0000
+++ uClibc.patch/libpthread/linuxthreads/condvar.c	2008-06-19 14:29:20.000000000 +0000
@@ -19,6 +19,10 @@
 #include <sched.h>
 #include <stddef.h>
 #include <sys/time.h>
+/*Imported from glibc-2.7 to support pthread_condattr_{g,s}etclock*/
+#include <sys/syscall.h>
+#include <assert.h>
+/*End: Imported from glibc-2.7 to support pthread_condattr_{g,s}etclock*/
 #include "pthread.h"
 #include "internals.h"
 #include "spinlock.h"
@@ -302,3 +306,56 @@
 
   return 0;
 }
+
+/*Imported from glibc-2.7 to support pthread_condattr_{g,s}etclock*/
+/* The __NWAITERS field is used as a counter and to house the number
+   of bits for other purposes.  COND_CLOCK_BITS is the number
+   of bits needed to represent the ID of the clock.  COND_NWAITERS_SHIFT
+   is the number of bits reserved for other purposes like the clock.  */
+#define COND_CLOCK_BITS         1
+#define COND_NWAITERS_SHIFT     1
+int pthread_condattr_getclock (const pthread_condattr_t *attr, clockid_t *clock_id)
+{
+    *clock_id = ( ((attr->__dummy) >> 1) & ((1 << COND_NWAITERS_SHIFT) - 1) );
+    return 0;
+}
+
+int pthread_condattr_setclock (pthread_condattr_t *attr, clockid_t clock_id)
+{
+  /* Only a few clocks are allowed.  CLOCK_REALTIME is always allowed.
+     CLOCK_MONOTONIC only if the kernel has the necessary support.  */
+  if (clock_id == CLOCK_MONOTONIC)
+    {
+#ifndef __ASSUME_POSIX_TIMERS
+# ifdef __NR_clock_getres
+      /* Check whether the clock is available.  */
+      static int avail;
+
+      if (avail == 0)
+	{
+	  struct timespec ts;
+
+	  INTERNAL_SYSCALL_DECL (err);
+	  int val;
+	  val = INTERNAL_SYSCALL (clock_getres, err, 2, CLOCK_MONOTONIC, &ts);
+	  avail = INTERNAL_SYSCALL_ERROR_P (val, err) ? -1 : 1;
+	}
+
+      if (avail < 0)
+# endif
+	/* Not available.  */
+	return EINVAL;
+#endif
+    }
+  else if (clock_id != CLOCK_REALTIME)
+    /* If more clocks are allowed some day the storing of the clock ID
+       in the pthread_cond_t structure needs to be adjusted.  */
+    return EINVAL;
+
+  /* Make sure the value fits in the bits we reserved.  */
+  assert (clock_id < (1 << COND_NWAITERS_SHIFT));
+
+  (attr->__dummy) = ( ((attr->__dummy) & ~(1 << (COND_NWAITERS_SHIFT + 1)) & ~1) | (clock_id << 1) );
+
+  return 0;
+}
diff -Naur uClibc/libpthread/linuxthreads/mutex.c uClibc.patch/libpthread/linuxthreads/mutex.c
--- uClibc/libpthread/linuxthreads/mutex.c	2008-06-19 09:21:47.000000000 +0000
+++ uClibc.patch/libpthread/linuxthreads/mutex.c	2008-06-19 14:30:30.000000000 +0000
@@ -236,6 +236,31 @@
 strong_alias (__pthread_mutexattr_gettype, __pthread_mutexattr_getkind_np)
 weak_alias (__pthread_mutexattr_getkind_np, pthread_mutexattr_getkind_np)
 
+/*Imported from glibc-2.7 to support  pthread_mutexattr_{g,s}etprotocol*/
+int pthread_mutexattr_setprotocol (pthread_mutexattr_t *attr,   int protocol)
+{
+    if (protocol != PTHREAD_PRIO_NONE
+       && protocol != PTHREAD_PRIO_INHERIT
+       && __builtin_expect (protocol != PTHREAD_PRIO_PROTECT, 0))
+    return EINVAL;
+
+    attr->__mutexkind = ((attr->__mutexkind & ~PTHREAD_MUTEXATTR_PROTOCOL_MASK)
+                       | (protocol << PTHREAD_MUTEXATTR_PROTOCOL_SHIFT));
+
+    return 0;
+}
+
+int pthread_mutexattr_getprotocol (const pthread_mutexattr_t *attr, int *protocol)
+{
+
+    *protocol = ((attr->__mutexkind & PTHREAD_MUTEXATTR_PROTOCOL_MASK)
+                >> PTHREAD_MUTEXATTR_PROTOCOL_SHIFT);
+
+    return 0;
+}
+/*End: Imported from glibc-2.7 to support  pthread_mutexattr_{g,s}etprotocol*/
+
+
 int __pthread_mutexattr_getpshared (const pthread_mutexattr_t *attr,
 				   int *pshared)
 {
diff -Naur uClibc/libpthread/linuxthreads/sysdeps/pthread/pthread.h uClibc.patch/libpthread/linuxthreads/sysdeps/pthread/pthread.h
--- uClibc/libpthread/linuxthreads/sysdeps/pthread/pthread.h	2008-06-19 09:21:47.000000000 +0000
+++ uClibc.patch/libpthread/linuxthreads/sysdeps/pthread/pthread.h	2008-06-19 13:21:48.000000000 +0000
@@ -28,6 +28,17 @@
 
 __BEGIN_DECLS
 
+/* Flags in mutex attr. From glibc-2.7, to support pthread_mutexattr_{g,s}etprotocol*/
+  #ifdef __USE_UNIX98
+  /* Mutex protocols.  */
+enum
+{
+    PTHREAD_PRIO_NONE,
+    PTHREAD_PRIO_INHERIT,
+    PTHREAD_PRIO_PROTECT
+};
+#endif
+
 /* Initializers.  */
 
 #define PTHREAD_MUTEX_INITIALIZER \
@@ -154,6 +165,16 @@
 };
 #define PTHREAD_CANCELED ((void *) -1)
 
+/* Flags in mutex attr. From glibc-2.7, to support pthread_mutexattr_{g,s}etprotocol*/
+#define PTHREAD_MUTEXATTR_PROTOCOL_SHIFT        28
+#define PTHREAD_MUTEXATTR_PROTOCOL_MASK         0x30000000
+#define PTHREAD_MUTEXATTR_PRIO_CEILING_SHIFT    12
+#define PTHREAD_MUTEXATTR_PRIO_CEILING_MASK     0x00fff000
+#define PTHREAD_MUTEXATTR_FLAG_ROBUST           0x40000000
+#define PTHREAD_MUTEXATTR_FLAG_PSHARED          0x80000000
+#define PTHREAD_MUTEXATTR_FLAG_BITS \
+  (PTHREAD_MUTEXATTR_FLAG_ROBUST | PTHREAD_MUTEXATTR_FLAG_PSHARED \
+   | PTHREAD_MUTEXATTR_PROTOCOL_MASK | PTHREAD_MUTEXATTR_PRIO_CEILING_MASK)
 
 /* Function for handling threads.  */
 
@@ -373,6 +394,17 @@
 /* Return in *KIND the mutex kind attribute in *ATTR.  */
 extern int pthread_mutexattr_gettype (__const pthread_mutexattr_t *__restrict
 				      __attr, int *__restrict __kind) __THROW;
+
+/*imported from glibc-2.7*/
+/* Return in *PROTOCOL the mutex protocol attribute in *ATTR.  */
+extern int pthread_mutexattr_getprotocol (__const pthread_mutexattr_t *__restrict __attr, int *__restrict __protocol) __THROW;
+
+/*imported from glibc-2.7*/
+/* Set the mutex protocol attribute in *ATTR to PROTOCOL (either
+PTHREAD_PRIO_NONE, PTHREAD_PRIO_INHERIT, or PTHREAD_PRIO_PROTECT).  */
+extern int pthread_mutexattr_setprotocol (pthread_mutexattr_t *__attr, int __protocol) __THROW;
+
+/*End: imported from glibc-2.7*/
 #endif
 
 
@@ -424,6 +456,16 @@
 extern int pthread_condattr_setpshared (pthread_condattr_t *__attr,
 					int __pshared) __THROW;
 
+/*imported from glibc-2.7*/
+#ifdef __USE_XOPEN2K
+/* Get the clock selected for the conditon variable attribute ATTR.  */
+extern int pthread_condattr_getclock (const pthread_condattr_t *attr, clockid_t *clock_id) __THROW;
+
+/* Set the clock selected for the conditon variable attribute ATTR.  */
+extern int pthread_condattr_setclock (pthread_condattr_t *attr, clockid_t clock_id) __THROW;
+
+#endif
+/*end: imported from glibc-2.7*/
 
 #if defined __USE_UNIX98 || defined __USE_XOPEN2K
 /* Functions for handling read-write locks.  */
diff -Naur uClibc/libpthread/linuxthreads.old/condvar.c uClibc.patch/libpthread/linuxthreads.old/condvar.c
--- uClibc/libpthread/linuxthreads.old/condvar.c	2008-06-19 09:21:44.000000000 +0000
+++ uClibc.patch/libpthread/linuxthreads.old/condvar.c	2008-06-19 14:25:33.000000000 +0000
@@ -19,6 +19,10 @@
 #include <sched.h>
 #include <stddef.h>
 #include <sys/time.h>
+/*Imported from glibc-2.7 to support pthread_condattr_{g,s}etclock*/
+#include <sys/syscall.h>
+#include <assert.h>
+/*End: Imported from glibc-2.7 to support pthread_condattr_{g,s}etclock*/
 #include "pthread.h"
 #include "internals.h"
 #include "spinlock.h"
@@ -312,3 +316,56 @@
 
   return 0;
 }
+
+/*Imported from glibc-2.7 to support pthread_condattr_{g,s}etclock*/
+/* The __NWAITERS field is used as a counter and to house the number
+   of bits for other purposes.  COND_CLOCK_BITS is the number
+   of bits needed to represent the ID of the clock.  COND_NWAITERS_SHIFT
+   is the number of bits reserved for other purposes like the clock.  */
+#define COND_CLOCK_BITS         1
+#define COND_NWAITERS_SHIFT     1
+int pthread_condattr_getclock (const pthread_condattr_t *attr, clockid_t *clock_id)
+{
+    *clock_id = ( ((attr->__dummy) >> 1) & ((1 << COND_NWAITERS_SHIFT) - 1) );
+    return 0;
+}
+
+int pthread_condattr_setclock (pthread_condattr_t *attr, clockid_t clock_id)
+{
+  /* Only a few clocks are allowed.  CLOCK_REALTIME is always allowed.
+     CLOCK_MONOTONIC only if the kernel has the necessary support.  */
+  if (clock_id == CLOCK_MONOTONIC)
+    {
+#ifndef __ASSUME_POSIX_TIMERS
+# ifdef __NR_clock_getres
+      /* Check whether the clock is available.  */
+      static int avail;
+
+      if (avail == 0)
+	{
+	  struct timespec ts;
+
+	  INTERNAL_SYSCALL_DECL (err);
+	  int val;
+	  val = INTERNAL_SYSCALL (clock_getres, err, 2, CLOCK_MONOTONIC, &ts);
+	  avail = INTERNAL_SYSCALL_ERROR_P (val, err) ? -1 : 1;
+	}
+
+      if (avail < 0)
+# endif
+	/* Not available.  */
+	return EINVAL;
+#endif
+    }
+  else if (clock_id != CLOCK_REALTIME)
+    /* If more clocks are allowed some day the storing of the clock ID
+       in the pthread_cond_t structure needs to be adjusted.  */
+    return EINVAL;
+
+  /* Make sure the value fits in the bits we reserved.  */
+  assert (clock_id < (1 << COND_NWAITERS_SHIFT));
+
+  (attr->__dummy) = ( ((attr->__dummy) & ~(1 << (COND_NWAITERS_SHIFT + 1)) & ~1) | (clock_id << 1) );
+
+  return 0;
+}
diff -Naur uClibc/libpthread/linuxthreads.old/mutex.c uClibc.patch/libpthread/linuxthreads.old/mutex.c
--- uClibc/libpthread/linuxthreads.old/mutex.c	2008-06-19 09:21:44.000000000 +0000
+++ uClibc.patch/libpthread/linuxthreads.old/mutex.c	2008-06-19 14:27:10.000000000 +0000
@@ -235,6 +235,31 @@
 strong_alias (__pthread_mutexattr_gettype, __pthread_mutexattr_getkind_np)
 weak_alias (__pthread_mutexattr_getkind_np, pthread_mutexattr_getkind_np)
 
+/*Imported from glibc-2.7 to support  pthread_mutexattr_{g,s}etprotocol*/
+int pthread_mutexattr_setprotocol (pthread_mutexattr_t *attr,   int protocol)
+{
+    if (protocol != PTHREAD_PRIO_NONE
+       && protocol != PTHREAD_PRIO_INHERIT
+       && __builtin_expect (protocol != PTHREAD_PRIO_PROTECT, 0))
+    return EINVAL;
+
+    attr->__mutexkind = ((attr->__mutexkind & ~PTHREAD_MUTEXATTR_PROTOCOL_MASK)
+                       | (protocol << PTHREAD_MUTEXATTR_PROTOCOL_SHIFT));
+
+    return 0;
+}
+
+int pthread_mutexattr_getprotocol (const pthread_mutexattr_t *attr, int *protocol)
+{
+
+    *protocol = ((attr->__mutexkind & PTHREAD_MUTEXATTR_PROTOCOL_MASK)
+                >> PTHREAD_MUTEXATTR_PROTOCOL_SHIFT);
+
+    return 0;
+}
+
+/*End: Imported from glibc-2.7 to support  pthread_mutexattr_{g,s}etprotocol*/
+
 int __pthread_mutexattr_getpshared (const pthread_mutexattr_t *attr attribute_unused,
 				   int *pshared) attribute_hidden;
 int __pthread_mutexattr_getpshared (const pthread_mutexattr_t *attr attribute_unused,
diff -Naur uClibc/libpthread/linuxthreads.old/sysdeps/pthread/pthread.h uClibc.patch/libpthread/linuxthreads.old/sysdeps/pthread/pthread.h
--- uClibc/libpthread/linuxthreads.old/sysdeps/pthread/pthread.h	2008-06-19 09:21:44.000000000 +0000
+++ uClibc.patch/libpthread/linuxthreads.old/sysdeps/pthread/pthread.h	2008-06-19 13:20:20.000000000 +0000
@@ -28,6 +28,17 @@
 
 __BEGIN_DECLS
 
+/* Flags in mutex attr. From glibc-2.7, to support pthread_mutexattr_{g,s}etprotocol*/
+#ifdef __USE_UNIX98
+/* Mutex protocols.  */
+enum
+{
+    PTHREAD_PRIO_NONE,
+    PTHREAD_PRIO_INHERIT,
+    PTHREAD_PRIO_PROTECT
+};
+#endif
+
 /* Initializers.  */
 
 #define PTHREAD_MUTEX_INITIALIZER \
@@ -154,6 +165,16 @@
 };
 #define PTHREAD_CANCELED ((void *) -1)
 
+/* Flags in mutex attr. From glibc-2.7, to support pthread_mutexattr_{g,s}etprotocol*/
+#define PTHREAD_MUTEXATTR_PROTOCOL_SHIFT        28
+#define PTHREAD_MUTEXATTR_PROTOCOL_MASK         0x30000000
+#define PTHREAD_MUTEXATTR_PRIO_CEILING_SHIFT    12
+#define PTHREAD_MUTEXATTR_PRIO_CEILING_MASK     0x00fff000
+#define PTHREAD_MUTEXATTR_FLAG_ROBUST           0x40000000
+#define PTHREAD_MUTEXATTR_FLAG_PSHARED          0x80000000
+#define PTHREAD_MUTEXATTR_FLAG_BITS \
+  (PTHREAD_MUTEXATTR_FLAG_ROBUST | PTHREAD_MUTEXATTR_FLAG_PSHARED \
+   | PTHREAD_MUTEXATTR_PROTOCOL_MASK | PTHREAD_MUTEXATTR_PRIO_CEILING_MASK)
 
 /* Function for handling threads.  */
 
@@ -377,6 +398,17 @@
 /* Return in *KIND the mutex kind attribute in *ATTR.  */
 extern int pthread_mutexattr_gettype (__const pthread_mutexattr_t *__restrict
 				      __attr, int *__restrict __kind) __THROW;
+
+/*imported from glibc-2.7*/
+/* Return in *PROTOCOL the mutex protocol attribute in *ATTR.  */
+extern int pthread_mutexattr_getprotocol (__const pthread_mutexattr_t *__restrict __attr, int *__restrict __protocol) __THROW;
+
+/*imported from glibc-2.7*/
+/* Set the mutex protocol attribute in *ATTR to PROTOCOL (either
+PTHREAD_PRIO_NONE, PTHREAD_PRIO_INHERIT, or PTHREAD_PRIO_PROTECT).  */
+extern int pthread_mutexattr_setprotocol (pthread_mutexattr_t *__attr, int __protocol) __THROW;
+/*End: imported from glibc-2.7*/
+
 #endif
 
 
@@ -428,6 +460,16 @@
 extern int pthread_condattr_setpshared (pthread_condattr_t *__attr,
 					int __pshared) __THROW;
 
+/*imported from glibc-2.7*/
+#ifdef __USE_XOPEN2K
+/* Get the clock selected for the conditon variable attribute ATTR.  */
+extern int pthread_condattr_getclock (const pthread_condattr_t *attr, clockid_t *clock_id) __THROW;
+
+/* Set the clock selected for the conditon variable attribute ATTR.  */
+extern int pthread_condattr_setclock (pthread_condattr_t *attr, clockid_t clock_id) __THROW;
+
+#endif
+/*end: imported from glibc-2.7*/
 
 #if defined __USE_UNIX98 || defined __USE_XOPEN2K
 /* Functions for handling read-write locks.  */
_______________________________________________
uClibc mailing list
uClibc@uclibc.org
http://busybox.net/cgi-bin/mailman/listinfo/uclibc

Reply via email to