|
1 /* |
|
2 * Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies). |
|
3 * All rights reserved. |
|
4 * This component and the accompanying materials are made available |
|
5 * under the terms of "Eclipse Public License v1.0" |
|
6 * which accompanies this distribution, and is available |
|
7 * at the URL "http://www.eclipse.org/legal/epl-v10.html". |
|
8 * |
|
9 * Initial Contributors: |
|
10 * Nokia Corporation - initial contribution. |
|
11 * |
|
12 * Contributors: |
|
13 * |
|
14 * Description: |
|
15 * |
|
16 */ |
|
17 |
|
18 // Currently, SUN CC requires object file |
|
19 |
|
20 #if defined (__GNUC__) |
|
21 |
|
22 /* |
|
23 ** int _STLP_atomic_exchange (__stl_atomic_t *pvalue, __stl_atomic_t value) |
|
24 */ |
|
25 |
|
26 # if defined(__sparc_v9__) || defined (__sparcv9) |
|
27 |
|
28 # ifdef __arch64__ |
|
29 |
|
30 # define _STLP_EXCH_ASM asm volatile ("casx [%3], %4, %0 ; membar #LoadLoad | #LoadStore " : \ |
|
31 "=r" (_L_value2), "=m" (*_L_pvalue1) : \ |
|
32 "m" (*_L_pvalue1), "r" (_L_pvalue1), "r" (_L_value1), "0" (_L_value2) ) |
|
33 |
|
34 # else /* __arch64__ */ |
|
35 |
|
36 # define _STLP_EXCH_ASM asm volatile ("cas [%3], %4, %0" : \ |
|
37 "=r" (_L_value2), "=m" (*_L_pvalue1) : \ |
|
38 "m" (*_L_pvalue1), "r" (_L_pvalue1), "r" (_L_value1), "0" (_L_value2) ) |
|
39 # endif |
|
40 |
|
41 # else /* __sparc_v9__ */ |
|
42 |
|
43 # define _STLP_EXCH_ASM asm volatile ("swap [%3], %0 " : \ |
|
44 "=r" (_L_value2), "=m" (*_L_pvalue1) : \ |
|
45 "m" (*_L_pvalue1), "r" (_L_pvalue1), "0" (_L_value2) ) |
|
46 # endif |
|
47 |
|
48 |
|
49 # define _STLP_ATOMIC_EXCHANGE(__pvalue1, __value2) \ |
|
50 ({ register volatile __stl_atomic_t *_L_pvalue1 = __pvalue1; \ |
|
51 register __stl_atomic_t _L_value1, _L_value2 = __value2 ; \ |
|
52 do { _L_value1 = *_L_pvalue1; _STLP_EXCH_ASM; } while ( _L_value1 != _L_value2 ) ; \ |
|
53 _L_value1; }) |
|
54 |
|
55 # define _STLP_ATOMIC_INCREMENT(__pvalue1) \ |
|
56 ({ register volatile __stl_atomic_t *_L_pvalue1 = __pvalue1; \ |
|
57 register __stl_atomic_t _L_value1, _L_value2; \ |
|
58 do { _L_value1 = *_L_pvalue1; _L_value2 = _L_value1+1; _STLP_EXCH_ASM; } while ( _L_value1 != _L_value2 ) ; \ |
|
59 (_L_value2 + 1); }) |
|
60 |
|
61 # define _STLP_ATOMIC_DECREMENT(__pvalue1) \ |
|
62 ({ register volatile __stl_atomic_t *_L_pvalue1 = __pvalue1; \ |
|
63 register __stl_atomic_t _L_value1, _L_value2; \ |
|
64 do { _L_value1 = *_L_pvalue1; _L_value2 = _L_value1-1; _STLP_EXCH_ASM; } while ( _L_value1 != _L_value2 ) ; \ |
|
65 (_L_value2 - 1); }) |
|
66 |
|
67 # elif ! defined (_STLP_NO_EXTERN_INLINE) |
|
68 |
|
69 extern "C" __stl_atomic_t _STLP_atomic_exchange(__stl_atomic_t * __x, __stl_atomic_t __v); |
|
70 extern "C" void _STLP_atomic_decrement(__stl_atomic_t* i); |
|
71 extern "C" void _STLP_atomic_increment(__stl_atomic_t* i); |
|
72 |
|
73 # define _STLP_ATOMIC_INCREMENT(__x) _STLP_atomic_increment((__stl_atomic_t*)__x) |
|
74 # define _STLP_ATOMIC_DECREMENT(__x) _STLP_atomic_decrement((__stl_atomic_t*)__x) |
|
75 # define _STLP_ATOMIC_EXCHANGE(__x, __y) _STLP_atomic_exchange((__stl_atomic_t*)__x, (__stl_atomic_t)__y) |
|
76 |
|
77 # endif |
|
78 |