summaryrefslogtreecommitdiff
path: root/libpthread/linuxthreads.old/sysdeps/v850/pt-machine.h
blob: a9cb9b8bf043928d0d0f1f6ff80d4c5474995877 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
/*
 * sysdeps/v850/pt-machine.h -- v850-specific pthread definitions
 *
 *  Copyright (C) 2002  NEC Electronics Corporation
 *  Copyright (C) 2002  Miles Bader <miles@gnu.org>
 *
 * This file is subject to the terms and conditions of the GNU Lesser
 * General Public License.  See the file COPYING.LIB in the main
 * directory of this archive for more details.
 *
 * Written by Miles Bader <miles@gnu.org>
 */

#ifndef _PT_MACHINE_H
#define _PT_MACHINE_H   1

#include <features.h>

#ifndef PT_EI
# if __GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 3)
#  define PT_EI static inline __attribute__((always_inline))
# else
#  define PT_EI extern inline __attribute__((always_inline))
# endif
#endif

/* Get some notion of the current stack.  Need not be exactly the top
   of the stack, just something somewhere in the current frame.  */
#define CURRENT_STACK_FRAME  __stack_pointer
register char *__stack_pointer __asm__ ("sp");

#define HAS_COMPARE_AND_SWAP

/* Atomically:  If *PTR == OLD, set *PTR to NEW and return true,
   otherwise do nothing and return false.  */
PT_EI int
__compare_and_swap (long *ptr, long old, long new)
{
  unsigned long psw;

  /* disable interrupts  */
  __asm__ __volatile__ ("stsr psw, %0; di" : "=&r" (psw));

  if (likely (*ptr == old))
    {
      *ptr = new;
      __asm__ __volatile__ ("ldsr %0, psw" :: "r" (psw)); /* re-enable */
      return 1;
    }
  else
    {
      __asm__ __volatile__ ("ldsr %0, psw" :: "r" (psw)); /* re-enable */
      return 0;
    }
}
#endif /* pt-machine.h */