pt-machine.h 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. /* Machine-dependent pthreads configuration and inline functions.
  2. Copyright (C) 1996, 1998, 2000, 2002 Free Software Foundation, Inc.
  3. This file is part of the GNU C Library.
  4. Contributed by Richard Henderson <rth@tamu.edu>.
  5. The GNU C Library is free software; you can redistribute it and/or
  6. modify it under the terms of the GNU Lesser General Public License as
  7. published by the Free Software Foundation; either version 2.1 of the
  8. License, or (at your option) any later version.
  9. The GNU C Library is distributed in the hope that it will be useful,
  10. but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  12. Lesser General Public License for more details.
  13. You should have received a copy of the GNU Lesser General Public
  14. License along with the GNU C Library; see the file COPYING.LIB. If
  15. not, write to the Free Software Foundation, Inc.,
  16. 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
  17. #ifndef _PT_MACHINE_H
  18. #define _PT_MACHINE_H 1
  19. #ifndef PT_EI
  20. # define PT_EI extern inline
  21. #endif
  22. extern long int testandset (int *spinlock);
  23. extern int __compare_and_swap (long *, long , long);
  24. /* Spinlock implementation; required. */
  25. PT_EI long int
  26. testandset (int *spinlock)
  27. {
  28. if (*spinlock)
  29. return 1;
  30. else
  31. {
  32. *spinlock=1;
  33. return 0;
  34. }
  35. }
  36. #define HAS_COMPARE_AND_SWAP
  37. PT_EI int
  38. __compare_and_swap (long int *p, long int oldval, long int newval)
  39. {
  40. if((*p ^ oldval) == 0) {
  41. *p = newval;
  42. return 1;
  43. }
  44. else
  45. return 0;
  46. }
  47. #endif /* pt-machine.h */