pspinlock.c 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. /* POSIX spinlock implementation. PowerPC version.
  2. Copyright (C) 2000, 2003 Free Software Foundation, Inc.
  3. This file is part of the GNU C Library.
  4. The GNU C Library is free software; you can redistribute it and/or
  5. modify it under the terms of the GNU Lesser General Public License as
  6. published by the Free Software Foundation; either version 2.1 of the
  7. License, or (at your option) any later version.
  8. The GNU C Library is distributed in the hope that it will be useful,
  9. but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  11. Lesser General Public License for more details.
  12. You should have received a copy of the GNU Lesser General Public
  13. License along with the GNU C Library; see the file COPYING.LIB. If not,
  14. write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
  15. Boston, MA 02111-1307, USA. */
  16. #include <errno.h>
  17. #include <pthread.h>
  18. #include "internals.h"
  19. int
  20. __pthread_spin_lock (pthread_spinlock_t *lock)
  21. {
  22. while (! __compare_and_swap ((long int *)lock, 0, 1))
  23. ;
  24. return 0;
  25. }
  26. weak_alias (__pthread_spin_lock, pthread_spin_lock)
  27. int
  28. __pthread_spin_trylock (pthread_spinlock_t *lock)
  29. {
  30. return __compare_and_swap ((long int *)lock, 0, 1) ? 0 : EBUSY;
  31. }
  32. weak_alias (__pthread_spin_trylock, pthread_spin_trylock)
  33. int
  34. __pthread_spin_unlock (pthread_spinlock_t *lock)
  35. {
  36. MEMORY_BARRIER ();
  37. *lock = 0;
  38. return 0;
  39. }
  40. weak_alias (__pthread_spin_unlock, pthread_spin_unlock)
  41. int
  42. __pthread_spin_init (pthread_spinlock_t *lock, int pshared)
  43. {
  44. /* We can ignore the `pshared' parameter. Since we are busy-waiting
  45. all processes which can access the memory location `lock' points
  46. to can use the spinlock. */
  47. *lock = 0;
  48. return 0;
  49. }
  50. weak_alias (__pthread_spin_init, pthread_spin_init)
  51. int
  52. __pthread_spin_destroy (pthread_spinlock_t *lock)
  53. {
  54. /* Nothing to do. */
  55. return 0;
  56. }
  57. weak_alias (__pthread_spin_destroy, pthread_spin_destroy)