This is the mail archive of the libc-alpha@sourceware.org mailing list for the glibc project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: [PATCH] Clean pthread functions namespace for C11 threads


Functions needed to implement threads.h functions that aren't covered
in that patch do already have a weak alias (e.g. __nanosleep) or are
defined as "versioned symbols" (e.g. __pthread_create or
__pthread_cond_*) what allows them to be redefined by the user
externally (I'm not really sure about this last topic as today has
been the first time I have read about it).

I made a list with the equivalent functions between POSIX functions
and threads.h functions, I don't know if these are actually enough,
but this is the list I originally made:

thrd_create <-> pthread_create
thrd_exit <-> pthread_exit
thrd_sleep <-> nanosleep
thrd_current <-> pthread_self
thrd_join <-> pthread_join
thrd_detach <-> pthread_detach
thrd_yield <-> sched_yield

mtx_init <-> pthread_mutex_init
mtx_destroy <-> pthread_mutex_destroy
mtx_lock <-> pthread_mutex_lock
mtx_unlock <-> pthread_mutex_unlock
mtx_trylock <-> pthread_mutex_trylock
mtx_timedlock <-> pthread_mutex_timedlock

cnd_init <-> pthread_cond_init
cnd_destroy <-> pthread_cond_destroy
cnd_wait <-> pthread_cond_wait
cnd_signal <-> pthread_cond_signal
cnd_broadcast <-> pthread_cond_broadcast
cnd_timedwait <-> pthread_cond_timedwait

tss_create <-> pthread_key_create
tss_delete <-> pthread_key_delete
tss_set <-> pthread_setspecific
tss_get <-> pthread_getspecific

It's true that during the implementation of mtx_init, I had to use
pthread_mutexattr_init and pthread_mutex_settype, that weren't
initially in my plans. Do you think more functions are affected apart
from these?

I have attached a fixed patch for lacking spaces in some weak_alias in
the previous version.

Cheers.

2015-06-25 23:52 GMT+02:00 Joseph Myers <joseph@codesourcery.com>:
> There are various places where this patch is missing a space before the
> '(' in calls to weak_alias.
>
> I expect there are lots of other POSIX functions called from pthreads (and
> so called indirectly from C11 threads functions) where you'll need to move
> to calling implementation-namespace versions (which may or may not already
> exist) - will those be addressed in a later patch in the series?  (Adding
> threads.h to the headers tested for ISO11 in conform/, with corresponding
> expectations for header contents, will allow you to find such namespace
> issues through the linknamespace test results, but only once you actually
> have the C11 threads functions implemented.)
>
> --
> Joseph S. Myers
> joseph@codesourcery.com



-- 
Juan Manuel Torres Palma.
Computer Science Student at Universidad de Granada.
commit b491c34b9d17c50d040c004cd16719f8135740db
Author: Juan Manuel Torres Palma <jmtorrespalma@gmail.com>
Date:   Fri Jun 26 00:11:34 2015 +0200

    Clean pthread functions namespaces for C11 threads
    
    This patch creates weak aliases for all conflicting functions with
    C11 threads.h functions, allowong user to redefine them. Some
    functions do not need aliases as they have already been defined as
    versioned symbols.

