pspinlock.c 2.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  1. /* POSIX spinlock implementation. SPARC32 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. /* This implementation is similar to the one used in the Linux kernel. */
  20. int
  21. __pthread_spin_lock (pthread_spinlock_t *lock)
  22. {
  23. __asm__ __volatile__
  24. ("1: ldstub [%0], %%g2\n"
  25. " orcc %%g2, 0x0, %%g0\n"
  26. " bne,a 2f\n"
  27. " ldub [%0], %%g2\n"
  28. ".subsection 2\n"
  29. "2: orcc %%g2, 0x0, %%g0\n"
  30. " bne,a 2b\n"
  31. " ldub [%0], %%g2\n"
  32. " b,a 1b\n"
  33. ".previous"
  34. : /* no outputs */
  35. : "r" (lock)
  36. : "g2", "memory", "cc");
  37. return 0;
  38. }
  39. weak_alias (__pthread_spin_lock, pthread_spin_lock)
  40. int
  41. __pthread_spin_trylock (pthread_spinlock_t *lock)
  42. {
  43. int result;
  44. __asm__ __volatile__
  45. ("ldstub [%1], %0"
  46. : "=r" (result)
  47. : "r" (lock)
  48. : "memory");
  49. return result == 0 ? 0 : EBUSY;
  50. }
  51. weak_alias (__pthread_spin_trylock, pthread_spin_trylock)
  52. int
  53. __pthread_spin_unlock (pthread_spinlock_t *lock)
  54. {
  55. *lock = 0;
  56. return 0;
  57. }
  58. weak_alias (__pthread_spin_unlock, pthread_spin_unlock)
  59. int
  60. __pthread_spin_init (pthread_spinlock_t *lock, int pshared)
  61. {
  62. /* We can ignore the `pshared' parameter. Since we are busy-waiting
  63. all processes which can access the memory location `lock' points
  64. to can use the spinlock. */
  65. *lock = 0;
  66. return 0;
  67. }
  68. weak_alias (__pthread_spin_init, pthread_spin_init)
  69. int
  70. __pthread_spin_destroy (pthread_spinlock_t *lock)
  71. {
  72. /* Nothing to do. */
  73. return 0;
  74. }
  75. weak_alias (__pthread_spin_destroy, pthread_spin_destroy)