pspinlock.c 2.4 KB

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