pspinlock.c 2.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  1. /* POSIX spinlock implementation. MIPS version.
  2. Copyright (C) 2000, 2002, 2003, 2004 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 <sgidefs.h>
  18. #include <sys/tas.h>
  19. #include "internals.h"
  20. /* This implementation is similar to the one used in the Linux kernel. */
  21. int
  22. __pthread_spin_lock (pthread_spinlock_t *lock)
  23. {
  24. unsigned int tmp1, tmp2;
  25. __asm__ __volatile__
  26. ("\t\t\t# spin_lock\n"
  27. "1:\n\t"
  28. ".set push\n\t"
  29. #if _MIPS_SIM == _ABIO32
  30. ".set mips2\n\t"
  31. #endif
  32. "ll %1,%3\n\t"
  33. "li %2,1\n\t"
  34. "bnez %1,1b\n\t"
  35. "sc %2,%0\n\t"
  36. ".set pop\n\t"
  37. "beqz %2,1b"
  38. : "=m" (*lock), "=&r" (tmp1), "=&r" (tmp2)
  39. : "m" (*lock)
  40. : "memory");
  41. return 0;
  42. }
  43. weak_alias (__pthread_spin_lock, pthread_spin_lock)
  44. int
  45. __pthread_spin_trylock (pthread_spinlock_t *lock)
  46. {
  47. /* To be done. */
  48. return 0;
  49. }
  50. weak_alias (__pthread_spin_trylock, pthread_spin_trylock)
  51. int
  52. __pthread_spin_unlock (pthread_spinlock_t *lock)
  53. {
  54. __asm__ __volatile__
  55. ("\t\t\t# spin_unlock\n\t"
  56. "sw $0,%0"
  57. : "=m" (*lock)
  58. :
  59. : "memory");
  60. return 0;
  61. }
  62. weak_alias (__pthread_spin_unlock, pthread_spin_unlock)
  63. int
  64. __pthread_spin_init (pthread_spinlock_t *lock, int pshared)
  65. {
  66. /* We can ignore the `pshared' parameter. Since we are busy-waiting
  67. all processes which can access the memory location `lock' points
  68. to can use the spinlock. */
  69. *lock = 0;
  70. return 0;
  71. }
  72. weak_alias (__pthread_spin_init, pthread_spin_init)
  73. int
  74. __pthread_spin_destroy (pthread_spinlock_t *lock)
  75. {
  76. /* Nothing to do. */
  77. return 0;
  78. }
  79. weak_alias (__pthread_spin_destroy, pthread_spin_destroy)