Message ID | 20201216015143.4084732-2-samuel.thibault@ens-lyon.org |
---|---|
State | New |
Headers | show |
Series | Move sem_open/close/unlink to sysdeps/pthread | expand |
On 15/12/2020 22:51, Samuel Thibault wrote: > This allows to easily reuse all of the sem_open/sem_close/sem_unlink > implementations in the various ports. LGTM, thanks. Reviewed-by: Adhemerval Zanella <adhemerval.zanella@linaro.org> > --- > nptl/sem_open.c | 12 +----------- > nptl/semaphoreP.h | 15 +++++++++++++++ > 2 files changed, 16 insertions(+), 11 deletions(-) > > diff --git a/nptl/sem_open.c b/nptl/sem_open.c > index 05e286002b..634bdf7425 100644 > --- a/nptl/sem_open.c > +++ b/nptl/sem_open.c > @@ -211,17 +211,7 @@ sem_open (const char *name, int oflag, ...) > struct new_sem newsem; > } sem; > > -#if __HAVE_64B_ATOMICS > - sem.newsem.data = value; > -#else > - sem.newsem.value = value << SEM_VALUE_SHIFT; > - sem.newsem.nwaiters = 0; > -#endif > - /* pad is used as a mutex on pre-v9 sparc and ignored otherwise. */ > - sem.newsem.pad = 0; > - > - /* This always is a shared semaphore. */ > - sem.newsem.private = FUTEX_SHARED; > + __new_sem_open_init (&sem.newsem, value); > > /* Initialize the remaining bytes as well. */ > memset ((char *) &sem.initsem + sizeof (struct new_sem), '\0', Ok. > diff --git a/nptl/semaphoreP.h b/nptl/semaphoreP.h > index f25ba329d7..2f8757e1f0 100644 > --- a/nptl/semaphoreP.h > +++ b/nptl/semaphoreP.h > @@ -17,6 +17,7 @@ > <https://www.gnu.org/licenses/>. */ > > #include <semaphore.h> > +#include <futex-internal.h> > #include "pthreadP.h" > > #define SEM_SHM_PREFIX "sem." > @@ -42,6 +43,20 @@ extern int __sem_mappings_lock attribute_hidden; > /* Comparison function for search in tree with existing mappings. */ > extern int __sem_search (const void *a, const void *b) attribute_hidden; > > +static inline void __new_sem_open_init (struct new_sem *sem, unsigned value) > +{ > +#if __HAVE_64B_ATOMICS > + sem->data = value; > +#else > + sem->value = value << SEM_VALUE_SHIFT; > + sem->nwaiters = 0; > +#endif > + /* pad is used as a mutex on pre-v9 sparc and ignored otherwise. */ > + sem->pad = 0; > + > + /* This always is a shared semaphore. */ > + sem->private = FUTEX_SHARED; > +} > > /* Prototypes of functions with multiple interfaces. */ > extern int __new_sem_init (sem_t *sem, int pshared, unsigned int value); > Ok.
Adhemerval Zanella, le mer. 16 déc. 2020 10:25:59 -0300, a ecrit: > On 15/12/2020 22:51, Samuel Thibault wrote: > > This allows to easily reuse all of the sem_open/sem_close/sem_unlink > > implementations in the various ports. > > LGTM, thanks. Thanks for the prompt feedback! Samuel
diff --git a/nptl/sem_open.c b/nptl/sem_open.c index 05e286002b..634bdf7425 100644 --- a/nptl/sem_open.c +++ b/nptl/sem_open.c @@ -211,17 +211,7 @@ sem_open (const char *name, int oflag, ...) struct new_sem newsem; } sem; -#if __HAVE_64B_ATOMICS - sem.newsem.data = value; -#else - sem.newsem.value = value << SEM_VALUE_SHIFT; - sem.newsem.nwaiters = 0; -#endif - /* pad is used as a mutex on pre-v9 sparc and ignored otherwise. */ - sem.newsem.pad = 0; - - /* This always is a shared semaphore. */ - sem.newsem.private = FUTEX_SHARED; + __new_sem_open_init (&sem.newsem, value); /* Initialize the remaining bytes as well. */ memset ((char *) &sem.initsem + sizeof (struct new_sem), '\0', diff --git a/nptl/semaphoreP.h b/nptl/semaphoreP.h index f25ba329d7..2f8757e1f0 100644 --- a/nptl/semaphoreP.h +++ b/nptl/semaphoreP.h @@ -17,6 +17,7 @@ <https://www.gnu.org/licenses/>. */ #include <semaphore.h> +#include <futex-internal.h> #include "pthreadP.h" #define SEM_SHM_PREFIX "sem." @@ -42,6 +43,20 @@ extern int __sem_mappings_lock attribute_hidden; /* Comparison function for search in tree with existing mappings. */ extern int __sem_search (const void *a, const void *b) attribute_hidden; +static inline void __new_sem_open_init (struct new_sem *sem, unsigned value) +{ +#if __HAVE_64B_ATOMICS + sem->data = value; +#else + sem->value = value << SEM_VALUE_SHIFT; + sem->nwaiters = 0; +#endif + /* pad is used as a mutex on pre-v9 sparc and ignored otherwise. */ + sem->pad = 0; + + /* This always is a shared semaphore. */ + sem->private = FUTEX_SHARED; +} /* Prototypes of functions with multiple interfaces. */ extern int __new_sem_init (sem_t *sem, int pshared, unsigned int value);