OpenCores
URL https://opencores.org/ocsvn/openrisc/openrisc/trunk

Subversion Repositories openrisc

[/] [openrisc/] [trunk/] [gnu-dev/] [or1k-gcc/] [libjava/] [sysdep/] [powerpc/] [locks.h] - Blame information for rev 764

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 764 jeremybenn
// locks.h - Thread synchronization primitives. PowerPC implementation.
2
 
3
/* Copyright (C) 2002,2008  Free Software Foundation
4
 
5
   This file is part of libgcj.
6
 
7
This software is copyrighted work licensed under the terms of the
8
Libgcj License.  Please consult the file "LIBGCJ_LICENSE" for
9
details.  */
10
 
11
#ifndef __SYSDEP_LOCKS_H__
12
#define __SYSDEP_LOCKS_H__
13
 
14
#ifdef __LP64__
15
#define _LARX "ldarx "
16
#define _STCX "stdcx. "
17
#else
18
#define _LARX "lwarx "
19
#ifdef __PPC405__
20
#define _STCX "sync; stwcx. "
21
#else
22
#define _STCX "stwcx. "
23
#endif
24
#endif
25
 
26
typedef size_t obj_addr_t;      /* Integer type big enough for object   */
27
                                /* address.                             */
28
 
29
inline static bool
30
compare_and_swap (volatile obj_addr_t *addr, obj_addr_t old,
31
                  obj_addr_t new_val)
32
{
33
  obj_addr_t ret;
34
 
35
  __asm__ __volatile__ (
36
           "      " _LARX "%0,0,%1 \n"
37
           "      xor. %0,%3,%0\n"
38
           "      bne $+12\n"
39
           "      " _STCX "%2,0,%1\n"
40
           "      bne- $-16\n"
41
        : "=&r" (ret)
42
        : "r" (addr), "r" (new_val), "r" (old)
43
        : "cr0", "memory");
44
 
45
  /* This version of __compare_and_swap is to be used when acquiring
46
     a lock, so we don't need to worry about whether other memory
47
     operations have completed, but we do need to be sure that any loads
48
     after this point really occur after we have acquired the lock.  */
49
  __asm__ __volatile__ ("isync" : : : "memory");
50
  return ret == 0;
51
}
52
 
53
inline static void
54
release_set (volatile obj_addr_t *addr, obj_addr_t new_val)
55
{
56
  __asm__ __volatile__ ("sync" : : : "memory");
57
  *addr = new_val;
58
}
59
 
60
inline static bool
61
compare_and_swap_release (volatile obj_addr_t *addr, obj_addr_t old,
62
                          obj_addr_t new_val)
63
{
64
  obj_addr_t ret;
65
 
66
  __asm__ __volatile__ ("sync" : : : "memory");
67
 
68
  __asm__ __volatile__ (
69
           "      " _LARX "%0,0,%1 \n"
70
           "      xor. %0,%3,%0\n"
71
           "      bne $+12\n"
72
           "      " _STCX "%2,0,%1\n"
73
           "      bne- $-16\n"
74
        : "=&r" (ret)
75
        : "r" (addr), "r" (new_val), "r" (old)
76
        : "cr0", "memory");
77
 
78
  return ret == 0;
79
}
80
 
81
// Ensure that subsequent instructions do not execute on stale
82
// data that was loaded from memory before the barrier.
83
inline static void
84
read_barrier ()
85
{
86
  __asm__ __volatile__ ("isync" : : : "memory");
87
}
88
 
89
// Ensure that prior stores to memory are completed with respect to other
90
// processors.
91
inline static void
92
write_barrier ()
93
{
94
  __asm__ __volatile__ ("sync" : : : "memory");
95
}
96
 
97
#endif

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.