1
0
mirror of https://sourceware.org/git/glibc.git synced 2025-07-30 22:43:12 +03:00

sem_close: Use __twalk_r

This commit is contained in:
Florian Weimer
2019-05-10 14:17:26 +02:00
parent eb669ff5bf
commit 4aee85f96b
2 changed files with 21 additions and 13 deletions

View File

@ -1,3 +1,9 @@
2019-05-10 Florian Weimer <fweimer@redhat.com>
* nptl/sem_close.c (struct walk_closure): Define.
(walker): Adjust for __twalk_r.
(sem_close): Call __twalk_r.
2019-05-09 Adhemerval Zanella <adhemerval.zanella@linaro.org> 2019-05-09 Adhemerval Zanella <adhemerval.zanella@linaro.org>
* support/timespec.c (test_timespec_before_impl, * support/timespec.c (test_timespec_before_impl,

View File

@ -21,21 +21,20 @@
#include <sys/mman.h> #include <sys/mman.h>
#include "semaphoreP.h" #include "semaphoreP.h"
struct walk_closure
/* Global variables to parametrize the walk function. This works {
since we always have to use locks. And we have to use the twalk sem_t *the_sem;
function since the entries are not sorted wrt the mapping struct inuse_sem *rec;
address. */ };
static sem_t *the_sem;
static struct inuse_sem *rec;
static void static void
walker (const void *inodep, const VISIT which, const int depth) walker (const void *inodep, VISIT which, void *closure0)
{ {
struct walk_closure *closure = closure0;
struct inuse_sem *nodep = *(struct inuse_sem **) inodep; struct inuse_sem *nodep = *(struct inuse_sem **) inodep;
if (nodep->sem == the_sem) if (nodep->sem == closure->the_sem)
rec = nodep; closure->rec = nodep;
} }
@ -48,9 +47,12 @@ sem_close (sem_t *sem)
lll_lock (__sem_mappings_lock, LLL_PRIVATE); lll_lock (__sem_mappings_lock, LLL_PRIVATE);
/* Locate the entry for the mapping the caller provided. */ /* Locate the entry for the mapping the caller provided. */
rec = NULL; struct inuse_sem *rec;
the_sem = sem; {
__twalk (__sem_mappings, walker); struct walk_closure closure = { .the_sem = sem, .rec = NULL };
__twalk_r (__sem_mappings, walker, &closure);
rec = closure.rec;
}
if (rec != NULL) if (rec != NULL)
{ {
/* Check the reference counter. If it is going to be zero, free /* Check the reference counter. If it is going to be zero, free