diff options
author | Neal H. Walfield <neal@gnu.org> | 2007-11-20 16:23:24 +0000 |
---|---|---|
committer | Thomas Schwinge <tschwinge@gnu.org> | 2009-04-07 23:05:35 +0200 |
commit | 43e3246eb6a26162ef931dadcd4a8a649c57289b (patch) | |
tree | 80cac95ce1c8b948f2a2a4ff980385b0dcbeec43 /sysdeps/generic/sem-post.c | |
parent | 7373049ff9aac3dbfe088da7d30b2724d15fa67a (diff) | |
parent | 8caaa8379e5a1500863792514189d6e8f414dcaf (diff) |
2007-11-20 Neal H. Walfield <neal@gnu.org>
Merge changes from mainline Hurd. Update L4 bits to compile with
those changes.
* sysdeps/l4/pt-block.c (__pthread_block): Call l4_receive, not
L4_Receive.
* sysdeps/l4/pt-create-np.c (pthread_create_from_l4_tid_np): Don't
pass TID to __pthread_create_internal. Emit a warning.
* sysdeps/l4/pt-stack-alloc.c (allocate_page): Remove function.
(__pthread_stack_alloc): Don't require that STACKSIZE is equal to
__pthread_stacksize. Call mmap.
* sysdeps/l4/pt-thread-halt.c (__pthread_thread_halt): Take
additional argument, need_dealloc. Call __pthread_dealloc. Stop
the thread.
* sysdeps/l4/hurd/pt-sysdep.c (init_routine): When calling
__pthread_create_internal, don't pass the tid.
* tests/test-1.c (main): Use pthread_mutex_init, not
PTHREAD_MUTEX_INITIALIZER.
* pthread/pt-alloc.c: Don't include <bits/atomic.h>. Include
<atomic.h>.
(__pthread_free_threads): Make it an atomicptr_t, not an
__atomicptr_t.
(__pthread_alloc): Don't use __atomicptr_compare_and_swap, use
atomic_compare_and_exchange_val_acq.
* pthread/pt-create.c: Don't include <bits/atomic.h>. Include
<atomic.h>.
(__pthread_total): Make it an atomic_fast32_t, not an __atomic_t.
(__pthread_create_internal): Use atomic_increment and
atomic_decrement, not __atomic_inc and __atomic_dec.
* pthread/pt-dealloc.c: Don't include <bits/atomic.h>. Include
<atomic.h>.
(__pthread_free_threads): Make it an atomicptr_t, not an
__atomicptr_t.
(__pthread_dealloc): Use atomic_compare_and_exchange_val_acq, not
__atomicptr_compare_and_swap.
* pthread/pt-exit.c: Don't include <bits/atomic.h>. Include
<atomic.h>.
(pthread_exit): Use atomic_decrement_and_test, not
__atomic_dec_and_test.
* pthread/pt-internal.h: Don't include <bits/atomic.h>. Include
<atomic.h>.
(__pthread_total): Make it an atomic_fast32_t, not an __atomic_t.
* sysdeps/powerpc/bits/atomic.h: Remove file.
* sysdeps/ia32/bits/atomic.h: Likewise.
Diffstat (limited to 'sysdeps/generic/sem-post.c')
-rw-r--r-- | sysdeps/generic/sem-post.c | 62 |
1 files changed, 62 insertions, 0 deletions
diff --git a/sysdeps/generic/sem-post.c b/sysdeps/generic/sem-post.c new file mode 100644 index 00000000..0e20ea7a --- /dev/null +++ b/sysdeps/generic/sem-post.c @@ -0,0 +1,62 @@ +/* Post a semaphore. Generic version. + Copyright (C) 2005 Free Software Foundation, Inc. + This file is part of the GNU C Library. + + The GNU C Library is free software; you can redistribute it and/or + modify it under the terms of the GNU Library General Public License as + published by the Free Software Foundation; either version 2 of the + License, or (at your option) any later version. + + The GNU C Library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Library General Public License for more details. + + You should have received a copy of the GNU Library General Public + License along with the GNU C Library; see the file COPYING.LIB. If not, + write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, + Boston, MA 02111-1307, USA. */ + +#include <semaphore.h> +#include <assert.h> + +#include <pt-internal.h> + +int +__sem_post (sem_t *sem) +{ + struct __pthread *wakeup; + + __pthread_spin_lock (&sem->__lock); + if (sem->__value > 0) + /* Do a quick up. */ + { + assert (! sem->__queue); + sem->__value ++; + __pthread_spin_unlock (&sem->__lock); + return 0; + } + + if (! sem->__queue) + /* No one waiting. */ + { + sem->__value = 1; + __pthread_spin_unlock (&sem->__lock); + return 0; + } + + /* Wake someone up. */ + + /* First dequeue someone. */ + wakeup = sem->__queue; + __pthread_dequeue (wakeup); + + /* Then drop the lock and transfer control. */ + __pthread_spin_unlock (&sem->__lock); + + __pthread_wakeup (wakeup); + + return 0; +} + +strong_alias (__sem_post, sem_post); |