pspinlock.c 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. /* POSIX spinlock implementation. Arm version.
  2. Copyright (C) 2000 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. unsigned int val;
  23. do
  24. asm volatile ("swp %0, %1, [%2]"
  25. : "=r" (val)
  26. : "0" (1), "r" (lock)
  27. : "memory");
  28. while (val != 0);
  29. return 0;
  30. }
  31. weak_alias (__pthread_spin_lock, pthread_spin_lock)
  32. int
  33. __pthread_spin_trylock (pthread_spinlock_t *lock)
  34. {
  35. unsigned int val;
  36. asm volatile ("swp %0, %1, [%2]"
  37. : "=r" (val)
  38. : "0" (1), "r" (lock)
  39. : "memory");
  40. return val ? EBUSY : 0;
  41. }
  42. weak_alias (__pthread_spin_trylock, pthread_spin_trylock)
  43. int
  44. __pthread_spin_unlock (pthread_spinlock_t *lock)
  45. {
  46. return *lock = 0;
  47. }
  48. weak_alias (__pthread_spin_unlock, pthread_spin_unlock)
  49. int
  50. __pthread_spin_init (pthread_spinlock_t *lock, int pshared)
  51. {
  52. /* We can ignore the `pshared' parameter. Since we are busy-waiting
  53. all processes which can access the memory location `lock' points
  54. to can use the spinlock. */
  55. return *lock = 0;
  56. }
  57. weak_alias (__pthread_spin_init, pthread_spin_init)
  58. int
  59. __pthread_spin_destroy (pthread_spinlock_t *lock)
  60. {
  61. /* Nothing to do. */
  62. return 0;
  63. }
  64. weak_alias (__pthread_spin_destroy, pthread_spin_destroy)