diff --git a/nptl/pthreadP.h b/nptl/pthreadP.h
index 84a7105..b997b22 100644
--- a/nptl/pthreadP.h
+++ b/nptl/pthreadP.h
@@ -414,6 +414,8 @@ extern int __pthread_mutex_init (pthread_mutex_t *__mutex,
 extern int __pthread_mutex_destroy (pthread_mutex_t *__mutex);
 extern int __pthread_mutex_trylock (pthread_mutex_t *_mutex);
 extern int __pthread_mutex_lock (pthread_mutex_t *__mutex);
+extern int __pthread_mutex_timedlock (pthread_mutex_t *__mutex,
+     const struct timespec *__abstime);
 extern int __pthread_mutex_cond_lock (pthread_mutex_t *__mutex)
      attribute_hidden internal_function;
 extern void __pthread_mutex_cond_lock_adjust (pthread_mutex_t *__mutex)
@@ -477,6 +479,7 @@ extern int __pthread_cond_timedwait (pthread_cond_t *cond,
 extern int __pthread_condattr_destroy (pthread_condattr_t *attr);
 extern int __pthread_condattr_init (pthread_condattr_t *attr);
 extern int __pthread_key_create (pthread_key_t *key, void (*destr) (void *));
+extern int __pthread_key_delete (pthread_key_t key);
 extern void *__pthread_getspecific (pthread_key_t key);
 extern int __pthread_setspecific (pthread_key_t key, const void *value);
 extern int __pthread_once (pthread_once_t *once_control,
@@ -485,8 +488,10 @@ extern int __pthread_atfork (void (*prepare) (void), void (*parent) (void),
 			     void (*child) (void));
 extern pthread_t __pthread_self (void);
 extern int __pthread_equal (pthread_t thread1, pthread_t thread2);
+extern int __pthread_detach (pthread_t th);
 extern int __pthread_kill (pthread_t threadid, int signo);
 extern void __pthread_exit (void *value) __attribute__ ((__noreturn__));
+extern int __pthread_join (pthread_t threadid, void **thread_return);
 extern int __pthread_setcanceltype (int type, int *oldtype);
 extern int __pthread_enable_asynccancel (void) attribute_hidden;
 extern void __pthread_disable_asynccancel (int oldtype)
diff --git a/nptl/pthread_detach.c b/nptl/pthread_detach.c
index aa735f6..c7628f1 100644
--- a/nptl/pthread_detach.c
+++ b/nptl/pthread_detach.c
@@ -22,7 +22,7 @@
 
 
 int
-pthread_detach (th)
+__pthread_detach (th)
      pthread_t th;
 {
   struct pthread *pd = (struct pthread *) th;
@@ -54,3 +54,4 @@ pthread_detach (th)
 
   return result;
 }
+weak_alias (__pthread_detach, pthread_detach)
diff --git a/nptl/pthread_equal.c b/nptl/pthread_equal.c
index 69f4c1b..2e730df 100644
--- a/nptl/pthread_equal.c
+++ b/nptl/pthread_equal.c
@@ -26,4 +26,4 @@ __pthread_equal (thread1, thread2)
 {
   return thread1 == thread2;
 }
-strong_alias (__pthread_equal, pthread_equal)
+weak_alias (__pthread_equal, pthread_equal)
diff --git a/nptl/pthread_exit.c b/nptl/pthread_exit.c
index a60adbd..9ec8b0d 100644
--- a/nptl/pthread_exit.c
+++ b/nptl/pthread_exit.c
@@ -27,7 +27,7 @@ __pthread_exit (void *value)
 
   __do_cancel ();
 }
-strong_alias (__pthread_exit, pthread_exit)
+weak_alias (__pthread_exit, pthread_exit)
 
 /* After a thread terminates, __libc_start_main decrements
    __nptl_nthreads defined in pthread_create.c.  */
diff --git a/nptl/pthread_getspecific.c b/nptl/pthread_getspecific.c
index 0bee354..a5e5f45 100644
--- a/nptl/pthread_getspecific.c
+++ b/nptl/pthread_getspecific.c
@@ -64,5 +64,5 @@ __pthread_getspecific (key)
 
   return result;
 }
-strong_alias (__pthread_getspecific, pthread_getspecific)
+weak_alias (__pthread_getspecific, pthread_getspecific)
 hidden_def (__pthread_getspecific)
diff --git a/nptl/pthread_join.c b/nptl/pthread_join.c
index c841ff9..9635b08 100644
--- a/nptl/pthread_join.c
+++ b/nptl/pthread_join.c
@@ -37,7 +37,7 @@ cleanup (void *arg)
 
 
 int
-pthread_join (pthread_t threadid, void **thread_return)
+__pthread_join (pthread_t threadid, void **thread_return)
 {
   struct pthread *pd = (struct pthread *) threadid;
 
@@ -115,3 +115,4 @@ pthread_join (pthread_t threadid, void **thread_return)
 
   return result;
 }
+weak_alias (__pthread_join, pthread_join)
diff --git a/nptl/pthread_key_create.c b/nptl/pthread_key_create.c
index a642c69..9beec6b 100644
--- a/nptl/pthread_key_create.c
+++ b/nptl/pthread_key_create.c
@@ -49,5 +49,5 @@ __pthread_key_create (key, destr)
 
   return EAGAIN;
 }
-strong_alias (__pthread_key_create, pthread_key_create)
+weak_alias (__pthread_key_create, pthread_key_create)
 hidden_def (__pthread_key_create)
diff --git a/nptl/pthread_key_delete.c b/nptl/pthread_key_delete.c
index bd9b4a2..f201b71 100644
--- a/nptl/pthread_key_delete.c
+++ b/nptl/pthread_key_delete.c
@@ -22,7 +22,7 @@
 
 
 int
-pthread_key_delete (key)
+__pthread_key_delete (key)
      pthread_key_t key;
 {
   int result = EINVAL;
@@ -40,3 +40,4 @@ pthread_key_delete (key)
 
   return result;
 }
