pspinlock.c 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. /* POSIX spinlock implementation. SH version.
  2. Copyright (C) 2000, 2001 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
  14. not, see <http://www.gnu.org/licenses/>. */
  15. #include <errno.h>
  16. #include <pthread.h>
  17. #include "internals.h"
  18. int
  19. __pthread_spin_lock (pthread_spinlock_t *lock)
  20. {
  21. unsigned int val;
  22. do
  23. __asm__ __volatile__ ("tas.b @%1; movt %0"
  24. : "=r" (val)
  25. : "r" (lock)
  26. : "memory");
  27. while (val == 0);
  28. return 0;
  29. }
  30. weak_alias (__pthread_spin_lock, pthread_spin_lock)
  31. int
  32. __pthread_spin_trylock (pthread_spinlock_t *lock)
  33. {
  34. unsigned int val;
  35. __asm__ __volatile__ ("tas.b @%1; movt %0"
  36. : "=r" (val)
  37. : "r" (lock)
  38. : "memory");
  39. return val ? 0 : EBUSY;
  40. }
  41. weak_alias (__pthread_spin_trylock, pthread_spin_trylock)
  42. int
  43. __pthread_spin_unlock (pthread_spinlock_t *lock)
  44. {
  45. return *lock = 0;
  46. }
  47. weak_alias (__pthread_spin_unlock, pthread_spin_unlock)
  48. int
  49. __pthread_spin_init (pthread_spinlock_t *lock, int pshared)
  50. {
  51. /* We can ignore the `pshared' parameter. Since we are busy-waiting
  52. all processes which can access the memory location `lock' points
  53. to can use the spinlock. */
  54. return *lock = 0;
  55. }
  56. weak_alias (__pthread_spin_init, pthread_spin_init)
  57. int
  58. __pthread_spin_destroy (pthread_spinlock_t *lock)
  59. {
  60. /* Nothing to do. */
  61. return 0;
  62. }
  63. weak_alias (__pthread_spin_destroy, pthread_spin_destroy)