pspinlock.c 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  1. /* POSIX spinlock implementation. M68k 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
  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__ (
  24. #if !defined(__mcoldfire__) && !defined(__mcf5200__) && !defined(__m68000)
  25. "tas %1; sne %0"
  26. #else
  27. "bset #7,%1; sne %0"
  28. #endif
  29. : "=dm" (val), "=m" (*lock)
  30. : "m" (*lock)
  31. : "cc");
  32. while (val);
  33. return 0;
  34. }
  35. weak_alias (__pthread_spin_lock, pthread_spin_lock)
  36. int
  37. __pthread_spin_trylock (pthread_spinlock_t *lock)
  38. {
  39. unsigned int val;
  40. __asm__ __volatile__ (
  41. #if !defined(__mcoldfire__) && !defined(__mcf5200__) && !defined(__m68000)
  42. "tas %1; sne %0"
  43. #else
  44. "bset #7,%1; sne %0"
  45. #endif
  46. : "=dm" (val), "=m" (*lock)
  47. : "m" (*lock)
  48. : "cc");
  49. return val ? EBUSY : 0;
  50. }
  51. weak_alias (__pthread_spin_trylock, pthread_spin_trylock)
  52. int
  53. __pthread_spin_unlock (pthread_spinlock_t *lock)
  54. {
  55. return *lock = 0;
  56. }
  57. weak_alias (__pthread_spin_unlock, pthread_spin_unlock)
  58. int
  59. __pthread_spin_init (pthread_spinlock_t *lock, int pshared)
  60. {
  61. /* We can ignore the `pshared' parameter. Since we are busy-waiting
  62. all processes which can access the memory location `lock' points
  63. to can use the spinlock. */
  64. return *lock = 0;
  65. }
  66. weak_alias (__pthread_spin_init, pthread_spin_init)
  67. int
  68. __pthread_spin_destroy (pthread_spinlock_t *lock)
  69. {
  70. /* Nothing to do. */
  71. return 0;
  72. }
  73. weak_alias (__pthread_spin_destroy, pthread_spin_destroy)