+weak_alias (__pthread_key_delete, pthread_key_delete)
diff --git a/nptl/pthread_mutex_destroy.c b/nptl/pthread_mutex_destroy.c
index f6089df..3d40205 100644
--- a/nptl/pthread_mutex_destroy.c
+++ b/nptl/pthread_mutex_destroy.c
@@ -37,5 +37,5 @@ __pthread_mutex_destroy (mutex)
 
   return 0;
 }
-strong_alias (__pthread_mutex_destroy, pthread_mutex_destroy)
+weak_alias (__pthread_mutex_destroy, pthread_mutex_destroy)
 hidden_def (__pthread_mutex_destroy)
diff --git a/nptl/pthread_mutex_init.c b/nptl/pthread_mutex_init.c
index d71cfef..6b9ab16 100644
--- a/nptl/pthread_mutex_init.c
+++ b/nptl/pthread_mutex_init.c
@@ -148,5 +148,5 @@ __pthread_mutex_init (mutex, mutexattr)
 
   return 0;
 }
-strong_alias (__pthread_mutex_init, pthread_mutex_init)
+weak_alias (__pthread_mutex_init, pthread_mutex_init)
 hidden_def (__pthread_mutex_init)
diff --git a/nptl/pthread_mutex_lock.c b/nptl/pthread_mutex_lock.c
index 9607512..4ee4280 100644
--- a/nptl/pthread_mutex_lock.c
+++ b/nptl/pthread_mutex_lock.c
@@ -516,7 +516,7 @@ __pthread_mutex_lock_full (pthread_mutex_t *mutex)
   return 0;
 }
 #ifndef __pthread_mutex_lock
-strong_alias (__pthread_mutex_lock, pthread_mutex_lock)
+weak_alias (__pthread_mutex_lock, pthread_mutex_lock)
 hidden_def (__pthread_mutex_lock)
 #endif
 
diff --git a/nptl/pthread_mutex_timedlock.c b/nptl/pthread_mutex_timedlock.c
index 109a46a..4b96a95 100644
--- a/nptl/pthread_mutex_timedlock.c
+++ b/nptl/pthread_mutex_timedlock.c
@@ -40,7 +40,7 @@
 #endif
 
 int
-pthread_mutex_timedlock (mutex, abstime)
+__pthread_mutex_timedlock (mutex, abstime)
      pthread_mutex_t *mutex;
      const struct timespec *abstime;
 {
@@ -522,3 +522,4 @@ pthread_mutex_timedlock (mutex, abstime)
  out:
   return result;
 }
+weak_alias (__pthread_mutex_timedlock, pthread_mutex_timedlock)
diff --git a/nptl/pthread_mutex_trylock.c b/nptl/pthread_mutex_trylock.c
index 33df384..229afdf 100644
--- a/nptl/pthread_mutex_trylock.c
+++ b/nptl/pthread_mutex_trylock.c
@@ -404,6 +404,6 @@ __pthread_mutex_trylock (mutex)
 
 #ifndef __pthread_mutex_trylock
 #ifndef pthread_mutex_trylock
-strong_alias (__pthread_mutex_trylock, pthread_mutex_trylock)
+weak_alias (__pthread_mutex_trylock, pthread_mutex_trylock)
 #endif
 #endif
diff --git a/nptl/pthread_mutex_unlock.c b/nptl/pthread_mutex_unlock.c
index 80939ba..d9ff351 100644
--- a/nptl/pthread_mutex_unlock.c
+++ b/nptl/pthread_mutex_unlock.c
@@ -314,5 +314,5 @@ __pthread_mutex_unlock (mutex)
 {
   return __pthread_mutex_unlock_usercnt (mutex, 1);
 }
-strong_alias (__pthread_mutex_unlock, pthread_mutex_unlock)
+weak_alias (__pthread_mutex_unlock, pthread_mutex_unlock)
 hidden_def (__pthread_mutex_unlock)
diff --git a/nptl/pthread_self.c b/nptl/pthread_self.c
index d6ba45c..422151e 100644
--- a/nptl/pthread_self.c
+++ b/nptl/pthread_self.c
@@ -25,4 +25,4 @@ __pthread_self (void)
 {
   return (pthread_t) THREAD_SELF;
 }
-strong_alias (__pthread_self, pthread_self)
+weak_alias (__pthread_self, pthread_self)
diff --git a/nptl/pthread_setspecific.c b/nptl/pthread_setspecific.c
index a9cf26c..36b42f8 100644
--- a/nptl/pthread_setspecific.c
+++ b/nptl/pthread_setspecific.c
@@ -91,5 +91,5 @@ __pthread_setspecific (key, value)
 
   return 0;
 }
-strong_alias (__pthread_setspecific, pthread_setspecific)
+weak_alias (__pthread_setspecific, pthread_setspecific)
 hidden_def (__pthread_setspecific)

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]