pspinlock.c 2.5 KB

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