src/hotspot/share/runtime/atomic.hpp
author lfoltan
Tue, 20 Feb 2018 07:00:49 -0500
changeset 49022 83fd70753121
parent 48468 7cc7de9bf4a4
child 49364 601146c66cad
permissions -rw-r--r--
8196889: VS2017 Unable to Instantiate OrderAccess::release_store with an Incomplete Class Within an Inlined Method Summary: Fix compilation error by declaring Atomic::IsPointerConvertible public. Reviewed-by: kbarrett, stuefe
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
     1
/*
49022
83fd70753121 8196889: VS2017 Unable to Instantiate OrderAccess::release_store with an Incomplete Class Within an Inlined Method
lfoltan
parents: 48468
diff changeset
     2
 * Copyright (c) 1999, 2018, Oracle and/or its affiliates. All rights reserved.
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
489c9b5090e2 Initial load
duke
parents:
diff changeset
     4
 *
489c9b5090e2 Initial load
duke
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
489c9b5090e2 Initial load
duke
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
489c9b5090e2 Initial load
duke
parents:
diff changeset
     7
 * published by the Free Software Foundation.
489c9b5090e2 Initial load
duke
parents:
diff changeset
     8
 *
489c9b5090e2 Initial load
duke
parents:
diff changeset
     9
 * This code is distributed in the hope that it will be useful, but WITHOUT
489c9b5090e2 Initial load
duke
parents:
diff changeset
    10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
489c9b5090e2 Initial load
duke
parents:
diff changeset
    11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
489c9b5090e2 Initial load
duke
parents:
diff changeset
    12
 * version 2 for more details (a copy is included in the LICENSE file that
489c9b5090e2 Initial load
duke
parents:
diff changeset
    13
 * accompanied this code).
489c9b5090e2 Initial load
duke
parents:
diff changeset
    14
 *
489c9b5090e2 Initial load
duke
parents:
diff changeset
    15
 * You should have received a copy of the GNU General Public License version
489c9b5090e2 Initial load
duke
parents:
diff changeset
    16
 * 2 along with this work; if not, write to the Free Software Foundation,
489c9b5090e2 Initial load
duke
parents:
diff changeset
    17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
489c9b5090e2 Initial load
duke
parents:
diff changeset
    18
 *
5547
f4b087cbb361 6941466: Oracle rebranding changes for Hotspot repositories
trims
parents: 3795
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
f4b087cbb361 6941466: Oracle rebranding changes for Hotspot repositories
trims
parents: 3795
diff changeset
    20
 * or visit www.oracle.com if you need additional information or have any
f4b087cbb361 6941466: Oracle rebranding changes for Hotspot repositories
trims
parents: 3795
diff changeset
    21
 * questions.
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    22
 *
489c9b5090e2 Initial load
duke
parents:
diff changeset
    23
 */
489c9b5090e2 Initial load
duke
parents:
diff changeset
    24
7397
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 5547
diff changeset
    25
#ifndef SHARE_VM_RUNTIME_ATOMIC_HPP
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 5547
diff changeset
    26
#define SHARE_VM_RUNTIME_ATOMIC_HPP
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 5547
diff changeset
    27
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 5547
diff changeset
    28
#include "memory/allocation.hpp"
46993
dd0f91c85ffc 8186476: Generalize Atomic::add with templates
eosterlund
parents: 46958
diff changeset
    29
#include "metaprogramming/conditional.hpp"
46958
a13bd8c6b7a2 8186166: Generalize Atomic::cmpxchg with templates
eosterlund
parents: 46625
diff changeset
    30
#include "metaprogramming/enableIf.hpp"
a13bd8c6b7a2 8186166: Generalize Atomic::cmpxchg with templates
eosterlund
parents: 46625
diff changeset
    31
#include "metaprogramming/isIntegral.hpp"
46993
dd0f91c85ffc 8186476: Generalize Atomic::add with templates
eosterlund
parents: 46958
diff changeset
    32
#include "metaprogramming/isPointer.hpp"
46958
a13bd8c6b7a2 8186166: Generalize Atomic::cmpxchg with templates
eosterlund
parents: 46625
diff changeset
    33
#include "metaprogramming/isSame.hpp"
a13bd8c6b7a2 8186166: Generalize Atomic::cmpxchg with templates
eosterlund
parents: 46625
diff changeset
    34
#include "metaprogramming/primitiveConversions.hpp"
a13bd8c6b7a2 8186166: Generalize Atomic::cmpxchg with templates
eosterlund
parents: 46625
diff changeset
    35
#include "metaprogramming/removeCV.hpp"
46993
dd0f91c85ffc 8186476: Generalize Atomic::add with templates
eosterlund
parents: 46958
diff changeset
    36
#include "metaprogramming/removePointer.hpp"
46625
edefffab74e2 8183552: Move align functions to align.hpp
stefank
parents: 46619
diff changeset
    37
#include "utilities/align.hpp"
40655
9f644073d3a0 8157907: Incorrect inclusion of atomic.hpp instead of atomic.inline.hpp
dholmes
parents: 39404
diff changeset
    38
#include "utilities/macros.hpp"
7397
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 5547
diff changeset
    39
39404
d0ad5220e91c 8155949: Support relaxed semantics in cmpxchg
mdoerr
parents: 27691
diff changeset
    40
enum cmpxchg_memory_order {
d0ad5220e91c 8155949: Support relaxed semantics in cmpxchg
mdoerr
parents: 27691
diff changeset
    41
  memory_order_relaxed,
d0ad5220e91c 8155949: Support relaxed semantics in cmpxchg
mdoerr
parents: 27691
diff changeset
    42
  // Use value which doesn't interfere with C++2011. We need to be more conservative.
d0ad5220e91c 8155949: Support relaxed semantics in cmpxchg
mdoerr
parents: 27691
diff changeset
    43
  memory_order_conservative = 8
d0ad5220e91c 8155949: Support relaxed semantics in cmpxchg
mdoerr
parents: 27691
diff changeset
    44
};
d0ad5220e91c 8155949: Support relaxed semantics in cmpxchg
mdoerr
parents: 27691
diff changeset
    45
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    46
class Atomic : AllStatic {
47609
a1f68e415b48 8188813: Generalize OrderAccess to use templates
eosterlund
parents: 47593
diff changeset
    47
public:
48468
7cc7de9bf4a4 8186903: Remove j-types from Atomic
coleenp
parents: 47634
diff changeset
    48
  // Atomic operations on int64 types are not available on all 32-bit
7cc7de9bf4a4 8186903: Remove j-types from Atomic
coleenp
parents: 47634
diff changeset
    49
  // platforms. If atomic ops on int64 are defined here they must only
15803
9328492899cc 8008314: Unimplemented() Atomic::load breaks the applications
jwilhelm
parents: 14626
diff changeset
    50
  // be used from code that verifies they are available at runtime and
9328492899cc 8008314: Unimplemented() Atomic::load breaks the applications
jwilhelm
parents: 14626
diff changeset
    51
  // can provide an alternative action if not - see supports_cx8() for
9328492899cc 8008314: Unimplemented() Atomic::load breaks the applications
jwilhelm
parents: 14626
diff changeset
    52
  // a means to test availability.
9328492899cc 8008314: Unimplemented() Atomic::load breaks the applications
jwilhelm
parents: 14626
diff changeset
    53
25625
00dca966711e 8049104: resolve atomic.hpp wording issues from JDK-8047104 code review
dcubed
parents: 25069
diff changeset
    54
  // The memory operations that are mentioned with each of the atomic
00dca966711e 8049104: resolve atomic.hpp wording issues from JDK-8047104 code review
dcubed
parents: 25069
diff changeset
    55
  // function families come from src/share/vm/runtime/orderAccess.hpp,
00dca966711e 8049104: resolve atomic.hpp wording issues from JDK-8047104 code review
dcubed
parents: 25069
diff changeset
    56
  // e.g., <fence> is described in that file and is implemented by the
00dca966711e 8049104: resolve atomic.hpp wording issues from JDK-8047104 code review
dcubed
parents: 25069
diff changeset
    57
  // OrderAccess::fence() function. See that file for the gory details
00dca966711e 8049104: resolve atomic.hpp wording issues from JDK-8047104 code review
dcubed
parents: 25069
diff changeset
    58
  // on the Memory Access Ordering Model.
00dca966711e 8049104: resolve atomic.hpp wording issues from JDK-8047104 code review
dcubed
parents: 25069
diff changeset
    59
00dca966711e 8049104: resolve atomic.hpp wording issues from JDK-8047104 code review
dcubed
parents: 25069
diff changeset
    60
  // All of the atomic operations that imply a read-modify-write action
00dca966711e 8049104: resolve atomic.hpp wording issues from JDK-8047104 code review
dcubed
parents: 25069
diff changeset
    61
  // guarantee a two-way memory barrier across that operation. Historically
00dca966711e 8049104: resolve atomic.hpp wording issues from JDK-8047104 code review
dcubed
parents: 25069
diff changeset
    62
  // these semantics reflect the strength of atomic operations that are
00dca966711e 8049104: resolve atomic.hpp wording issues from JDK-8047104 code review
dcubed
parents: 25069
diff changeset
    63
  // provided on SPARC/X86. We assume that strength is necessary unless
00dca966711e 8049104: resolve atomic.hpp wording issues from JDK-8047104 code review
dcubed
parents: 25069
diff changeset
    64
  // we can prove that a weaker form is sufficiently safe.
00dca966711e 8049104: resolve atomic.hpp wording issues from JDK-8047104 code review
dcubed
parents: 25069
diff changeset
    65
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    66
  // Atomically store to a location
47593
2d56326b98f0 8188224: Generalize Atomic::load/store to use templates
eosterlund
parents: 47578
diff changeset
    67
  // The type T must be either a pointer type convertible to or equal
2d56326b98f0 8188224: Generalize Atomic::load/store to use templates
eosterlund
parents: 47578
diff changeset
    68
  // to D, an integral/enum type equal to D, or a type equal to D that
2d56326b98f0 8188224: Generalize Atomic::load/store to use templates
eosterlund
parents: 47578
diff changeset
    69
  // is primitive convertible using PrimitiveConversions.
2d56326b98f0 8188224: Generalize Atomic::load/store to use templates
eosterlund
parents: 47578
diff changeset
    70
  template<typename T, typename D>
2d56326b98f0 8188224: Generalize Atomic::load/store to use templates
eosterlund
parents: 47578
diff changeset
    71
  inline static void store(T store_value, volatile D* dest);
2d56326b98f0 8188224: Generalize Atomic::load/store to use templates
eosterlund
parents: 47578
diff changeset
    72
2d56326b98f0 8188224: Generalize Atomic::load/store to use templates
eosterlund
parents: 47578
diff changeset
    73
  // Atomically load from a location
2d56326b98f0 8188224: Generalize Atomic::load/store to use templates
eosterlund
parents: 47578
diff changeset
    74
  // The type T must be either a pointer type, an integral/enum type,
2d56326b98f0 8188224: Generalize Atomic::load/store to use templates
eosterlund
parents: 47578
diff changeset
    75
  // or a type that is primitive convertible using PrimitiveConversions.
2d56326b98f0 8188224: Generalize Atomic::load/store to use templates
eosterlund
parents: 47578
diff changeset
    76
  template<typename T>
2d56326b98f0 8188224: Generalize Atomic::load/store to use templates
eosterlund
parents: 47578
diff changeset
    77
  inline static T load(const volatile T* dest);
3594
0ce9158bc84c 6863420: os::javaTimeNanos() go backward on Solaris x86
kvn
parents: 670
diff changeset
    78
25625
00dca966711e 8049104: resolve atomic.hpp wording issues from JDK-8047104 code review
dcubed
parents: 25069
diff changeset
    79
  // Atomically add to a location. Returns updated value. add*() provide:
00dca966711e 8049104: resolve atomic.hpp wording issues from JDK-8047104 code review
dcubed
parents: 25069
diff changeset
    80
  // <fence> add-value-to-dest <membar StoreLoad|StoreStore>
46993
dd0f91c85ffc 8186476: Generalize Atomic::add with templates
eosterlund
parents: 46958
diff changeset
    81
dd0f91c85ffc 8186476: Generalize Atomic::add with templates
eosterlund
parents: 46958
diff changeset
    82
  template<typename I, typename D>
dd0f91c85ffc 8186476: Generalize Atomic::add with templates
eosterlund
parents: 46958
diff changeset
    83
  inline static D add(I add_value, D volatile* dest);
dd0f91c85ffc 8186476: Generalize Atomic::add with templates
eosterlund
parents: 46958
diff changeset
    84
47634
6a0c42c40cd1 8188220: Remove Atomic::*_ptr() uses and overloads from hotspot
coleenp
parents: 47609
diff changeset
    85
  template<typename I, typename D>
6a0c42c40cd1 8188220: Remove Atomic::*_ptr() uses and overloads from hotspot
coleenp
parents: 47609
diff changeset
    86
  inline static D sub(I sub_value, D volatile* dest);
9990
c8683968c01b 6941923: RFE: Handling large log files produced by long running Java Applications
minqi
parents: 7397
diff changeset
    87
47552
8a3599d60996 8186838: Generalize Atomic::inc/dec with templates
eosterlund
parents: 47216
diff changeset
    88
  // Atomically increment location. inc() provide:
25625
00dca966711e 8049104: resolve atomic.hpp wording issues from JDK-8047104 code review
dcubed
parents: 25069
diff changeset
    89
  // <fence> increment-dest <membar StoreLoad|StoreStore>
47552
8a3599d60996 8186838: Generalize Atomic::inc/dec with templates
eosterlund
parents: 47216
diff changeset
    90
  // The type D may be either a pointer type, or an integral
8a3599d60996 8186838: Generalize Atomic::inc/dec with templates
eosterlund
parents: 47216
diff changeset
    91
  // type. If it is a pointer type, then the increment is
8a3599d60996 8186838: Generalize Atomic::inc/dec with templates
eosterlund
parents: 47216
diff changeset
    92
  // scaled to the size of the type pointed to by the pointer.
8a3599d60996 8186838: Generalize Atomic::inc/dec with templates
eosterlund
parents: 47216
diff changeset
    93
  template<typename D>
8a3599d60996 8186838: Generalize Atomic::inc/dec with templates
eosterlund
parents: 47216
diff changeset
    94
  inline static void inc(D volatile* dest);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    95
47552
8a3599d60996 8186838: Generalize Atomic::inc/dec with templates
eosterlund
parents: 47216
diff changeset
    96
  // Atomically decrement a location. dec() provide:
25625
00dca966711e 8049104: resolve atomic.hpp wording issues from JDK-8047104 code review
dcubed
parents: 25069
diff changeset
    97
  // <fence> decrement-dest <membar StoreLoad|StoreStore>
47552
8a3599d60996 8186838: Generalize Atomic::inc/dec with templates
eosterlund
parents: 47216
diff changeset
    98
  // The type D may be either a pointer type, or an integral
8a3599d60996 8186838: Generalize Atomic::inc/dec with templates
eosterlund
parents: 47216
diff changeset
    99
  // type. If it is a pointer type, then the decrement is
8a3599d60996 8186838: Generalize Atomic::inc/dec with templates
eosterlund
parents: 47216
diff changeset
   100
  // scaled to the size of the type pointed to by the pointer.
8a3599d60996 8186838: Generalize Atomic::inc/dec with templates
eosterlund
parents: 47216
diff changeset
   101
  template<typename D>
8a3599d60996 8186838: Generalize Atomic::inc/dec with templates
eosterlund
parents: 47216
diff changeset
   102
  inline static void dec(D volatile* dest);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   103
25625
00dca966711e 8049104: resolve atomic.hpp wording issues from JDK-8047104 code review
dcubed
parents: 25069
diff changeset
   104
  // Performs atomic exchange of *dest with exchange_value. Returns old
00dca966711e 8049104: resolve atomic.hpp wording issues from JDK-8047104 code review
dcubed
parents: 25069
diff changeset
   105
  // prior value of *dest. xchg*() provide:
00dca966711e 8049104: resolve atomic.hpp wording issues from JDK-8047104 code review
dcubed
parents: 25069
diff changeset
   106
  // <fence> exchange-value-with-dest <membar StoreLoad|StoreStore>
47578
09c41c4913d9 8187977: Generalize Atomic::xchg to use templates
eosterlund
parents: 47552
diff changeset
   107
  // The type T must be either a pointer type convertible to or equal
09c41c4913d9 8187977: Generalize Atomic::xchg to use templates
eosterlund
parents: 47552
diff changeset
   108
  // to D, an integral/enum type equal to D, or a type equal to D that
09c41c4913d9 8187977: Generalize Atomic::xchg to use templates
eosterlund
parents: 47552
diff changeset
   109
  // is primitive convertible using PrimitiveConversions.
09c41c4913d9 8187977: Generalize Atomic::xchg to use templates
eosterlund
parents: 47552
diff changeset
   110
  template<typename T, typename D>
09c41c4913d9 8187977: Generalize Atomic::xchg to use templates
eosterlund
parents: 47552
diff changeset
   111
  inline static D xchg(T exchange_value, volatile D* dest);
09c41c4913d9 8187977: Generalize Atomic::xchg to use templates
eosterlund
parents: 47552
diff changeset
   112
25625
00dca966711e 8049104: resolve atomic.hpp wording issues from JDK-8047104 code review
dcubed
parents: 25069
diff changeset
   113
  // Performs atomic compare of *dest and compare_value, and exchanges
00dca966711e 8049104: resolve atomic.hpp wording issues from JDK-8047104 code review
dcubed
parents: 25069
diff changeset
   114
  // *dest with exchange_value if the comparison succeeded. Returns prior
00dca966711e 8049104: resolve atomic.hpp wording issues from JDK-8047104 code review
dcubed
parents: 25069
diff changeset
   115
  // value of *dest. cmpxchg*() provide:
00dca966711e 8049104: resolve atomic.hpp wording issues from JDK-8047104 code review
dcubed
parents: 25069
diff changeset
   116
  // <fence> compare-and-exchange <membar StoreLoad|StoreStore>
46958
a13bd8c6b7a2 8186166: Generalize Atomic::cmpxchg with templates
eosterlund
parents: 46625
diff changeset
   117
a13bd8c6b7a2 8186166: Generalize Atomic::cmpxchg with templates
eosterlund
parents: 46625
diff changeset
   118
  template<typename T, typename D, typename U>
a13bd8c6b7a2 8186166: Generalize Atomic::cmpxchg with templates
eosterlund
parents: 46625
diff changeset
   119
  inline static D cmpxchg(T exchange_value,
a13bd8c6b7a2 8186166: Generalize Atomic::cmpxchg with templates
eosterlund
parents: 46625
diff changeset
   120
                          D volatile* dest,
a13bd8c6b7a2 8186166: Generalize Atomic::cmpxchg with templates
eosterlund
parents: 46625
diff changeset
   121
                          U compare_value,
a13bd8c6b7a2 8186166: Generalize Atomic::cmpxchg with templates
eosterlund
parents: 46625
diff changeset
   122
                          cmpxchg_memory_order order = memory_order_conservative);
a13bd8c6b7a2 8186166: Generalize Atomic::cmpxchg with templates
eosterlund
parents: 46625
diff changeset
   123
a13bd8c6b7a2 8186166: Generalize Atomic::cmpxchg with templates
eosterlund
parents: 46625
diff changeset
   124
  // Performs atomic compare of *dest and NULL, and replaces *dest
a13bd8c6b7a2 8186166: Generalize Atomic::cmpxchg with templates
eosterlund
parents: 46625
diff changeset
   125
  // with exchange_value if the comparison succeeded.  Returns true if
a13bd8c6b7a2 8186166: Generalize Atomic::cmpxchg with templates
eosterlund
parents: 46625
diff changeset
   126
  // the comparison succeeded and the exchange occurred.  This is
a13bd8c6b7a2 8186166: Generalize Atomic::cmpxchg with templates
eosterlund
parents: 46625
diff changeset
   127
  // often used as part of lazy initialization, as a lock-free
a13bd8c6b7a2 8186166: Generalize Atomic::cmpxchg with templates
eosterlund
parents: 46625
diff changeset
   128
  // alternative to the Double-Checked Locking Pattern.
a13bd8c6b7a2 8186166: Generalize Atomic::cmpxchg with templates
eosterlund
parents: 46625
diff changeset
   129
  template<typename T, typename D>
a13bd8c6b7a2 8186166: Generalize Atomic::cmpxchg with templates
eosterlund
parents: 46625
diff changeset
   130
  inline static bool replace_if_null(T* value, D* volatile* dest,
a13bd8c6b7a2 8186166: Generalize Atomic::cmpxchg with templates
eosterlund
parents: 46625
diff changeset
   131
                                     cmpxchg_memory_order order = memory_order_conservative);
a13bd8c6b7a2 8186166: Generalize Atomic::cmpxchg with templates
eosterlund
parents: 46625
diff changeset
   132
a13bd8c6b7a2 8186166: Generalize Atomic::cmpxchg with templates
eosterlund
parents: 46625
diff changeset
   133
private:
49022
83fd70753121 8196889: VS2017 Unable to Instantiate OrderAccess::release_store with an Incomplete Class Within an Inlined Method
lfoltan
parents: 48468
diff changeset
   134
WINDOWS_ONLY(public:) // VS2017 warns (C2027) use of undefined type if IsPointerConvertible is declared private
46958
a13bd8c6b7a2 8186166: Generalize Atomic::cmpxchg with templates
eosterlund
parents: 46625
diff changeset
   135
  // Test whether From is implicitly convertible to To.
a13bd8c6b7a2 8186166: Generalize Atomic::cmpxchg with templates
eosterlund
parents: 46625
diff changeset
   136
  // From and To must be pointer types.
a13bd8c6b7a2 8186166: Generalize Atomic::cmpxchg with templates
eosterlund
parents: 46625
diff changeset
   137
  // Note: Provides the limited subset of C++11 std::is_convertible
a13bd8c6b7a2 8186166: Generalize Atomic::cmpxchg with templates
eosterlund
parents: 46625
diff changeset
   138
  // that is needed here.
a13bd8c6b7a2 8186166: Generalize Atomic::cmpxchg with templates
eosterlund
parents: 46625
diff changeset
   139
  template<typename From, typename To> struct IsPointerConvertible;
a13bd8c6b7a2 8186166: Generalize Atomic::cmpxchg with templates
eosterlund
parents: 46625
diff changeset
   140
47609
a1f68e415b48 8188813: Generalize OrderAccess to use templates
eosterlund
parents: 47593
diff changeset
   141
protected:
47593
2d56326b98f0 8188224: Generalize Atomic::load/store to use templates
eosterlund
parents: 47578
diff changeset
   142
  // Dispatch handler for store.  Provides type-based validity
2d56326b98f0 8188224: Generalize Atomic::load/store to use templates
eosterlund
parents: 47578
diff changeset
   143
  // checking and limited conversions around calls to the platform-
2d56326b98f0 8188224: Generalize Atomic::load/store to use templates
eosterlund
parents: 47578
diff changeset
   144
  // specific implementation layer provided by PlatformOp.
2d56326b98f0 8188224: Generalize Atomic::load/store to use templates
eosterlund
parents: 47578
diff changeset
   145
  template<typename T, typename D, typename PlatformOp, typename Enable = void>
2d56326b98f0 8188224: Generalize Atomic::load/store to use templates
eosterlund
parents: 47578
diff changeset
   146
  struct StoreImpl;
2d56326b98f0 8188224: Generalize Atomic::load/store to use templates
eosterlund
parents: 47578
diff changeset
   147
2d56326b98f0 8188224: Generalize Atomic::load/store to use templates
eosterlund
parents: 47578
diff changeset
   148
  // Platform-specific implementation of store.  Support for sizes
2d56326b98f0 8188224: Generalize Atomic::load/store to use templates
eosterlund
parents: 47578
diff changeset
   149
  // of 1, 2, 4, and (if different) pointer size bytes are required.
2d56326b98f0 8188224: Generalize Atomic::load/store to use templates
eosterlund
parents: 47578
diff changeset
   150
  // The class is a function object that must be default constructable,
2d56326b98f0 8188224: Generalize Atomic::load/store to use templates
eosterlund
parents: 47578
diff changeset
   151
  // with these requirements:
2d56326b98f0 8188224: Generalize Atomic::load/store to use templates
eosterlund
parents: 47578
diff changeset
   152
  //
2d56326b98f0 8188224: Generalize Atomic::load/store to use templates
eosterlund
parents: 47578
diff changeset
   153
  // either:
2d56326b98f0 8188224: Generalize Atomic::load/store to use templates
eosterlund
parents: 47578
diff changeset
   154
  // - dest is of type D*, an integral, enum or pointer type.
2d56326b98f0 8188224: Generalize Atomic::load/store to use templates
eosterlund
parents: 47578
diff changeset
   155
  // - new_value are of type T, an integral, enum or pointer type D or
2d56326b98f0 8188224: Generalize Atomic::load/store to use templates
eosterlund
parents: 47578
diff changeset
   156
  //   pointer type convertible to D.
2d56326b98f0 8188224: Generalize Atomic::load/store to use templates
eosterlund
parents: 47578
diff changeset
   157
  // or:
2d56326b98f0 8188224: Generalize Atomic::load/store to use templates
eosterlund
parents: 47578
diff changeset
   158
  // - T and D are the same and are primitive convertible using PrimitiveConversions
2d56326b98f0 8188224: Generalize Atomic::load/store to use templates
eosterlund
parents: 47578
diff changeset
   159
  // and either way:
2d56326b98f0 8188224: Generalize Atomic::load/store to use templates
eosterlund
parents: 47578
diff changeset
   160
  // - platform_store is an object of type PlatformStore<sizeof(T)>.
2d56326b98f0 8188224: Generalize Atomic::load/store to use templates
eosterlund
parents: 47578
diff changeset
   161
  //
2d56326b98f0 8188224: Generalize Atomic::load/store to use templates
eosterlund
parents: 47578
diff changeset
   162
  // Then
2d56326b98f0 8188224: Generalize Atomic::load/store to use templates
eosterlund
parents: 47578
diff changeset
   163
  //   platform_store(new_value, dest)
2d56326b98f0 8188224: Generalize Atomic::load/store to use templates
eosterlund
parents: 47578
diff changeset
   164
  // must be a valid expression.
2d56326b98f0 8188224: Generalize Atomic::load/store to use templates
eosterlund
parents: 47578
diff changeset
   165
  //
2d56326b98f0 8188224: Generalize Atomic::load/store to use templates
eosterlund
parents: 47578
diff changeset
   166
  // The default implementation is a volatile store. If a platform
2d56326b98f0 8188224: Generalize Atomic::load/store to use templates
eosterlund
parents: 47578
diff changeset
   167
  // requires more for e.g. 64 bit stores, a specialization is required
2d56326b98f0 8188224: Generalize Atomic::load/store to use templates
eosterlund
parents: 47578
diff changeset
   168
  template<size_t byte_size> struct PlatformStore;
2d56326b98f0 8188224: Generalize Atomic::load/store to use templates
eosterlund
parents: 47578
diff changeset
   169
2d56326b98f0 8188224: Generalize Atomic::load/store to use templates
eosterlund
parents: 47578
diff changeset
   170
  // Dispatch handler for load.  Provides type-based validity
2d56326b98f0 8188224: Generalize Atomic::load/store to use templates
eosterlund
parents: 47578
diff changeset
   171
  // checking and limited conversions around calls to the platform-
2d56326b98f0 8188224: Generalize Atomic::load/store to use templates
eosterlund
parents: 47578
diff changeset
   172
  // specific implementation layer provided by PlatformOp.
2d56326b98f0 8188224: Generalize Atomic::load/store to use templates
eosterlund
parents: 47578
diff changeset
   173
  template<typename T, typename PlatformOp, typename Enable = void>
2d56326b98f0 8188224: Generalize Atomic::load/store to use templates
eosterlund
parents: 47578
diff changeset
   174
  struct LoadImpl;
2d56326b98f0 8188224: Generalize Atomic::load/store to use templates
eosterlund
parents: 47578
diff changeset
   175
2d56326b98f0 8188224: Generalize Atomic::load/store to use templates
eosterlund
parents: 47578
diff changeset
   176
  // Platform-specific implementation of load. Support for sizes of
2d56326b98f0 8188224: Generalize Atomic::load/store to use templates
eosterlund
parents: 47578
diff changeset
   177
  // 1, 2, 4 bytes and (if different) pointer size bytes are required.
2d56326b98f0 8188224: Generalize Atomic::load/store to use templates
eosterlund
parents: 47578
diff changeset
   178
  // The class is a function object that must be default
2d56326b98f0 8188224: Generalize Atomic::load/store to use templates
eosterlund
parents: 47578
diff changeset
   179
  // constructable, with these requirements:
2d56326b98f0 8188224: Generalize Atomic::load/store to use templates
eosterlund
parents: 47578
diff changeset
   180
  //
2d56326b98f0 8188224: Generalize Atomic::load/store to use templates
eosterlund
parents: 47578
diff changeset
   181
  // - dest is of type T*, an integral, enum or pointer type, or
2d56326b98f0 8188224: Generalize Atomic::load/store to use templates
eosterlund
parents: 47578
diff changeset
   182
  //   T is convertible to a primitive type using PrimitiveConversions
2d56326b98f0 8188224: Generalize Atomic::load/store to use templates
eosterlund
parents: 47578
diff changeset
   183
  // - platform_load is an object of type PlatformLoad<sizeof(T)>.
2d56326b98f0 8188224: Generalize Atomic::load/store to use templates
eosterlund
parents: 47578
diff changeset
   184
  //
2d56326b98f0 8188224: Generalize Atomic::load/store to use templates
eosterlund
parents: 47578
diff changeset
   185
  // Then
2d56326b98f0 8188224: Generalize Atomic::load/store to use templates
eosterlund
parents: 47578
diff changeset
   186
  //   platform_load(src)
2d56326b98f0 8188224: Generalize Atomic::load/store to use templates
eosterlund
parents: 47578
diff changeset
   187
  // must be a valid expression, returning a result convertible to T.
2d56326b98f0 8188224: Generalize Atomic::load/store to use templates
eosterlund
parents: 47578
diff changeset
   188
  //
2d56326b98f0 8188224: Generalize Atomic::load/store to use templates
eosterlund
parents: 47578
diff changeset
   189
  // The default implementation is a volatile load. If a platform
2d56326b98f0 8188224: Generalize Atomic::load/store to use templates
eosterlund
parents: 47578
diff changeset
   190
  // requires more for e.g. 64 bit loads, a specialization is required
2d56326b98f0 8188224: Generalize Atomic::load/store to use templates
eosterlund
parents: 47578
diff changeset
   191
  template<size_t byte_size> struct PlatformLoad;
2d56326b98f0 8188224: Generalize Atomic::load/store to use templates
eosterlund
parents: 47578
diff changeset
   192
47609
a1f68e415b48 8188813: Generalize OrderAccess to use templates
eosterlund
parents: 47593
diff changeset
   193
private:
46993
dd0f91c85ffc 8186476: Generalize Atomic::add with templates
eosterlund
parents: 46958
diff changeset
   194
  // Dispatch handler for add.  Provides type-based validity checking
dd0f91c85ffc 8186476: Generalize Atomic::add with templates
eosterlund
parents: 46958
diff changeset
   195
  // and limited conversions around calls to the platform-specific
dd0f91c85ffc 8186476: Generalize Atomic::add with templates
eosterlund
parents: 46958
diff changeset
   196
  // implementation layer provided by PlatformAdd.
dd0f91c85ffc 8186476: Generalize Atomic::add with templates
eosterlund
parents: 46958
diff changeset
   197
  template<typename I, typename D, typename Enable = void>
dd0f91c85ffc 8186476: Generalize Atomic::add with templates
eosterlund
parents: 46958
diff changeset
   198
  struct AddImpl;
dd0f91c85ffc 8186476: Generalize Atomic::add with templates
eosterlund
parents: 46958
diff changeset
   199
dd0f91c85ffc 8186476: Generalize Atomic::add with templates
eosterlund
parents: 46958
diff changeset
   200
  // Platform-specific implementation of add.  Support for sizes of 4
dd0f91c85ffc 8186476: Generalize Atomic::add with templates
eosterlund
parents: 46958
diff changeset
   201
  // bytes and (if different) pointer size bytes are required.  The
dd0f91c85ffc 8186476: Generalize Atomic::add with templates
eosterlund
parents: 46958
diff changeset
   202
  // class is a function object that must be default constructable,
dd0f91c85ffc 8186476: Generalize Atomic::add with templates
eosterlund
parents: 46958
diff changeset
   203
  // with these requirements:
dd0f91c85ffc 8186476: Generalize Atomic::add with templates
eosterlund
parents: 46958
diff changeset
   204
  //
dd0f91c85ffc 8186476: Generalize Atomic::add with templates
eosterlund
parents: 46958
diff changeset
   205
  // - dest is of type D*, an integral or pointer type.
dd0f91c85ffc 8186476: Generalize Atomic::add with templates
eosterlund
parents: 46958
diff changeset
   206
  // - add_value is of type I, an integral type.
dd0f91c85ffc 8186476: Generalize Atomic::add with templates
eosterlund
parents: 46958
diff changeset
   207
  // - sizeof(I) == sizeof(D).
dd0f91c85ffc 8186476: Generalize Atomic::add with templates
eosterlund
parents: 46958
diff changeset
   208
  // - if D is an integral type, I == D.
dd0f91c85ffc 8186476: Generalize Atomic::add with templates
eosterlund
parents: 46958
diff changeset
   209
  // - platform_add is an object of type PlatformAdd<sizeof(D)>.
dd0f91c85ffc 8186476: Generalize Atomic::add with templates
eosterlund
parents: 46958
diff changeset
   210
  //
dd0f91c85ffc 8186476: Generalize Atomic::add with templates
eosterlund
parents: 46958
diff changeset
   211
  // Then
dd0f91c85ffc 8186476: Generalize Atomic::add with templates
eosterlund
parents: 46958
diff changeset
   212
  //   platform_add(add_value, dest)
dd0f91c85ffc 8186476: Generalize Atomic::add with templates
eosterlund
parents: 46958
diff changeset
   213
  // must be a valid expression, returning a result convertible to D.
dd0f91c85ffc 8186476: Generalize Atomic::add with templates
eosterlund
parents: 46958
diff changeset
   214
  //
dd0f91c85ffc 8186476: Generalize Atomic::add with templates
eosterlund
parents: 46958
diff changeset
   215
  // No definition is provided; all platforms must explicitly define
dd0f91c85ffc 8186476: Generalize Atomic::add with templates
eosterlund
parents: 46958
diff changeset
   216
  // this class and any needed specializations.
dd0f91c85ffc 8186476: Generalize Atomic::add with templates
eosterlund
parents: 46958
diff changeset
   217
  template<size_t byte_size> struct PlatformAdd;
dd0f91c85ffc 8186476: Generalize Atomic::add with templates
eosterlund
parents: 46958
diff changeset
   218
dd0f91c85ffc 8186476: Generalize Atomic::add with templates
eosterlund
parents: 46958
diff changeset
   219
  // Helper base classes for defining PlatformAdd.  To use, define
dd0f91c85ffc 8186476: Generalize Atomic::add with templates
eosterlund
parents: 46958
diff changeset
   220
  // PlatformAdd or a specialization that derives from one of these,
dd0f91c85ffc 8186476: Generalize Atomic::add with templates
eosterlund
parents: 46958
diff changeset
   221
  // and include in the PlatformAdd definition the support function
dd0f91c85ffc 8186476: Generalize Atomic::add with templates
eosterlund
parents: 46958
diff changeset
   222
  // (described below) required by the base class.
dd0f91c85ffc 8186476: Generalize Atomic::add with templates
eosterlund
parents: 46958
diff changeset
   223
  //
dd0f91c85ffc 8186476: Generalize Atomic::add with templates
eosterlund
parents: 46958
diff changeset
   224
  // These classes implement the required function object protocol for
dd0f91c85ffc 8186476: Generalize Atomic::add with templates
eosterlund
parents: 46958
diff changeset
   225
  // PlatformAdd, using a support function template provided by the
dd0f91c85ffc 8186476: Generalize Atomic::add with templates
eosterlund
parents: 46958
diff changeset
   226
  // derived class.  Let add_value (of type I) and dest (of type D) be
dd0f91c85ffc 8186476: Generalize Atomic::add with templates
eosterlund
parents: 46958
diff changeset
   227
  // the arguments the object is called with.  If D is a pointer type
dd0f91c85ffc 8186476: Generalize Atomic::add with templates
eosterlund
parents: 46958
diff changeset
   228
  // P*, then let addend (of type I) be add_value * sizeof(P);
dd0f91c85ffc 8186476: Generalize Atomic::add with templates
eosterlund
parents: 46958
diff changeset
   229
  // otherwise, addend is add_value.
dd0f91c85ffc 8186476: Generalize Atomic::add with templates
eosterlund
parents: 46958
diff changeset
   230
  //
dd0f91c85ffc 8186476: Generalize Atomic::add with templates
eosterlund
parents: 46958
diff changeset
   231
  // FetchAndAdd requires the derived class to provide
dd0f91c85ffc 8186476: Generalize Atomic::add with templates
eosterlund
parents: 46958
diff changeset
   232
  //   fetch_and_add(addend, dest)
dd0f91c85ffc 8186476: Generalize Atomic::add with templates
eosterlund
parents: 46958
diff changeset
   233
  // atomically adding addend to the value of dest, and returning the
dd0f91c85ffc 8186476: Generalize Atomic::add with templates
eosterlund
parents: 46958
diff changeset
   234
  // old value.
dd0f91c85ffc 8186476: Generalize Atomic::add with templates
eosterlund
parents: 46958
diff changeset
   235
  //
dd0f91c85ffc 8186476: Generalize Atomic::add with templates
eosterlund
parents: 46958
diff changeset
   236
  // AddAndFetch requires the derived class to provide
dd0f91c85ffc 8186476: Generalize Atomic::add with templates
eosterlund
parents: 46958
diff changeset
   237
  //   add_and_fetch(addend, dest)
dd0f91c85ffc 8186476: Generalize Atomic::add with templates
eosterlund
parents: 46958
diff changeset
   238
  // atomically adding addend to the value of dest, and returning the
dd0f91c85ffc 8186476: Generalize Atomic::add with templates
eosterlund
parents: 46958
diff changeset
   239
  // new value.
dd0f91c85ffc 8186476: Generalize Atomic::add with templates
eosterlund
parents: 46958
diff changeset
   240
  //
dd0f91c85ffc 8186476: Generalize Atomic::add with templates
eosterlund
parents: 46958
diff changeset
   241
  // When D is a pointer type P*, both fetch_and_add and add_and_fetch
dd0f91c85ffc 8186476: Generalize Atomic::add with templates
eosterlund
parents: 46958
diff changeset
   242
  // treat it as if it were a uintptr_t; they do not perform any
dd0f91c85ffc 8186476: Generalize Atomic::add with templates
eosterlund
parents: 46958
diff changeset
   243
  // scaling of the addend, as that has already been done by the
dd0f91c85ffc 8186476: Generalize Atomic::add with templates
eosterlund
parents: 46958
diff changeset
   244
  // caller.
dd0f91c85ffc 8186476: Generalize Atomic::add with templates
eosterlund
parents: 46958
diff changeset
   245
public: // Temporary, can't be private: C++03 11.4/2. Fixed by C++11.
dd0f91c85ffc 8186476: Generalize Atomic::add with templates
eosterlund
parents: 46958
diff changeset
   246
  template<typename Derived> struct FetchAndAdd;
dd0f91c85ffc 8186476: Generalize Atomic::add with templates
eosterlund
parents: 46958
diff changeset
   247
  template<typename Derived> struct AddAndFetch;
dd0f91c85ffc 8186476: Generalize Atomic::add with templates
eosterlund
parents: 46958
diff changeset
   248
private:
dd0f91c85ffc 8186476: Generalize Atomic::add with templates
eosterlund
parents: 46958
diff changeset
   249
dd0f91c85ffc 8186476: Generalize Atomic::add with templates
eosterlund
parents: 46958
diff changeset
   250
  // Support for platforms that implement some variants of add using a
dd0f91c85ffc 8186476: Generalize Atomic::add with templates
eosterlund
parents: 46958
diff changeset
   251
  // (typically out of line) non-template helper function.  The
dd0f91c85ffc 8186476: Generalize Atomic::add with templates
eosterlund
parents: 46958
diff changeset
   252
  // generic arguments passed to PlatformAdd need to be translated to
dd0f91c85ffc 8186476: Generalize Atomic::add with templates
eosterlund
parents: 46958
diff changeset
   253
  // the appropriate type for the helper function, the helper function
dd0f91c85ffc 8186476: Generalize Atomic::add with templates
eosterlund
parents: 46958
diff changeset
   254
  // invoked on the translated arguments, and the result translated
dd0f91c85ffc 8186476: Generalize Atomic::add with templates
eosterlund
parents: 46958
diff changeset
   255
  // back.  Type is the parameter / return type of the helper
dd0f91c85ffc 8186476: Generalize Atomic::add with templates
eosterlund
parents: 46958
diff changeset
   256
  // function.  No scaling of add_value is performed when D is a pointer
dd0f91c85ffc 8186476: Generalize Atomic::add with templates
eosterlund
parents: 46958
diff changeset
   257
  // type, so this function can be used to implement the support function
dd0f91c85ffc 8186476: Generalize Atomic::add with templates
eosterlund
parents: 46958
diff changeset
   258
  // required by AddAndFetch.
dd0f91c85ffc 8186476: Generalize Atomic::add with templates
eosterlund
parents: 46958
diff changeset
   259
  template<typename Type, typename Fn, typename I, typename D>
dd0f91c85ffc 8186476: Generalize Atomic::add with templates
eosterlund
parents: 46958
diff changeset
   260
  static D add_using_helper(Fn fn, I add_value, D volatile* dest);
dd0f91c85ffc 8186476: Generalize Atomic::add with templates
eosterlund
parents: 46958
diff changeset
   261
46958
a13bd8c6b7a2 8186166: Generalize Atomic::cmpxchg with templates
eosterlund
parents: 46625
diff changeset
   262
  // Dispatch handler for cmpxchg.  Provides type-based validity
a13bd8c6b7a2 8186166: Generalize Atomic::cmpxchg with templates
eosterlund
parents: 46625
diff changeset
   263
  // checking and limited conversions around calls to the
a13bd8c6b7a2 8186166: Generalize Atomic::cmpxchg with templates
eosterlund
parents: 46625
diff changeset
   264
  // platform-specific implementation layer provided by
a13bd8c6b7a2 8186166: Generalize Atomic::cmpxchg with templates
eosterlund
parents: 46625
diff changeset
   265
  // PlatformCmpxchg.
a13bd8c6b7a2 8186166: Generalize Atomic::cmpxchg with templates
eosterlund
parents: 46625
diff changeset
   266
  template<typename T, typename D, typename U, typename Enable = void>
a13bd8c6b7a2 8186166: Generalize Atomic::cmpxchg with templates
eosterlund
parents: 46625
diff changeset
   267
  struct CmpxchgImpl;
a13bd8c6b7a2 8186166: Generalize Atomic::cmpxchg with templates
eosterlund
parents: 46625
diff changeset
   268
a13bd8c6b7a2 8186166: Generalize Atomic::cmpxchg with templates
eosterlund
parents: 46625
diff changeset
   269
  // Platform-specific implementation of cmpxchg.  Support for sizes
a13bd8c6b7a2 8186166: Generalize Atomic::cmpxchg with templates
eosterlund
parents: 46625
diff changeset
   270
  // of 1, 4, and 8 are required.  The class is a function object that
a13bd8c6b7a2 8186166: Generalize Atomic::cmpxchg with templates
eosterlund
parents: 46625
diff changeset
   271
  // must be default constructable, with these requirements:
a13bd8c6b7a2 8186166: Generalize Atomic::cmpxchg with templates
eosterlund
parents: 46625
diff changeset
   272
  //
a13bd8c6b7a2 8186166: Generalize Atomic::cmpxchg with templates
eosterlund
parents: 46625
diff changeset
   273
  // - dest is of type T*.
a13bd8c6b7a2 8186166: Generalize Atomic::cmpxchg with templates
eosterlund
parents: 46625
diff changeset
   274
  // - exchange_value and compare_value are of type T.
a13bd8c6b7a2 8186166: Generalize Atomic::cmpxchg with templates
eosterlund
parents: 46625
diff changeset
   275
  // - order is of type cmpxchg_memory_order.
a13bd8c6b7a2 8186166: Generalize Atomic::cmpxchg with templates
eosterlund
parents: 46625
diff changeset
   276
  // - platform_cmpxchg is an object of type PlatformCmpxchg<sizeof(T)>.
a13bd8c6b7a2 8186166: Generalize Atomic::cmpxchg with templates
eosterlund
parents: 46625
diff changeset
   277
  //
a13bd8c6b7a2 8186166: Generalize Atomic::cmpxchg with templates
eosterlund
parents: 46625
diff changeset
   278
  // Then
a13bd8c6b7a2 8186166: Generalize Atomic::cmpxchg with templates
eosterlund
parents: 46625
diff changeset
   279
  //   platform_cmpxchg(exchange_value, dest, compare_value, order)
a13bd8c6b7a2 8186166: Generalize Atomic::cmpxchg with templates
eosterlund
parents: 46625
diff changeset
   280
  // must be a valid expression, returning a result convertible to T.
a13bd8c6b7a2 8186166: Generalize Atomic::cmpxchg with templates
eosterlund
parents: 46625
diff changeset
   281
  //
a13bd8c6b7a2 8186166: Generalize Atomic::cmpxchg with templates
eosterlund
parents: 46625
diff changeset
   282
  // A default definition is provided, which declares a function template
a13bd8c6b7a2 8186166: Generalize Atomic::cmpxchg with templates
eosterlund
parents: 46625
diff changeset
   283
  //   T operator()(T, T volatile*, T, cmpxchg_memory_order) const
a13bd8c6b7a2 8186166: Generalize Atomic::cmpxchg with templates
eosterlund
parents: 46625
diff changeset
   284
  //
a13bd8c6b7a2 8186166: Generalize Atomic::cmpxchg with templates
eosterlund
parents: 46625
diff changeset
   285
  // For each required size, a platform must either provide an
a13bd8c6b7a2 8186166: Generalize Atomic::cmpxchg with templates
eosterlund
parents: 46625
diff changeset
   286
  // appropriate definition of that function, or must entirely
a13bd8c6b7a2 8186166: Generalize Atomic::cmpxchg with templates
eosterlund
parents: 46625
diff changeset
   287
  // specialize the class template for that size.
a13bd8c6b7a2 8186166: Generalize Atomic::cmpxchg with templates
eosterlund
parents: 46625
diff changeset
   288
  template<size_t byte_size> struct PlatformCmpxchg;
a13bd8c6b7a2 8186166: Generalize Atomic::cmpxchg with templates
eosterlund
parents: 46625
diff changeset
   289
a13bd8c6b7a2 8186166: Generalize Atomic::cmpxchg with templates
eosterlund
parents: 46625
diff changeset
   290
  // Support for platforms that implement some variants of cmpxchg
a13bd8c6b7a2 8186166: Generalize Atomic::cmpxchg with templates
eosterlund
parents: 46625
diff changeset
   291
  // using a (typically out of line) non-template helper function.
a13bd8c6b7a2 8186166: Generalize Atomic::cmpxchg with templates
eosterlund
parents: 46625
diff changeset
   292
  // The generic arguments passed to PlatformCmpxchg need to be
a13bd8c6b7a2 8186166: Generalize Atomic::cmpxchg with templates
eosterlund
parents: 46625
diff changeset
   293
  // translated to the appropriate type for the helper function, the
a13bd8c6b7a2 8186166: Generalize Atomic::cmpxchg with templates
eosterlund
parents: 46625
diff changeset
   294
  // helper invoked on the translated arguments, and the result
a13bd8c6b7a2 8186166: Generalize Atomic::cmpxchg with templates
eosterlund
parents: 46625
diff changeset
   295
  // translated back.  Type is the parameter / return type of the
a13bd8c6b7a2 8186166: Generalize Atomic::cmpxchg with templates
eosterlund
parents: 46625
diff changeset
   296
  // helper function.
a13bd8c6b7a2 8186166: Generalize Atomic::cmpxchg with templates
eosterlund
parents: 46625
diff changeset
   297
  template<typename Type, typename Fn, typename T>
a13bd8c6b7a2 8186166: Generalize Atomic::cmpxchg with templates
eosterlund
parents: 46625
diff changeset
   298
  static T cmpxchg_using_helper(Fn fn,
a13bd8c6b7a2 8186166: Generalize Atomic::cmpxchg with templates
eosterlund
parents: 46625
diff changeset
   299
                                T exchange_value,
a13bd8c6b7a2 8186166: Generalize Atomic::cmpxchg with templates
eosterlund
parents: 46625
diff changeset
   300
                                T volatile* dest,
a13bd8c6b7a2 8186166: Generalize Atomic::cmpxchg with templates
eosterlund
parents: 46625
diff changeset
   301
                                T compare_value);
a13bd8c6b7a2 8186166: Generalize Atomic::cmpxchg with templates
eosterlund
parents: 46625
diff changeset
   302
a13bd8c6b7a2 8186166: Generalize Atomic::cmpxchg with templates
eosterlund
parents: 46625
diff changeset
   303
  // Support platforms that do not provide Read-Modify-Write
a13bd8c6b7a2 8186166: Generalize Atomic::cmpxchg with templates
eosterlund
parents: 46625
diff changeset
   304
  // byte-level atomic access. To use, derive PlatformCmpxchg<1> from
a13bd8c6b7a2 8186166: Generalize Atomic::cmpxchg with templates
eosterlund
parents: 46625
diff changeset
   305
  // this class.
a13bd8c6b7a2 8186166: Generalize Atomic::cmpxchg with templates
eosterlund
parents: 46625
diff changeset
   306
public: // Temporary, can't be private: C++03 11.4/2. Fixed by C++11.
a13bd8c6b7a2 8186166: Generalize Atomic::cmpxchg with templates
eosterlund
parents: 46625
diff changeset
   307
  struct CmpxchgByteUsingInt;
a13bd8c6b7a2 8186166: Generalize Atomic::cmpxchg with templates
eosterlund
parents: 46625
diff changeset
   308
private:
47578
09c41c4913d9 8187977: Generalize Atomic::xchg to use templates
eosterlund
parents: 47552
diff changeset
   309
09c41c4913d9 8187977: Generalize Atomic::xchg to use templates
eosterlund
parents: 47552
diff changeset
   310
  // Dispatch handler for xchg.  Provides type-based validity
09c41c4913d9 8187977: Generalize Atomic::xchg to use templates
eosterlund
parents: 47552
diff changeset
   311
  // checking and limited conversions around calls to the
09c41c4913d9 8187977: Generalize Atomic::xchg to use templates
eosterlund
parents: 47552
diff changeset
   312
  // platform-specific implementation layer provided by
09c41c4913d9 8187977: Generalize Atomic::xchg to use templates
eosterlund
parents: 47552
diff changeset
   313
  // PlatformXchg.
09c41c4913d9 8187977: Generalize Atomic::xchg to use templates
eosterlund
parents: 47552
diff changeset
   314
  template<typename T, typename D, typename Enable = void>
09c41c4913d9 8187977: Generalize Atomic::xchg to use templates
eosterlund
parents: 47552
diff changeset
   315
  struct XchgImpl;
09c41c4913d9 8187977: Generalize Atomic::xchg to use templates
eosterlund
parents: 47552
diff changeset
   316
09c41c4913d9 8187977: Generalize Atomic::xchg to use templates
eosterlund
parents: 47552
diff changeset
   317
  // Platform-specific implementation of xchg.  Support for sizes
09c41c4913d9 8187977: Generalize Atomic::xchg to use templates
eosterlund
parents: 47552
diff changeset
   318
  // of 4, and sizeof(intptr_t) are required.  The class is a function
09c41c4913d9 8187977: Generalize Atomic::xchg to use templates
eosterlund
parents: 47552
diff changeset
   319
  // object that must be default constructable, with these requirements:
09c41c4913d9 8187977: Generalize Atomic::xchg to use templates
eosterlund
parents: 47552
diff changeset
   320
  //
09c41c4913d9 8187977: Generalize Atomic::xchg to use templates
eosterlund
parents: 47552
diff changeset
   321
  // - dest is of type T*.
09c41c4913d9 8187977: Generalize Atomic::xchg to use templates
eosterlund
parents: 47552
diff changeset
   322
  // - exchange_value is of type T.
09c41c4913d9 8187977: Generalize Atomic::xchg to use templates
eosterlund
parents: 47552
diff changeset
   323
  // - platform_xchg is an object of type PlatformXchg<sizeof(T)>.
09c41c4913d9 8187977: Generalize Atomic::xchg to use templates
eosterlund
parents: 47552
diff changeset
   324
  //
09c41c4913d9 8187977: Generalize Atomic::xchg to use templates
eosterlund
parents: 47552
diff changeset
   325
  // Then
09c41c4913d9 8187977: Generalize Atomic::xchg to use templates
eosterlund
parents: 47552
diff changeset
   326
  //   platform_xchg(exchange_value, dest)
09c41c4913d9 8187977: Generalize Atomic::xchg to use templates
eosterlund
parents: 47552
diff changeset
   327
  // must be a valid expression, returning a result convertible to T.
09c41c4913d9 8187977: Generalize Atomic::xchg to use templates
eosterlund
parents: 47552
diff changeset
   328
  //
09c41c4913d9 8187977: Generalize Atomic::xchg to use templates
eosterlund
parents: 47552
diff changeset
   329
  // A default definition is provided, which declares a function template
09c41c4913d9 8187977: Generalize Atomic::xchg to use templates
eosterlund
parents: 47552
diff changeset
   330
  //   T operator()(T, T volatile*, T, cmpxchg_memory_order) const
09c41c4913d9 8187977: Generalize Atomic::xchg to use templates
eosterlund
parents: 47552
diff changeset
   331
  //
09c41c4913d9 8187977: Generalize Atomic::xchg to use templates
eosterlund
parents: 47552
diff changeset
   332
  // For each required size, a platform must either provide an
09c41c4913d9 8187977: Generalize Atomic::xchg to use templates
eosterlund
parents: 47552
diff changeset
   333
  // appropriate definition of that function, or must entirely
09c41c4913d9 8187977: Generalize Atomic::xchg to use templates
eosterlund
parents: 47552
diff changeset
   334
  // specialize the class template for that size.
09c41c4913d9 8187977: Generalize Atomic::xchg to use templates
eosterlund
parents: 47552
diff changeset
   335
  template<size_t byte_size> struct PlatformXchg;
09c41c4913d9 8187977: Generalize Atomic::xchg to use templates
eosterlund
parents: 47552
diff changeset
   336
09c41c4913d9 8187977: Generalize Atomic::xchg to use templates
eosterlund
parents: 47552
diff changeset
   337
  // Support for platforms that implement some variants of xchg
09c41c4913d9 8187977: Generalize Atomic::xchg to use templates
eosterlund
parents: 47552
diff changeset
   338
  // using a (typically out of line) non-template helper function.
09c41c4913d9 8187977: Generalize Atomic::xchg to use templates
eosterlund
parents: 47552
diff changeset
   339
  // The generic arguments passed to PlatformXchg need to be
09c41c4913d9 8187977: Generalize Atomic::xchg to use templates
eosterlund
parents: 47552
diff changeset
   340
  // translated to the appropriate type for the helper function, the
09c41c4913d9 8187977: Generalize Atomic::xchg to use templates
eosterlund
parents: 47552
diff changeset
   341
  // helper invoked on the translated arguments, and the result
09c41c4913d9 8187977: Generalize Atomic::xchg to use templates
eosterlund
parents: 47552
diff changeset
   342
  // translated back.  Type is the parameter / return type of the
09c41c4913d9 8187977: Generalize Atomic::xchg to use templates
eosterlund
parents: 47552
diff changeset
   343
  // helper function.
09c41c4913d9 8187977: Generalize Atomic::xchg to use templates
eosterlund
parents: 47552
diff changeset
   344
  template<typename Type, typename Fn, typename T>
09c41c4913d9 8187977: Generalize Atomic::xchg to use templates
eosterlund
parents: 47552
diff changeset
   345
  static T xchg_using_helper(Fn fn,
09c41c4913d9 8187977: Generalize Atomic::xchg to use templates
eosterlund
parents: 47552
diff changeset
   346
                             T exchange_value,
09c41c4913d9 8187977: Generalize Atomic::xchg to use templates
eosterlund
parents: 47552
diff changeset
   347
                             T volatile* dest);
46958
a13bd8c6b7a2 8186166: Generalize Atomic::cmpxchg with templates
eosterlund
parents: 46625
diff changeset
   348
};
a13bd8c6b7a2 8186166: Generalize Atomic::cmpxchg with templates
eosterlund
parents: 46625
diff changeset
   349
a13bd8c6b7a2 8186166: Generalize Atomic::cmpxchg with templates
eosterlund
parents: 46625
diff changeset
   350
template<typename From, typename To>
a13bd8c6b7a2 8186166: Generalize Atomic::cmpxchg with templates
eosterlund
parents: 46625
diff changeset
   351
struct Atomic::IsPointerConvertible<From*, To*> : AllStatic {
a13bd8c6b7a2 8186166: Generalize Atomic::cmpxchg with templates
eosterlund
parents: 46625
diff changeset
   352
  // Determine whether From* is implicitly convertible to To*, using
a13bd8c6b7a2 8186166: Generalize Atomic::cmpxchg with templates
eosterlund
parents: 46625
diff changeset
   353
  // the "sizeof trick".
a13bd8c6b7a2 8186166: Generalize Atomic::cmpxchg with templates
eosterlund
parents: 46625
diff changeset
   354
  typedef char yes;
a13bd8c6b7a2 8186166: Generalize Atomic::cmpxchg with templates
eosterlund
parents: 46625
diff changeset
   355
  typedef char (&no)[2];
a13bd8c6b7a2 8186166: Generalize Atomic::cmpxchg with templates
eosterlund
parents: 46625
diff changeset
   356
a13bd8c6b7a2 8186166: Generalize Atomic::cmpxchg with templates
eosterlund
parents: 46625
diff changeset
   357
  static yes test(To*);
a13bd8c6b7a2 8186166: Generalize Atomic::cmpxchg with templates
eosterlund
parents: 46625
diff changeset
   358
  static no test(...);
a13bd8c6b7a2 8186166: Generalize Atomic::cmpxchg with templates
eosterlund
parents: 46625
diff changeset
   359
  static From* test_value;
a13bd8c6b7a2 8186166: Generalize Atomic::cmpxchg with templates
eosterlund
parents: 46625
diff changeset
   360
a13bd8c6b7a2 8186166: Generalize Atomic::cmpxchg with templates
eosterlund
parents: 46625
diff changeset
   361
  static const bool value = (sizeof(yes) == sizeof(test(test_value)));
a13bd8c6b7a2 8186166: Generalize Atomic::cmpxchg with templates
eosterlund
parents: 46625
diff changeset
   362
};
a13bd8c6b7a2 8186166: Generalize Atomic::cmpxchg with templates
eosterlund
parents: 46625
diff changeset
   363
47593
2d56326b98f0 8188224: Generalize Atomic::load/store to use templates
eosterlund
parents: 47578
diff changeset
   364
// Handle load for pointer, integral and enum types.
2d56326b98f0 8188224: Generalize Atomic::load/store to use templates
eosterlund
parents: 47578
diff changeset
   365
template<typename T, typename PlatformOp>
2d56326b98f0 8188224: Generalize Atomic::load/store to use templates
eosterlund
parents: 47578
diff changeset
   366
struct Atomic::LoadImpl<
2d56326b98f0 8188224: Generalize Atomic::load/store to use templates
eosterlund
parents: 47578
diff changeset
   367
  T,
2d56326b98f0 8188224: Generalize Atomic::load/store to use templates
eosterlund
parents: 47578
diff changeset
   368
  PlatformOp,
2d56326b98f0 8188224: Generalize Atomic::load/store to use templates
eosterlund
parents: 47578
diff changeset
   369
  typename EnableIf<IsIntegral<T>::value || IsRegisteredEnum<T>::value || IsPointer<T>::value>::type>
2d56326b98f0 8188224: Generalize Atomic::load/store to use templates
eosterlund
parents: 47578
diff changeset
   370
  VALUE_OBJ_CLASS_SPEC
2d56326b98f0 8188224: Generalize Atomic::load/store to use templates
eosterlund
parents: 47578
diff changeset
   371
{
2d56326b98f0 8188224: Generalize Atomic::load/store to use templates
eosterlund
parents: 47578
diff changeset
   372
  T operator()(T const volatile* dest) const {
2d56326b98f0 8188224: Generalize Atomic::load/store to use templates
eosterlund
parents: 47578
diff changeset
   373
    // Forward to the platform handler for the size of T.
2d56326b98f0 8188224: Generalize Atomic::load/store to use templates
eosterlund
parents: 47578
diff changeset
   374
    return PlatformOp()(dest);
2d56326b98f0 8188224: Generalize Atomic::load/store to use templates
eosterlund
parents: 47578
diff changeset
   375
  }
2d56326b98f0 8188224: Generalize Atomic::load/store to use templates
eosterlund
parents: 47578
diff changeset
   376
};
2d56326b98f0 8188224: Generalize Atomic::load/store to use templates
eosterlund
parents: 47578
diff changeset
   377
2d56326b98f0 8188224: Generalize Atomic::load/store to use templates
eosterlund
parents: 47578
diff changeset
   378
// Handle load for types that have a translator.
2d56326b98f0 8188224: Generalize Atomic::load/store to use templates
eosterlund
parents: 47578
diff changeset
   379
//
2d56326b98f0 8188224: Generalize Atomic::load/store to use templates
eosterlund
parents: 47578
diff changeset
   380
// All the involved types must be identical.
2d56326b98f0 8188224: Generalize Atomic::load/store to use templates
eosterlund
parents: 47578
diff changeset
   381
//
2d56326b98f0 8188224: Generalize Atomic::load/store to use templates
eosterlund
parents: 47578
diff changeset
   382
// This translates the original call into a call on the decayed
2d56326b98f0 8188224: Generalize Atomic::load/store to use templates
eosterlund
parents: 47578
diff changeset
   383
// arguments, and returns the recovered result of that translated
2d56326b98f0 8188224: Generalize Atomic::load/store to use templates
eosterlund
parents: 47578
diff changeset
   384
// call.
2d56326b98f0 8188224: Generalize Atomic::load/store to use templates
eosterlund
parents: 47578
diff changeset
   385
template<typename T, typename PlatformOp>
2d56326b98f0 8188224: Generalize Atomic::load/store to use templates
eosterlund
parents: 47578
diff changeset
   386
struct Atomic::LoadImpl<
2d56326b98f0 8188224: Generalize Atomic::load/store to use templates
eosterlund
parents: 47578
diff changeset
   387
  T,
2d56326b98f0 8188224: Generalize Atomic::load/store to use templates
eosterlund
parents: 47578
diff changeset
   388
  PlatformOp,
2d56326b98f0 8188224: Generalize Atomic::load/store to use templates
eosterlund
parents: 47578
diff changeset
   389
  typename EnableIf<PrimitiveConversions::Translate<T>::value>::type>
2d56326b98f0 8188224: Generalize Atomic::load/store to use templates
eosterlund
parents: 47578
diff changeset
   390
  VALUE_OBJ_CLASS_SPEC
2d56326b98f0 8188224: Generalize Atomic::load/store to use templates
eosterlund
parents: 47578
diff changeset
   391
{
2d56326b98f0 8188224: Generalize Atomic::load/store to use templates
eosterlund
parents: 47578
diff changeset
   392
  T operator()(T const volatile* dest) const {
2d56326b98f0 8188224: Generalize Atomic::load/store to use templates
eosterlund
parents: 47578
diff changeset
   393
    typedef PrimitiveConversions::Translate<T> Translator;
2d56326b98f0 8188224: Generalize Atomic::load/store to use templates
eosterlund
parents: 47578
diff changeset
   394
    typedef typename Translator::Decayed Decayed;
2d56326b98f0 8188224: Generalize Atomic::load/store to use templates
eosterlund
parents: 47578
diff changeset
   395
    STATIC_ASSERT(sizeof(T) == sizeof(Decayed));
2d56326b98f0 8188224: Generalize Atomic::load/store to use templates
eosterlund
parents: 47578
diff changeset
   396
    Decayed result = PlatformOp()(reinterpret_cast<Decayed const volatile*>(dest));
2d56326b98f0 8188224: Generalize Atomic::load/store to use templates
eosterlund
parents: 47578
diff changeset
   397
    return Translator::recover(result);
2d56326b98f0 8188224: Generalize Atomic::load/store to use templates
eosterlund
parents: 47578
diff changeset
   398
  }
2d56326b98f0 8188224: Generalize Atomic::load/store to use templates
eosterlund
parents: 47578
diff changeset
   399
};
2d56326b98f0 8188224: Generalize Atomic::load/store to use templates
eosterlund
parents: 47578
diff changeset
   400
2d56326b98f0 8188224: Generalize Atomic::load/store to use templates
eosterlund
parents: 47578
diff changeset
   401
// Default implementation of atomic load if a specific platform
2d56326b98f0 8188224: Generalize Atomic::load/store to use templates
eosterlund
parents: 47578
diff changeset
   402
// does not provide a specialization for a certain size class.
2d56326b98f0 8188224: Generalize Atomic::load/store to use templates
eosterlund
parents: 47578
diff changeset
   403
// For increased safety, the default implementation only allows
2d56326b98f0 8188224: Generalize Atomic::load/store to use templates
eosterlund
parents: 47578
diff changeset
   404
// load types that are pointer sized or smaller. If a platform still
2d56326b98f0 8188224: Generalize Atomic::load/store to use templates
eosterlund
parents: 47578
diff changeset
   405
// supports wide atomics, then it has to use specialization
2d56326b98f0 8188224: Generalize Atomic::load/store to use templates
eosterlund
parents: 47578
diff changeset
   406
// of Atomic::PlatformLoad for that wider size class.
2d56326b98f0 8188224: Generalize Atomic::load/store to use templates
eosterlund
parents: 47578
diff changeset
   407
template<size_t byte_size>
2d56326b98f0 8188224: Generalize Atomic::load/store to use templates
eosterlund
parents: 47578
diff changeset
   408
struct Atomic::PlatformLoad VALUE_OBJ_CLASS_SPEC {
2d56326b98f0 8188224: Generalize Atomic::load/store to use templates
eosterlund
parents: 47578
diff changeset
   409
  template<typename T>
2d56326b98f0 8188224: Generalize Atomic::load/store to use templates
eosterlund
parents: 47578
diff changeset
   410
  T operator()(T const volatile* dest) const {
2d56326b98f0 8188224: Generalize Atomic::load/store to use templates
eosterlund
parents: 47578
diff changeset
   411
    STATIC_ASSERT(sizeof(T) <= sizeof(void*)); // wide atomics need specialization
2d56326b98f0 8188224: Generalize Atomic::load/store to use templates
eosterlund
parents: 47578
diff changeset
   412
    return *dest;
2d56326b98f0 8188224: Generalize Atomic::load/store to use templates
eosterlund
parents: 47578
diff changeset
   413
  }
2d56326b98f0 8188224: Generalize Atomic::load/store to use templates
eosterlund
parents: 47578
diff changeset
   414
};
2d56326b98f0 8188224: Generalize Atomic::load/store to use templates
eosterlund
parents: 47578
diff changeset
   415
2d56326b98f0 8188224: Generalize Atomic::load/store to use templates
eosterlund
parents: 47578
diff changeset
   416
// Handle store for integral and enum types.
2d56326b98f0 8188224: Generalize Atomic::load/store to use templates
eosterlund
parents: 47578
diff changeset
   417
//
2d56326b98f0 8188224: Generalize Atomic::load/store to use templates
eosterlund
parents: 47578
diff changeset
   418
// All the involved types must be identical.
2d56326b98f0 8188224: Generalize Atomic::load/store to use templates
eosterlund
parents: 47578
diff changeset
   419
template<typename T, typename PlatformOp>
2d56326b98f0 8188224: Generalize Atomic::load/store to use templates
eosterlund
parents: 47578
diff changeset
   420
struct Atomic::StoreImpl<
2d56326b98f0 8188224: Generalize Atomic::load/store to use templates
eosterlund
parents: 47578
diff changeset
   421
  T, T,
2d56326b98f0 8188224: Generalize Atomic::load/store to use templates
eosterlund
parents: 47578
diff changeset
   422
  PlatformOp,
2d56326b98f0 8188224: Generalize Atomic::load/store to use templates
eosterlund
parents: 47578
diff changeset
   423
  typename EnableIf<IsIntegral<T>::value || IsRegisteredEnum<T>::value>::type>
2d56326b98f0 8188224: Generalize Atomic::load/store to use templates
eosterlund
parents: 47578
diff changeset
   424
  VALUE_OBJ_CLASS_SPEC
2d56326b98f0 8188224: Generalize Atomic::load/store to use templates
eosterlund
parents: 47578
diff changeset
   425
{
2d56326b98f0 8188224: Generalize Atomic::load/store to use templates
eosterlund
parents: 47578
diff changeset
   426
  void operator()(T new_value, T volatile* dest) const {
2d56326b98f0 8188224: Generalize Atomic::load/store to use templates
eosterlund
parents: 47578
diff changeset
   427
    // Forward to the platform handler for the size of T.
2d56326b98f0 8188224: Generalize Atomic::load/store to use templates
eosterlund
parents: 47578
diff changeset
   428
    PlatformOp()(new_value, dest);
2d56326b98f0 8188224: Generalize Atomic::load/store to use templates
eosterlund
parents: 47578
diff changeset
   429
  }
2d56326b98f0 8188224: Generalize Atomic::load/store to use templates
eosterlund
parents: 47578
diff changeset
   430
};
2d56326b98f0 8188224: Generalize Atomic::load/store to use templates
eosterlund
parents: 47578
diff changeset
   431
2d56326b98f0 8188224: Generalize Atomic::load/store to use templates
eosterlund
parents: 47578
diff changeset
   432
// Handle store for pointer types.
2d56326b98f0 8188224: Generalize Atomic::load/store to use templates
eosterlund
parents: 47578
diff changeset
   433
//
2d56326b98f0 8188224: Generalize Atomic::load/store to use templates
eosterlund
parents: 47578
diff changeset
   434
// The new_value must be implicitly convertible to the
2d56326b98f0 8188224: Generalize Atomic::load/store to use templates
eosterlund
parents: 47578
diff changeset
   435
// destination's type; it must be type-correct to store the
2d56326b98f0 8188224: Generalize Atomic::load/store to use templates
eosterlund
parents: 47578
diff changeset
   436
// new_value in the destination.
2d56326b98f0 8188224: Generalize Atomic::load/store to use templates
eosterlund
parents: 47578
diff changeset
   437
template<typename T, typename D, typename PlatformOp>
2d56326b98f0 8188224: Generalize Atomic::load/store to use templates
eosterlund
parents: 47578
diff changeset
   438
struct Atomic::StoreImpl<
2d56326b98f0 8188224: Generalize Atomic::load/store to use templates
eosterlund
parents: 47578
diff changeset
   439
  T*, D*,
2d56326b98f0 8188224: Generalize Atomic::load/store to use templates
eosterlund
parents: 47578
diff changeset
   440
  PlatformOp,
2d56326b98f0 8188224: Generalize Atomic::load/store to use templates
eosterlund
parents: 47578
diff changeset
   441
  typename EnableIf<Atomic::IsPointerConvertible<T*, D*>::value>::type>
2d56326b98f0 8188224: Generalize Atomic::load/store to use templates
eosterlund
parents: 47578
diff changeset
   442
  VALUE_OBJ_CLASS_SPEC
2d56326b98f0 8188224: Generalize Atomic::load/store to use templates
eosterlund
parents: 47578
diff changeset
   443
{
2d56326b98f0 8188224: Generalize Atomic::load/store to use templates
eosterlund
parents: 47578
diff changeset
   444
  void operator()(T* new_value, D* volatile* dest) const {
2d56326b98f0 8188224: Generalize Atomic::load/store to use templates
eosterlund
parents: 47578
diff changeset
   445
    // Allow derived to base conversion, and adding cv-qualifiers.
2d56326b98f0 8188224: Generalize Atomic::load/store to use templates
eosterlund
parents: 47578
diff changeset
   446
    D* value = new_value;
2d56326b98f0 8188224: Generalize Atomic::load/store to use templates
eosterlund
parents: 47578
diff changeset
   447
    PlatformOp()(value, dest);
2d56326b98f0 8188224: Generalize Atomic::load/store to use templates
eosterlund
parents: 47578
diff changeset
   448
  }
2d56326b98f0 8188224: Generalize Atomic::load/store to use templates
eosterlund
parents: 47578
diff changeset
   449
};
2d56326b98f0 8188224: Generalize Atomic::load/store to use templates
eosterlund
parents: 47578
diff changeset
   450
2d56326b98f0 8188224: Generalize Atomic::load/store to use templates
eosterlund
parents: 47578
diff changeset
   451
// Handle store for types that have a translator.
2d56326b98f0 8188224: Generalize Atomic::load/store to use templates
eosterlund
parents: 47578
diff changeset
   452
//
2d56326b98f0 8188224: Generalize Atomic::load/store to use templates
eosterlund
parents: 47578
diff changeset
   453
// All the involved types must be identical.
2d56326b98f0 8188224: Generalize Atomic::load/store to use templates
eosterlund
parents: 47578
diff changeset
   454
//
2d56326b98f0 8188224: Generalize Atomic::load/store to use templates
eosterlund
parents: 47578
diff changeset
   455
// This translates the original call into a call on the decayed
2d56326b98f0 8188224: Generalize Atomic::load/store to use templates
eosterlund
parents: 47578
diff changeset
   456
// arguments.
2d56326b98f0 8188224: Generalize Atomic::load/store to use templates
eosterlund
parents: 47578
diff changeset
   457
template<typename T, typename PlatformOp>
2d56326b98f0 8188224: Generalize Atomic::load/store to use templates
eosterlund
parents: 47578
diff changeset
   458
struct Atomic::StoreImpl<
2d56326b98f0 8188224: Generalize Atomic::load/store to use templates
eosterlund
parents: 47578
diff changeset
   459
  T, T,
2d56326b98f0 8188224: Generalize Atomic::load/store to use templates
eosterlund
parents: 47578
diff changeset
   460
  PlatformOp,
2d56326b98f0 8188224: Generalize Atomic::load/store to use templates
eosterlund
parents: 47578
diff changeset
   461
  typename EnableIf<PrimitiveConversions::Translate<T>::value>::type>
2d56326b98f0 8188224: Generalize Atomic::load/store to use templates
eosterlund
parents: 47578
diff changeset
   462
  VALUE_OBJ_CLASS_SPEC
2d56326b98f0 8188224: Generalize Atomic::load/store to use templates
eosterlund
parents: 47578
diff changeset
   463
{
2d56326b98f0 8188224: Generalize Atomic::load/store to use templates
eosterlund
parents: 47578
diff changeset
   464
  void operator()(T new_value, T volatile* dest) const {
2d56326b98f0 8188224: Generalize Atomic::load/store to use templates
eosterlund
parents: 47578
diff changeset
   465
    typedef PrimitiveConversions::Translate<T> Translator;
2d56326b98f0 8188224: Generalize Atomic::load/store to use templates
eosterlund
parents: 47578
diff changeset
   466
    typedef typename Translator::Decayed Decayed;
2d56326b98f0 8188224: Generalize Atomic::load/store to use templates
eosterlund
parents: 47578
diff changeset
   467
    STATIC_ASSERT(sizeof(T) == sizeof(Decayed));
2d56326b98f0 8188224: Generalize Atomic::load/store to use templates
eosterlund
parents: 47578
diff changeset
   468
    PlatformOp()(Translator::decay(new_value),
2d56326b98f0 8188224: Generalize Atomic::load/store to use templates
eosterlund
parents: 47578
diff changeset
   469
                 reinterpret_cast<Decayed volatile*>(dest));
2d56326b98f0 8188224: Generalize Atomic::load/store to use templates
eosterlund
parents: 47578
diff changeset
   470
  }
2d56326b98f0 8188224: Generalize Atomic::load/store to use templates
eosterlund
parents: 47578
diff changeset
   471
};
2d56326b98f0 8188224: Generalize Atomic::load/store to use templates
eosterlund
parents: 47578
diff changeset
   472
2d56326b98f0 8188224: Generalize Atomic::load/store to use templates
eosterlund
parents: 47578
diff changeset
   473
// Default implementation of atomic store if a specific platform
2d56326b98f0 8188224: Generalize Atomic::load/store to use templates
eosterlund
parents: 47578
diff changeset
   474
// does not provide a specialization for a certain size class.
2d56326b98f0 8188224: Generalize Atomic::load/store to use templates
eosterlund
parents: 47578
diff changeset
   475
// For increased safety, the default implementation only allows
2d56326b98f0 8188224: Generalize Atomic::load/store to use templates
eosterlund
parents: 47578
diff changeset
   476
// storing types that are pointer sized or smaller. If a platform still
2d56326b98f0 8188224: Generalize Atomic::load/store to use templates
eosterlund
parents: 47578
diff changeset
   477
// supports wide atomics, then it has to use specialization
2d56326b98f0 8188224: Generalize Atomic::load/store to use templates
eosterlund
parents: 47578
diff changeset
   478
// of Atomic::PlatformStore for that wider size class.
2d56326b98f0 8188224: Generalize Atomic::load/store to use templates
eosterlund
parents: 47578
diff changeset
   479
template<size_t byte_size>
2d56326b98f0 8188224: Generalize Atomic::load/store to use templates
eosterlund
parents: 47578
diff changeset
   480
struct Atomic::PlatformStore VALUE_OBJ_CLASS_SPEC {
2d56326b98f0 8188224: Generalize Atomic::load/store to use templates
eosterlund
parents: 47578
diff changeset
   481
  template<typename T>
2d56326b98f0 8188224: Generalize Atomic::load/store to use templates
eosterlund
parents: 47578
diff changeset
   482
  void operator()(T new_value,
2d56326b98f0 8188224: Generalize Atomic::load/store to use templates
eosterlund
parents: 47578
diff changeset
   483
                  T volatile* dest) const {
2d56326b98f0 8188224: Generalize Atomic::load/store to use templates
eosterlund
parents: 47578
diff changeset
   484
    STATIC_ASSERT(sizeof(T) <= sizeof(void*)); // wide atomics need specialization
2d56326b98f0 8188224: Generalize Atomic::load/store to use templates
eosterlund
parents: 47578
diff changeset
   485
    (void)const_cast<T&>(*dest = new_value);
2d56326b98f0 8188224: Generalize Atomic::load/store to use templates
eosterlund
parents: 47578
diff changeset
   486
  }
2d56326b98f0 8188224: Generalize Atomic::load/store to use templates
eosterlund
parents: 47578
diff changeset
   487
};
2d56326b98f0 8188224: Generalize Atomic::load/store to use templates
eosterlund
parents: 47578
diff changeset
   488
46993
dd0f91c85ffc 8186476: Generalize Atomic::add with templates
eosterlund
parents: 46958
diff changeset
   489
// Define FetchAndAdd and AddAndFetch helper classes before including
dd0f91c85ffc 8186476: Generalize Atomic::add with templates
eosterlund
parents: 46958
diff changeset
   490
// platform file, which may use these as base classes, requiring they
dd0f91c85ffc 8186476: Generalize Atomic::add with templates
eosterlund
parents: 46958
diff changeset
   491
// be complete.
dd0f91c85ffc 8186476: Generalize Atomic::add with templates
eosterlund
parents: 46958
diff changeset
   492
dd0f91c85ffc 8186476: Generalize Atomic::add with templates
eosterlund
parents: 46958
diff changeset
   493
template<typename Derived>
dd0f91c85ffc 8186476: Generalize Atomic::add with templates
eosterlund
parents: 46958
diff changeset
   494
struct Atomic::FetchAndAdd VALUE_OBJ_CLASS_SPEC {
dd0f91c85ffc 8186476: Generalize Atomic::add with templates
eosterlund
parents: 46958
diff changeset
   495
  template<typename I, typename D>
dd0f91c85ffc 8186476: Generalize Atomic::add with templates
eosterlund
parents: 46958
diff changeset
   496
  D operator()(I add_value, D volatile* dest) const;
dd0f91c85ffc 8186476: Generalize Atomic::add with templates
eosterlund
parents: 46958
diff changeset
   497
};
dd0f91c85ffc 8186476: Generalize Atomic::add with templates
eosterlund
parents: 46958
diff changeset
   498
dd0f91c85ffc 8186476: Generalize Atomic::add with templates
eosterlund
parents: 46958
diff changeset
   499
template<typename Derived>
dd0f91c85ffc 8186476: Generalize Atomic::add with templates
eosterlund
parents: 46958
diff changeset
   500
struct Atomic::AddAndFetch VALUE_OBJ_CLASS_SPEC {
dd0f91c85ffc 8186476: Generalize Atomic::add with templates
eosterlund
parents: 46958
diff changeset
   501
  template<typename I, typename D>
dd0f91c85ffc 8186476: Generalize Atomic::add with templates
eosterlund
parents: 46958
diff changeset
   502
  D operator()(I add_value, D volatile* dest) const;
dd0f91c85ffc 8186476: Generalize Atomic::add with templates
eosterlund
parents: 46958
diff changeset
   503
};
dd0f91c85ffc 8186476: Generalize Atomic::add with templates
eosterlund
parents: 46958
diff changeset
   504
47552
8a3599d60996 8186838: Generalize Atomic::inc/dec with templates
eosterlund
parents: 47216
diff changeset
   505
template<typename D>
8a3599d60996 8186838: Generalize Atomic::inc/dec with templates
eosterlund
parents: 47216
diff changeset
   506
inline void Atomic::inc(D volatile* dest) {
8a3599d60996 8186838: Generalize Atomic::inc/dec with templates
eosterlund
parents: 47216
diff changeset
   507
  STATIC_ASSERT(IsPointer<D>::value || IsIntegral<D>::value);
8a3599d60996 8186838: Generalize Atomic::inc/dec with templates
eosterlund
parents: 47216
diff changeset
   508
  typedef typename Conditional<IsPointer<D>::value, ptrdiff_t, D>::type I;
8a3599d60996 8186838: Generalize Atomic::inc/dec with templates
eosterlund
parents: 47216
diff changeset
   509
  Atomic::add(I(1), dest);
8a3599d60996 8186838: Generalize Atomic::inc/dec with templates
eosterlund
parents: 47216
diff changeset
   510
}
8a3599d60996 8186838: Generalize Atomic::inc/dec with templates
eosterlund
parents: 47216
diff changeset
   511
8a3599d60996 8186838: Generalize Atomic::inc/dec with templates
eosterlund
parents: 47216
diff changeset
   512
template<typename D>
8a3599d60996 8186838: Generalize Atomic::inc/dec with templates
eosterlund
parents: 47216
diff changeset
   513
inline void Atomic::dec(D volatile* dest) {
8a3599d60996 8186838: Generalize Atomic::inc/dec with templates
eosterlund
parents: 47216
diff changeset
   514
  STATIC_ASSERT(IsPointer<D>::value || IsIntegral<D>::value);
8a3599d60996 8186838: Generalize Atomic::inc/dec with templates
eosterlund
parents: 47216
diff changeset
   515
  typedef typename Conditional<IsPointer<D>::value, ptrdiff_t, D>::type I;
8a3599d60996 8186838: Generalize Atomic::inc/dec with templates
eosterlund
parents: 47216
diff changeset
   516
  // Assumes two's complement integer representation.
8a3599d60996 8186838: Generalize Atomic::inc/dec with templates
eosterlund
parents: 47216
diff changeset
   517
  #pragma warning(suppress: 4146)
8a3599d60996 8186838: Generalize Atomic::inc/dec with templates
eosterlund
parents: 47216
diff changeset
   518
  Atomic::add(I(-1), dest);
8a3599d60996 8186838: Generalize Atomic::inc/dec with templates
eosterlund
parents: 47216
diff changeset
   519
}
8a3599d60996 8186838: Generalize Atomic::inc/dec with templates
eosterlund
parents: 47216
diff changeset
   520
47634
6a0c42c40cd1 8188220: Remove Atomic::*_ptr() uses and overloads from hotspot
coleenp
parents: 47609
diff changeset
   521
template<typename I, typename D>
6a0c42c40cd1 8188220: Remove Atomic::*_ptr() uses and overloads from hotspot
coleenp
parents: 47609
diff changeset
   522
inline D Atomic::sub(I sub_value, D volatile* dest) {
6a0c42c40cd1 8188220: Remove Atomic::*_ptr() uses and overloads from hotspot
coleenp
parents: 47609
diff changeset
   523
  STATIC_ASSERT(IsPointer<D>::value || IsIntegral<D>::value);
6a0c42c40cd1 8188220: Remove Atomic::*_ptr() uses and overloads from hotspot
coleenp
parents: 47609
diff changeset
   524
  STATIC_ASSERT(IsIntegral<I>::value);
6a0c42c40cd1 8188220: Remove Atomic::*_ptr() uses and overloads from hotspot
coleenp
parents: 47609
diff changeset
   525
  // If D is a pointer type, use [u]intptr_t as the addend type,
6a0c42c40cd1 8188220: Remove Atomic::*_ptr() uses and overloads from hotspot
coleenp
parents: 47609
diff changeset
   526
  // matching signedness of I.  Otherwise, use D as the addend type.
6a0c42c40cd1 8188220: Remove Atomic::*_ptr() uses and overloads from hotspot
coleenp
parents: 47609
diff changeset
   527
  typedef typename Conditional<IsSigned<I>::value, intptr_t, uintptr_t>::type PI;
6a0c42c40cd1 8188220: Remove Atomic::*_ptr() uses and overloads from hotspot
coleenp
parents: 47609
diff changeset
   528
  typedef typename Conditional<IsPointer<D>::value, PI, D>::type AddendType;
6a0c42c40cd1 8188220: Remove Atomic::*_ptr() uses and overloads from hotspot
coleenp
parents: 47609
diff changeset
   529
  // Only allow conversions that can't change the value.
6a0c42c40cd1 8188220: Remove Atomic::*_ptr() uses and overloads from hotspot
coleenp
parents: 47609
diff changeset
   530
  STATIC_ASSERT(IsSigned<I>::value == IsSigned<AddendType>::value);
6a0c42c40cd1 8188220: Remove Atomic::*_ptr() uses and overloads from hotspot
coleenp
parents: 47609
diff changeset
   531
  STATIC_ASSERT(sizeof(I) <= sizeof(AddendType));
6a0c42c40cd1 8188220: Remove Atomic::*_ptr() uses and overloads from hotspot
coleenp
parents: 47609
diff changeset
   532
  AddendType addend = sub_value;
6a0c42c40cd1 8188220: Remove Atomic::*_ptr() uses and overloads from hotspot
coleenp
parents: 47609
diff changeset
   533
  // Assumes two's complement integer representation.
6a0c42c40cd1 8188220: Remove Atomic::*_ptr() uses and overloads from hotspot
coleenp
parents: 47609
diff changeset
   534
  #pragma warning(suppress: 4146) // In case AddendType is not signed.
6a0c42c40cd1 8188220: Remove Atomic::*_ptr() uses and overloads from hotspot
coleenp
parents: 47609
diff changeset
   535
  return Atomic::add(-addend, dest);
6a0c42c40cd1 8188220: Remove Atomic::*_ptr() uses and overloads from hotspot
coleenp
parents: 47609
diff changeset
   536
}
6a0c42c40cd1 8188220: Remove Atomic::*_ptr() uses and overloads from hotspot
coleenp
parents: 47609
diff changeset
   537
46958
a13bd8c6b7a2 8186166: Generalize Atomic::cmpxchg with templates
eosterlund
parents: 46625
diff changeset
   538
// Define the class before including platform file, which may specialize
a13bd8c6b7a2 8186166: Generalize Atomic::cmpxchg with templates
eosterlund
parents: 46625
diff changeset
   539
// the operator definition.  No generic definition of specializations
a13bd8c6b7a2 8186166: Generalize Atomic::cmpxchg with templates
eosterlund
parents: 46625
diff changeset
   540
// of the operator template are provided, nor are there any generic
a13bd8c6b7a2 8186166: Generalize Atomic::cmpxchg with templates
eosterlund
parents: 46625
diff changeset
   541
// specializations of the class.  The platform file is responsible for
a13bd8c6b7a2 8186166: Generalize Atomic::cmpxchg with templates
eosterlund
parents: 46625
diff changeset
   542
// providing those.
a13bd8c6b7a2 8186166: Generalize Atomic::cmpxchg with templates
eosterlund
parents: 46625
diff changeset
   543
template<size_t byte_size>
a13bd8c6b7a2 8186166: Generalize Atomic::cmpxchg with templates
eosterlund
parents: 46625
diff changeset
   544
struct Atomic::PlatformCmpxchg VALUE_OBJ_CLASS_SPEC {
a13bd8c6b7a2 8186166: Generalize Atomic::cmpxchg with templates
eosterlund
parents: 46625
diff changeset
   545
  template<typename T>
a13bd8c6b7a2 8186166: Generalize Atomic::cmpxchg with templates
eosterlund
parents: 46625
diff changeset
   546
  T operator()(T exchange_value,
a13bd8c6b7a2 8186166: Generalize Atomic::cmpxchg with templates
eosterlund
parents: 46625
diff changeset
   547
               T volatile* dest,
a13bd8c6b7a2 8186166: Generalize Atomic::cmpxchg with templates
eosterlund
parents: 46625
diff changeset
   548
               T compare_value,
a13bd8c6b7a2 8186166: Generalize Atomic::cmpxchg with templates
eosterlund
parents: 46625
diff changeset
   549
               cmpxchg_memory_order order) const;
a13bd8c6b7a2 8186166: Generalize Atomic::cmpxchg with templates
eosterlund
parents: 46625
diff changeset
   550
};
a13bd8c6b7a2 8186166: Generalize Atomic::cmpxchg with templates
eosterlund
parents: 46625
diff changeset
   551
a13bd8c6b7a2 8186166: Generalize Atomic::cmpxchg with templates
eosterlund
parents: 46625
diff changeset
   552
// Define the class before including platform file, which may use this
a13bd8c6b7a2 8186166: Generalize Atomic::cmpxchg with templates
eosterlund
parents: 46625
diff changeset
   553
// as a base class, requiring it be complete.  The definition is later
a13bd8c6b7a2 8186166: Generalize Atomic::cmpxchg with templates
eosterlund
parents: 46625
diff changeset
   554
// in this file, near the other definitions related to cmpxchg.
a13bd8c6b7a2 8186166: Generalize Atomic::cmpxchg with templates
eosterlund
parents: 46625
diff changeset
   555
struct Atomic::CmpxchgByteUsingInt VALUE_OBJ_CLASS_SPEC {
a13bd8c6b7a2 8186166: Generalize Atomic::cmpxchg with templates
eosterlund
parents: 46625
diff changeset
   556
  template<typename T>
a13bd8c6b7a2 8186166: Generalize Atomic::cmpxchg with templates
eosterlund
parents: 46625
diff changeset
   557
  T operator()(T exchange_value,
a13bd8c6b7a2 8186166: Generalize Atomic::cmpxchg with templates
eosterlund
parents: 46625
diff changeset
   558
               T volatile* dest,
a13bd8c6b7a2 8186166: Generalize Atomic::cmpxchg with templates
eosterlund
parents: 46625
diff changeset
   559
               T compare_value,
a13bd8c6b7a2 8186166: Generalize Atomic::cmpxchg with templates
eosterlund
parents: 46625
diff changeset
   560
               cmpxchg_memory_order order) const;
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   561
};
7397
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 5547
diff changeset
   562
47578
09c41c4913d9 8187977: Generalize Atomic::xchg to use templates
eosterlund
parents: 47552
diff changeset
   563
// Define the class before including platform file, which may specialize
09c41c4913d9 8187977: Generalize Atomic::xchg to use templates
eosterlund
parents: 47552
diff changeset
   564
// the operator definition.  No generic definition of specializations
09c41c4913d9 8187977: Generalize Atomic::xchg to use templates
eosterlund
parents: 47552
diff changeset
   565
// of the operator template are provided, nor are there any generic
09c41c4913d9 8187977: Generalize Atomic::xchg to use templates
eosterlund
parents: 47552
diff changeset
   566
// specializations of the class.  The platform file is responsible for
09c41c4913d9 8187977: Generalize Atomic::xchg to use templates
eosterlund
parents: 47552
diff changeset
   567
// providing those.
09c41c4913d9 8187977: Generalize Atomic::xchg to use templates
eosterlund
parents: 47552
diff changeset
   568
template<size_t byte_size>
09c41c4913d9 8187977: Generalize Atomic::xchg to use templates
eosterlund
parents: 47552
diff changeset
   569
struct Atomic::PlatformXchg VALUE_OBJ_CLASS_SPEC {
09c41c4913d9 8187977: Generalize Atomic::xchg to use templates
eosterlund
parents: 47552
diff changeset
   570
  template<typename T>
09c41c4913d9 8187977: Generalize Atomic::xchg to use templates
eosterlund
parents: 47552
diff changeset
   571
  T operator()(T exchange_value,
09c41c4913d9 8187977: Generalize Atomic::xchg to use templates
eosterlund
parents: 47552
diff changeset
   572
               T volatile* dest) const;
09c41c4913d9 8187977: Generalize Atomic::xchg to use templates
eosterlund
parents: 47552
diff changeset
   573
};
09c41c4913d9 8187977: Generalize Atomic::xchg to use templates
eosterlund
parents: 47552
diff changeset
   574
40655
9f644073d3a0 8157907: Incorrect inclusion of atomic.hpp instead of atomic.inline.hpp
dholmes
parents: 39404
diff changeset
   575
// platform specific in-line definitions - must come before shared definitions
9f644073d3a0 8157907: Incorrect inclusion of atomic.hpp instead of atomic.inline.hpp
dholmes
parents: 39404
diff changeset
   576
9f644073d3a0 8157907: Incorrect inclusion of atomic.hpp instead of atomic.inline.hpp
dholmes
parents: 39404
diff changeset
   577
#include OS_CPU_HEADER(atomic)
18438
9ea6bbfe0b83 8009575: Reduce Symbol::_refcount from 4 bytes to 2 bytes
iklam
parents: 15803
diff changeset
   578
40655
9f644073d3a0 8157907: Incorrect inclusion of atomic.hpp instead of atomic.inline.hpp
dholmes
parents: 39404
diff changeset
   579
// shared in-line definitions
9f644073d3a0 8157907: Incorrect inclusion of atomic.hpp instead of atomic.inline.hpp
dholmes
parents: 39404
diff changeset
   580
9f644073d3a0 8157907: Incorrect inclusion of atomic.hpp instead of atomic.inline.hpp
dholmes
parents: 39404
diff changeset
   581
// size_t casts...
9f644073d3a0 8157907: Incorrect inclusion of atomic.hpp instead of atomic.inline.hpp
dholmes
parents: 39404
diff changeset
   582
#if (SIZE_MAX != UINTPTR_MAX)
9f644073d3a0 8157907: Incorrect inclusion of atomic.hpp instead of atomic.inline.hpp
dholmes
parents: 39404
diff changeset
   583
#error size_t is not WORD_SIZE, interesting platform, but missing implementation here
18438
9ea6bbfe0b83 8009575: Reduce Symbol::_refcount from 4 bytes to 2 bytes
iklam
parents: 15803
diff changeset
   584
#endif
9ea6bbfe0b83 8009575: Reduce Symbol::_refcount from 4 bytes to 2 bytes
iklam
parents: 15803
diff changeset
   585
47593
2d56326b98f0 8188224: Generalize Atomic::load/store to use templates
eosterlund
parents: 47578
diff changeset
   586
template<typename T>
2d56326b98f0 8188224: Generalize Atomic::load/store to use templates
eosterlund
parents: 47578
diff changeset
   587
inline T Atomic::load(const volatile T* dest) {
2d56326b98f0 8188224: Generalize Atomic::load/store to use templates
eosterlund
parents: 47578
diff changeset
   588
  return LoadImpl<T, PlatformLoad<sizeof(T)> >()(dest);
2d56326b98f0 8188224: Generalize Atomic::load/store to use templates
eosterlund
parents: 47578
diff changeset
   589
}
2d56326b98f0 8188224: Generalize Atomic::load/store to use templates
eosterlund
parents: 47578
diff changeset
   590
2d56326b98f0 8188224: Generalize Atomic::load/store to use templates
eosterlund
parents: 47578
diff changeset
   591
template<typename T, typename D>
2d56326b98f0 8188224: Generalize Atomic::load/store to use templates
eosterlund
parents: 47578
diff changeset
   592
inline void Atomic::store(T store_value, volatile D* dest) {
2d56326b98f0 8188224: Generalize Atomic::load/store to use templates
eosterlund
parents: 47578
diff changeset
   593
  StoreImpl<T, D, PlatformStore<sizeof(D)> >()(store_value, dest);
2d56326b98f0 8188224: Generalize Atomic::load/store to use templates
eosterlund
parents: 47578
diff changeset
   594
}
2d56326b98f0 8188224: Generalize Atomic::load/store to use templates
eosterlund
parents: 47578
diff changeset
   595
46993
dd0f91c85ffc 8186476: Generalize Atomic::add with templates
eosterlund
parents: 46958
diff changeset
   596
template<typename I, typename D>
dd0f91c85ffc 8186476: Generalize Atomic::add with templates
eosterlund
parents: 46958
diff changeset
   597
inline D Atomic::add(I add_value, D volatile* dest) {
dd0f91c85ffc 8186476: Generalize Atomic::add with templates
eosterlund
parents: 46958
diff changeset
   598
  return AddImpl<I, D>()(add_value, dest);
dd0f91c85ffc 8186476: Generalize Atomic::add with templates
eosterlund
parents: 46958
diff changeset
   599
}
dd0f91c85ffc 8186476: Generalize Atomic::add with templates
eosterlund
parents: 46958
diff changeset
   600
dd0f91c85ffc 8186476: Generalize Atomic::add with templates
eosterlund
parents: 46958
diff changeset
   601
template<typename I, typename D>
dd0f91c85ffc 8186476: Generalize Atomic::add with templates
eosterlund
parents: 46958
diff changeset
   602
struct Atomic::AddImpl<
dd0f91c85ffc 8186476: Generalize Atomic::add with templates
eosterlund
parents: 46958
diff changeset
   603
  I, D,
dd0f91c85ffc 8186476: Generalize Atomic::add with templates
eosterlund
parents: 46958
diff changeset
   604
  typename EnableIf<IsIntegral<I>::value &&
dd0f91c85ffc 8186476: Generalize Atomic::add with templates
eosterlund
parents: 46958
diff changeset
   605
                    IsIntegral<D>::value &&
dd0f91c85ffc 8186476: Generalize Atomic::add with templates
eosterlund
parents: 46958
diff changeset
   606
                    (sizeof(I) <= sizeof(D)) &&
dd0f91c85ffc 8186476: Generalize Atomic::add with templates
eosterlund
parents: 46958
diff changeset
   607
                    (IsSigned<I>::value == IsSigned<D>::value)>::type>
dd0f91c85ffc 8186476: Generalize Atomic::add with templates
eosterlund
parents: 46958
diff changeset
   608
  VALUE_OBJ_CLASS_SPEC
dd0f91c85ffc 8186476: Generalize Atomic::add with templates
eosterlund
parents: 46958
diff changeset
   609
{
dd0f91c85ffc 8186476: Generalize Atomic::add with templates
eosterlund
parents: 46958
diff changeset
   610
  D operator()(I add_value, D volatile* dest) const {
dd0f91c85ffc 8186476: Generalize Atomic::add with templates
eosterlund
parents: 46958
diff changeset
   611
    D addend = add_value;
dd0f91c85ffc 8186476: Generalize Atomic::add with templates
eosterlund
parents: 46958
diff changeset
   612
    return PlatformAdd<sizeof(D)>()(addend, dest);
dd0f91c85ffc 8186476: Generalize Atomic::add with templates
eosterlund
parents: 46958
diff changeset
   613
  }
dd0f91c85ffc 8186476: Generalize Atomic::add with templates
eosterlund
parents: 46958
diff changeset
   614
};
dd0f91c85ffc 8186476: Generalize Atomic::add with templates
eosterlund
parents: 46958
diff changeset
   615
dd0f91c85ffc 8186476: Generalize Atomic::add with templates
eosterlund
parents: 46958
diff changeset
   616
template<typename I, typename P>
dd0f91c85ffc 8186476: Generalize Atomic::add with templates
eosterlund
parents: 46958
diff changeset
   617
struct Atomic::AddImpl<
dd0f91c85ffc 8186476: Generalize Atomic::add with templates
eosterlund
parents: 46958
diff changeset
   618
  I, P*,
dd0f91c85ffc 8186476: Generalize Atomic::add with templates
eosterlund
parents: 46958
diff changeset
   619
  typename EnableIf<IsIntegral<I>::value && (sizeof(I) <= sizeof(P*))>::type>
dd0f91c85ffc 8186476: Generalize Atomic::add with templates
eosterlund
parents: 46958
diff changeset
   620
  VALUE_OBJ_CLASS_SPEC
dd0f91c85ffc 8186476: Generalize Atomic::add with templates
eosterlund
parents: 46958
diff changeset
   621
{
dd0f91c85ffc 8186476: Generalize Atomic::add with templates
eosterlund
parents: 46958
diff changeset
   622
  P* operator()(I add_value, P* volatile* dest) const {
dd0f91c85ffc 8186476: Generalize Atomic::add with templates
eosterlund
parents: 46958
diff changeset
   623
    STATIC_ASSERT(sizeof(intptr_t) == sizeof(P*));
dd0f91c85ffc 8186476: Generalize Atomic::add with templates
eosterlund
parents: 46958
diff changeset
   624
    STATIC_ASSERT(sizeof(uintptr_t) == sizeof(P*));
dd0f91c85ffc 8186476: Generalize Atomic::add with templates
eosterlund
parents: 46958
diff changeset
   625
    typedef typename Conditional<IsSigned<I>::value,
dd0f91c85ffc 8186476: Generalize Atomic::add with templates
eosterlund
parents: 46958
diff changeset
   626
                                 intptr_t,
dd0f91c85ffc 8186476: Generalize Atomic::add with templates
eosterlund
parents: 46958
diff changeset
   627
                                 uintptr_t>::type CI;
dd0f91c85ffc 8186476: Generalize Atomic::add with templates
eosterlund
parents: 46958
diff changeset
   628
    CI addend = add_value;
dd0f91c85ffc 8186476: Generalize Atomic::add with templates
eosterlund
parents: 46958
diff changeset
   629
    return PlatformAdd<sizeof(P*)>()(addend, dest);
dd0f91c85ffc 8186476: Generalize Atomic::add with templates
eosterlund
parents: 46958
diff changeset
   630
  }
dd0f91c85ffc 8186476: Generalize Atomic::add with templates
eosterlund
parents: 46958
diff changeset
   631
};
dd0f91c85ffc 8186476: Generalize Atomic::add with templates
eosterlund
parents: 46958
diff changeset
   632
dd0f91c85ffc 8186476: Generalize Atomic::add with templates
eosterlund
parents: 46958
diff changeset
   633
// Most platforms do not support atomic add on a 2-byte value. However,
dd0f91c85ffc 8186476: Generalize Atomic::add with templates
eosterlund
parents: 46958
diff changeset
   634
// if the value occupies the most significant 16 bits of an aligned 32-bit
dd0f91c85ffc 8186476: Generalize Atomic::add with templates
eosterlund
parents: 46958
diff changeset
   635
// word, then we can do this with an atomic add of (add_value << 16)
dd0f91c85ffc 8186476: Generalize Atomic::add with templates
eosterlund
parents: 46958
diff changeset
   636
// to the 32-bit word.
dd0f91c85ffc 8186476: Generalize Atomic::add with templates
eosterlund
parents: 46958
diff changeset
   637
//
dd0f91c85ffc 8186476: Generalize Atomic::add with templates
eosterlund
parents: 46958
diff changeset
   638
// The least significant parts of this 32-bit word will never be affected, even
dd0f91c85ffc 8186476: Generalize Atomic::add with templates
eosterlund
parents: 46958
diff changeset
   639
// in case of overflow/underflow.
dd0f91c85ffc 8186476: Generalize Atomic::add with templates
eosterlund
parents: 46958
diff changeset
   640
//
dd0f91c85ffc 8186476: Generalize Atomic::add with templates
eosterlund
parents: 46958
diff changeset
   641
// Use the ATOMIC_SHORT_PAIR macro (see macros.hpp) to get the desired alignment.
dd0f91c85ffc 8186476: Generalize Atomic::add with templates
eosterlund
parents: 46958
diff changeset
   642
template<>
48468
7cc7de9bf4a4 8186903: Remove j-types from Atomic
coleenp
parents: 47634
diff changeset
   643
struct Atomic::AddImpl<short, short> VALUE_OBJ_CLASS_SPEC {
7cc7de9bf4a4 8186903: Remove j-types from Atomic
coleenp
parents: 47634
diff changeset
   644
  short operator()(short add_value, short volatile* dest) const {
46993
dd0f91c85ffc 8186476: Generalize Atomic::add with templates
eosterlund
parents: 46958
diff changeset
   645
#ifdef VM_LITTLE_ENDIAN
dd0f91c85ffc 8186476: Generalize Atomic::add with templates
eosterlund
parents: 46958
diff changeset
   646
    assert((intx(dest) & 0x03) == 0x02, "wrong alignment");
48468
7cc7de9bf4a4 8186903: Remove j-types from Atomic
coleenp
parents: 47634
diff changeset
   647
    int new_value = Atomic::add(add_value << 16, (volatile int*)(dest-1));
46993
dd0f91c85ffc 8186476: Generalize Atomic::add with templates
eosterlund
parents: 46958
diff changeset
   648
#else
dd0f91c85ffc 8186476: Generalize Atomic::add with templates
eosterlund
parents: 46958
diff changeset
   649
    assert((intx(dest) & 0x03) == 0x00, "wrong alignment");
48468
7cc7de9bf4a4 8186903: Remove j-types from Atomic
coleenp
parents: 47634
diff changeset
   650
    int new_value = Atomic::add(add_value << 16, (volatile int*)(dest));
46993
dd0f91c85ffc 8186476: Generalize Atomic::add with templates
eosterlund
parents: 46958
diff changeset
   651
#endif
48468
7cc7de9bf4a4 8186903: Remove j-types from Atomic
coleenp
parents: 47634
diff changeset
   652
    return (short)(new_value >> 16); // preserves sign
46993
dd0f91c85ffc 8186476: Generalize Atomic::add with templates
eosterlund
parents: 46958
diff changeset
   653
  }
dd0f91c85ffc 8186476: Generalize Atomic::add with templates
eosterlund
parents: 46958
diff changeset
   654
};
dd0f91c85ffc 8186476: Generalize Atomic::add with templates
eosterlund
parents: 46958
diff changeset
   655
dd0f91c85ffc 8186476: Generalize Atomic::add with templates
eosterlund
parents: 46958
diff changeset
   656
template<typename Derived>
dd0f91c85ffc 8186476: Generalize Atomic::add with templates
eosterlund
parents: 46958
diff changeset
   657
template<typename I, typename D>
dd0f91c85ffc 8186476: Generalize Atomic::add with templates
eosterlund
parents: 46958
diff changeset
   658
inline D Atomic::FetchAndAdd<Derived>::operator()(I add_value, D volatile* dest) const {
dd0f91c85ffc 8186476: Generalize Atomic::add with templates
eosterlund
parents: 46958
diff changeset
   659
  I addend = add_value;
dd0f91c85ffc 8186476: Generalize Atomic::add with templates
eosterlund
parents: 46958
diff changeset
   660
  // If D is a pointer type P*, scale by sizeof(P).
dd0f91c85ffc 8186476: Generalize Atomic::add with templates
eosterlund
parents: 46958
diff changeset
   661
  if (IsPointer<D>::value) {
dd0f91c85ffc 8186476: Generalize Atomic::add with templates
eosterlund
parents: 46958
diff changeset
   662
    addend *= sizeof(typename RemovePointer<D>::type);
dd0f91c85ffc 8186476: Generalize Atomic::add with templates
eosterlund
parents: 46958
diff changeset
   663
  }
dd0f91c85ffc 8186476: Generalize Atomic::add with templates
eosterlund
parents: 46958
diff changeset
   664
  D old = static_cast<const Derived*>(this)->fetch_and_add(addend, dest);
dd0f91c85ffc 8186476: Generalize Atomic::add with templates
eosterlund
parents: 46958
diff changeset
   665
  return old + add_value;
dd0f91c85ffc 8186476: Generalize Atomic::add with templates
eosterlund
parents: 46958
diff changeset
   666
}
dd0f91c85ffc 8186476: Generalize Atomic::add with templates
eosterlund
parents: 46958
diff changeset
   667
dd0f91c85ffc 8186476: Generalize Atomic::add with templates
eosterlund
parents: 46958
diff changeset
   668
template<typename Derived>
dd0f91c85ffc 8186476: Generalize Atomic::add with templates
eosterlund
parents: 46958
diff changeset
   669
template<typename I, typename D>
dd0f91c85ffc 8186476: Generalize Atomic::add with templates
eosterlund
parents: 46958
diff changeset
   670
inline D Atomic::AddAndFetch<Derived>::operator()(I add_value, D volatile* dest) const {
dd0f91c85ffc 8186476: Generalize Atomic::add with templates
eosterlund
parents: 46958
diff changeset
   671
  // If D is a pointer type P*, scale by sizeof(P).
dd0f91c85ffc 8186476: Generalize Atomic::add with templates
eosterlund
parents: 46958
diff changeset
   672
  if (IsPointer<D>::value) {
dd0f91c85ffc 8186476: Generalize Atomic::add with templates
eosterlund
parents: 46958
diff changeset
   673
    add_value *= sizeof(typename RemovePointer<D>::type);
dd0f91c85ffc 8186476: Generalize Atomic::add with templates
eosterlund
parents: 46958
diff changeset
   674
  }
dd0f91c85ffc 8186476: Generalize Atomic::add with templates
eosterlund
parents: 46958
diff changeset
   675
  return static_cast<const Derived*>(this)->add_and_fetch(add_value, dest);
dd0f91c85ffc 8186476: Generalize Atomic::add with templates
eosterlund
parents: 46958
diff changeset
   676
}
dd0f91c85ffc 8186476: Generalize Atomic::add with templates
eosterlund
parents: 46958
diff changeset
   677
dd0f91c85ffc 8186476: Generalize Atomic::add with templates
eosterlund
parents: 46958
diff changeset
   678
template<typename Type, typename Fn, typename I, typename D>
dd0f91c85ffc 8186476: Generalize Atomic::add with templates
eosterlund
parents: 46958
diff changeset
   679
inline D Atomic::add_using_helper(Fn fn, I add_value, D volatile* dest) {
dd0f91c85ffc 8186476: Generalize Atomic::add with templates
eosterlund
parents: 46958
diff changeset
   680
  return PrimitiveConversions::cast<D>(
dd0f91c85ffc 8186476: Generalize Atomic::add with templates
eosterlund
parents: 46958
diff changeset
   681
    fn(PrimitiveConversions::cast<Type>(add_value),
dd0f91c85ffc 8186476: Generalize Atomic::add with templates
eosterlund
parents: 46958
diff changeset
   682
       reinterpret_cast<Type volatile*>(dest)));
40655
9f644073d3a0 8157907: Incorrect inclusion of atomic.hpp instead of atomic.inline.hpp
dholmes
parents: 39404
diff changeset
   683
}
9f644073d3a0 8157907: Incorrect inclusion of atomic.hpp instead of atomic.inline.hpp
dholmes
parents: 39404
diff changeset
   684
46958
a13bd8c6b7a2 8186166: Generalize Atomic::cmpxchg with templates
eosterlund
parents: 46625
diff changeset
   685
template<typename T, typename D, typename U>
a13bd8c6b7a2 8186166: Generalize Atomic::cmpxchg with templates
eosterlund
parents: 46625
diff changeset
   686
inline D Atomic::cmpxchg(T exchange_value,
a13bd8c6b7a2 8186166: Generalize Atomic::cmpxchg with templates
eosterlund
parents: 46625
diff changeset
   687
                         D volatile* dest,
a13bd8c6b7a2 8186166: Generalize Atomic::cmpxchg with templates
eosterlund
parents: 46625
diff changeset
   688
                         U compare_value,
a13bd8c6b7a2 8186166: Generalize Atomic::cmpxchg with templates
eosterlund
parents: 46625
diff changeset
   689
                         cmpxchg_memory_order order) {
a13bd8c6b7a2 8186166: Generalize Atomic::cmpxchg with templates
eosterlund
parents: 46625
diff changeset
   690
  return CmpxchgImpl<T, D, U>()(exchange_value, dest, compare_value, order);
a13bd8c6b7a2 8186166: Generalize Atomic::cmpxchg with templates
eosterlund
parents: 46625
diff changeset
   691
}
a13bd8c6b7a2 8186166: Generalize Atomic::cmpxchg with templates
eosterlund
parents: 46625
diff changeset
   692
a13bd8c6b7a2 8186166: Generalize Atomic::cmpxchg with templates
eosterlund
parents: 46625
diff changeset
   693
template<typename T, typename D>
a13bd8c6b7a2 8186166: Generalize Atomic::cmpxchg with templates
eosterlund
parents: 46625
diff changeset
   694
inline bool Atomic::replace_if_null(T* value, D* volatile* dest,
a13bd8c6b7a2 8186166: Generalize Atomic::cmpxchg with templates
eosterlund
parents: 46625
diff changeset
   695
                                    cmpxchg_memory_order order) {
a13bd8c6b7a2 8186166: Generalize Atomic::cmpxchg with templates
eosterlund
parents: 46625
diff changeset
   696
  // Presently using a trivial implementation in terms of cmpxchg.
a13bd8c6b7a2 8186166: Generalize Atomic::cmpxchg with templates
eosterlund
parents: 46625
diff changeset
   697
  // Consider adding platform support, to permit the use of compiler
a13bd8c6b7a2 8186166: Generalize Atomic::cmpxchg with templates
eosterlund
parents: 46625
diff changeset
   698
  // intrinsics like gcc's __sync_bool_compare_and_swap.
a13bd8c6b7a2 8186166: Generalize Atomic::cmpxchg with templates
eosterlund
parents: 46625
diff changeset
   699
  D* expected_null = NULL;
a13bd8c6b7a2 8186166: Generalize Atomic::cmpxchg with templates
eosterlund
parents: 46625
diff changeset
   700
  return expected_null == cmpxchg(value, dest, expected_null, order);
a13bd8c6b7a2 8186166: Generalize Atomic::cmpxchg with templates
eosterlund
parents: 46625
diff changeset
   701
}
a13bd8c6b7a2 8186166: Generalize Atomic::cmpxchg with templates
eosterlund
parents: 46625
diff changeset
   702
a13bd8c6b7a2 8186166: Generalize Atomic::cmpxchg with templates
eosterlund
parents: 46625
diff changeset
   703
// Handle cmpxchg for integral and enum types.
a13bd8c6b7a2 8186166: Generalize Atomic::cmpxchg with templates
eosterlund
parents: 46625
diff changeset
   704
//
a13bd8c6b7a2 8186166: Generalize Atomic::cmpxchg with templates
eosterlund
parents: 46625
diff changeset
   705
// All the involved types must be identical.
a13bd8c6b7a2 8186166: Generalize Atomic::cmpxchg with templates
eosterlund
parents: 46625
diff changeset
   706
template<typename T>
a13bd8c6b7a2 8186166: Generalize Atomic::cmpxchg with templates
eosterlund
parents: 46625
diff changeset
   707
struct Atomic::CmpxchgImpl<
a13bd8c6b7a2 8186166: Generalize Atomic::cmpxchg with templates
eosterlund
parents: 46625
diff changeset
   708
  T, T, T,
a13bd8c6b7a2 8186166: Generalize Atomic::cmpxchg with templates
eosterlund
parents: 46625
diff changeset
   709
  typename EnableIf<IsIntegral<T>::value || IsRegisteredEnum<T>::value>::type>
a13bd8c6b7a2 8186166: Generalize Atomic::cmpxchg with templates
eosterlund
parents: 46625
diff changeset
   710
  VALUE_OBJ_CLASS_SPEC
a13bd8c6b7a2 8186166: Generalize Atomic::cmpxchg with templates
eosterlund
parents: 46625
diff changeset
   711
{
a13bd8c6b7a2 8186166: Generalize Atomic::cmpxchg with templates
eosterlund
parents: 46625
diff changeset
   712
  T operator()(T exchange_value, T volatile* dest, T compare_value,
a13bd8c6b7a2 8186166: Generalize Atomic::cmpxchg with templates
eosterlund
parents: 46625
diff changeset
   713
               cmpxchg_memory_order order) const {
a13bd8c6b7a2 8186166: Generalize Atomic::cmpxchg with templates
eosterlund
parents: 46625
diff changeset
   714
    // Forward to the platform handler for the size of T.
a13bd8c6b7a2 8186166: Generalize Atomic::cmpxchg with templates
eosterlund
parents: 46625
diff changeset
   715
    return PlatformCmpxchg<sizeof(T)>()(exchange_value,
a13bd8c6b7a2 8186166: Generalize Atomic::cmpxchg with templates
eosterlund
parents: 46625
diff changeset
   716
                                        dest,
a13bd8c6b7a2 8186166: Generalize Atomic::cmpxchg with templates
eosterlund
parents: 46625
diff changeset
   717
                                        compare_value,
a13bd8c6b7a2 8186166: Generalize Atomic::cmpxchg with templates
eosterlund
parents: 46625
diff changeset
   718
                                        order);
a13bd8c6b7a2 8186166: Generalize Atomic::cmpxchg with templates
eosterlund
parents: 46625
diff changeset
   719
  }
a13bd8c6b7a2 8186166: Generalize Atomic::cmpxchg with templates
eosterlund
parents: 46625
diff changeset
   720
};
a13bd8c6b7a2 8186166: Generalize Atomic::cmpxchg with templates
eosterlund
parents: 46625
diff changeset
   721
a13bd8c6b7a2 8186166: Generalize Atomic::cmpxchg with templates
eosterlund
parents: 46625
diff changeset
   722
// Handle cmpxchg for pointer types.
a13bd8c6b7a2 8186166: Generalize Atomic::cmpxchg with templates
eosterlund
parents: 46625
diff changeset
   723
//
a13bd8c6b7a2 8186166: Generalize Atomic::cmpxchg with templates
eosterlund
parents: 46625
diff changeset
   724
// The destination's type and the compare_value type must be the same,
a13bd8c6b7a2 8186166: Generalize Atomic::cmpxchg with templates
eosterlund
parents: 46625
diff changeset
   725
// ignoring cv-qualifiers; we don't care about the cv-qualifiers of
a13bd8c6b7a2 8186166: Generalize Atomic::cmpxchg with templates
eosterlund
parents: 46625
diff changeset
   726
// the compare_value.
a13bd8c6b7a2 8186166: Generalize Atomic::cmpxchg with templates
eosterlund
parents: 46625
diff changeset
   727
//
a13bd8c6b7a2 8186166: Generalize Atomic::cmpxchg with templates
eosterlund
parents: 46625
diff changeset
   728
// The exchange_value must be implicitly convertible to the
a13bd8c6b7a2 8186166: Generalize Atomic::cmpxchg with templates
eosterlund
parents: 46625
diff changeset
   729
// destination's type; it must be type-correct to store the
a13bd8c6b7a2 8186166: Generalize Atomic::cmpxchg with templates
eosterlund
parents: 46625
diff changeset
   730
// exchange_value in the destination.
a13bd8c6b7a2 8186166: Generalize Atomic::cmpxchg with templates
eosterlund
parents: 46625
diff changeset
   731
template<typename T, typename D, typename U>
a13bd8c6b7a2 8186166: Generalize Atomic::cmpxchg with templates
eosterlund
parents: 46625
diff changeset
   732
struct Atomic::CmpxchgImpl<
a13bd8c6b7a2 8186166: Generalize Atomic::cmpxchg with templates
eosterlund
parents: 46625
diff changeset
   733
  T*, D*, U*,
a13bd8c6b7a2 8186166: Generalize Atomic::cmpxchg with templates
eosterlund
parents: 46625
diff changeset
   734
  typename EnableIf<Atomic::IsPointerConvertible<T*, D*>::value &&
a13bd8c6b7a2 8186166: Generalize Atomic::cmpxchg with templates
eosterlund
parents: 46625
diff changeset
   735
                    IsSame<typename RemoveCV<D>::type,
a13bd8c6b7a2 8186166: Generalize Atomic::cmpxchg with templates
eosterlund
parents: 46625
diff changeset
   736
                           typename RemoveCV<U>::type>::value>::type>
a13bd8c6b7a2 8186166: Generalize Atomic::cmpxchg with templates
eosterlund
parents: 46625
diff changeset
   737
  VALUE_OBJ_CLASS_SPEC
a13bd8c6b7a2 8186166: Generalize Atomic::cmpxchg with templates
eosterlund
parents: 46625
diff changeset
   738
{
a13bd8c6b7a2 8186166: Generalize Atomic::cmpxchg with templates
eosterlund
parents: 46625
diff changeset
   739
  D* operator()(T* exchange_value, D* volatile* dest, U* compare_value,
a13bd8c6b7a2 8186166: Generalize Atomic::cmpxchg with templates
eosterlund
parents: 46625
diff changeset
   740
               cmpxchg_memory_order order) const {
a13bd8c6b7a2 8186166: Generalize Atomic::cmpxchg with templates
eosterlund
parents: 46625
diff changeset
   741
    // Allow derived to base conversion, and adding cv-qualifiers.
a13bd8c6b7a2 8186166: Generalize Atomic::cmpxchg with templates
eosterlund
parents: 46625
diff changeset
   742
    D* new_value = exchange_value;
a13bd8c6b7a2 8186166: Generalize Atomic::cmpxchg with templates
eosterlund
parents: 46625
diff changeset
   743
    // Don't care what the CV qualifiers for compare_value are,
a13bd8c6b7a2 8186166: Generalize Atomic::cmpxchg with templates
eosterlund
parents: 46625
diff changeset
   744
    // but we need to match D* when calling platform support.
a13bd8c6b7a2 8186166: Generalize Atomic::cmpxchg with templates
eosterlund
parents: 46625
diff changeset
   745
    D* old_value = const_cast<D*>(compare_value);
a13bd8c6b7a2 8186166: Generalize Atomic::cmpxchg with templates
eosterlund
parents: 46625
diff changeset
   746
    return PlatformCmpxchg<sizeof(D*)>()(new_value, dest, old_value, order);
a13bd8c6b7a2 8186166: Generalize Atomic::cmpxchg with templates
eosterlund
parents: 46625
diff changeset
   747
  }
a13bd8c6b7a2 8186166: Generalize Atomic::cmpxchg with templates
eosterlund
parents: 46625
diff changeset
   748
};
a13bd8c6b7a2 8186166: Generalize Atomic::cmpxchg with templates
eosterlund
parents: 46625
diff changeset
   749
a13bd8c6b7a2 8186166: Generalize Atomic::cmpxchg with templates
eosterlund
parents: 46625
diff changeset
   750
// Handle cmpxchg for types that have a translator.
a13bd8c6b7a2 8186166: Generalize Atomic::cmpxchg with templates
eosterlund
parents: 46625
diff changeset
   751
//
a13bd8c6b7a2 8186166: Generalize Atomic::cmpxchg with templates
eosterlund
parents: 46625
diff changeset
   752
// All the involved types must be identical.
a13bd8c6b7a2 8186166: Generalize Atomic::cmpxchg with templates
eosterlund
parents: 46625
diff changeset
   753
//
a13bd8c6b7a2 8186166: Generalize Atomic::cmpxchg with templates
eosterlund
parents: 46625
diff changeset
   754
// This translates the original call into a call on the decayed
a13bd8c6b7a2 8186166: Generalize Atomic::cmpxchg with templates
eosterlund
parents: 46625
diff changeset
   755
// arguments, and returns the recovered result of that translated
a13bd8c6b7a2 8186166: Generalize Atomic::cmpxchg with templates
eosterlund
parents: 46625
diff changeset
   756
// call.
a13bd8c6b7a2 8186166: Generalize Atomic::cmpxchg with templates
eosterlund
parents: 46625
diff changeset
   757
template<typename T>
a13bd8c6b7a2 8186166: Generalize Atomic::cmpxchg with templates
eosterlund
parents: 46625
diff changeset
   758
struct Atomic::CmpxchgImpl<
a13bd8c6b7a2 8186166: Generalize Atomic::cmpxchg with templates
eosterlund
parents: 46625
diff changeset
   759
  T, T, T,
a13bd8c6b7a2 8186166: Generalize Atomic::cmpxchg with templates
eosterlund
parents: 46625
diff changeset
   760
  typename EnableIf<PrimitiveConversions::Translate<T>::value>::type>
a13bd8c6b7a2 8186166: Generalize Atomic::cmpxchg with templates
eosterlund
parents: 46625
diff changeset
   761
  VALUE_OBJ_CLASS_SPEC
a13bd8c6b7a2 8186166: Generalize Atomic::cmpxchg with templates
eosterlund
parents: 46625
diff changeset
   762
{
a13bd8c6b7a2 8186166: Generalize Atomic::cmpxchg with templates
eosterlund
parents: 46625
diff changeset
   763
  T operator()(T exchange_value, T volatile* dest, T compare_value,
a13bd8c6b7a2 8186166: Generalize Atomic::cmpxchg with templates
eosterlund
parents: 46625
diff changeset
   764
               cmpxchg_memory_order order) const {
a13bd8c6b7a2 8186166: Generalize Atomic::cmpxchg with templates
eosterlund
parents: 46625
diff changeset
   765
    typedef PrimitiveConversions::Translate<T> Translator;
a13bd8c6b7a2 8186166: Generalize Atomic::cmpxchg with templates
eosterlund
parents: 46625
diff changeset
   766
    typedef typename Translator::Decayed Decayed;
a13bd8c6b7a2 8186166: Generalize Atomic::cmpxchg with templates
eosterlund
parents: 46625
diff changeset
   767
    STATIC_ASSERT(sizeof(T) == sizeof(Decayed));
a13bd8c6b7a2 8186166: Generalize Atomic::cmpxchg with templates
eosterlund
parents: 46625
diff changeset
   768
    return Translator::recover(
a13bd8c6b7a2 8186166: Generalize Atomic::cmpxchg with templates
eosterlund
parents: 46625
diff changeset
   769
      cmpxchg(Translator::decay(exchange_value),
a13bd8c6b7a2 8186166: Generalize Atomic::cmpxchg with templates
eosterlund
parents: 46625
diff changeset
   770
              reinterpret_cast<Decayed volatile*>(dest),
a13bd8c6b7a2 8186166: Generalize Atomic::cmpxchg with templates
eosterlund
parents: 46625
diff changeset
   771
              Translator::decay(compare_value),
a13bd8c6b7a2 8186166: Generalize Atomic::cmpxchg with templates
eosterlund
parents: 46625
diff changeset
   772
              order));
a13bd8c6b7a2 8186166: Generalize Atomic::cmpxchg with templates
eosterlund
parents: 46625
diff changeset
   773
  }
a13bd8c6b7a2 8186166: Generalize Atomic::cmpxchg with templates
eosterlund
parents: 46625
diff changeset
   774
};
a13bd8c6b7a2 8186166: Generalize Atomic::cmpxchg with templates
eosterlund
parents: 46625
diff changeset
   775
a13bd8c6b7a2 8186166: Generalize Atomic::cmpxchg with templates
eosterlund
parents: 46625
diff changeset
   776
template<typename Type, typename Fn, typename T>
a13bd8c6b7a2 8186166: Generalize Atomic::cmpxchg with templates
eosterlund
parents: 46625
diff changeset
   777
inline T Atomic::cmpxchg_using_helper(Fn fn,
a13bd8c6b7a2 8186166: Generalize Atomic::cmpxchg with templates
eosterlund
parents: 46625
diff changeset
   778
                                      T exchange_value,
a13bd8c6b7a2 8186166: Generalize Atomic::cmpxchg with templates
eosterlund
parents: 46625
diff changeset
   779
                                      T volatile* dest,
a13bd8c6b7a2 8186166: Generalize Atomic::cmpxchg with templates
eosterlund
parents: 46625
diff changeset
   780
                                      T compare_value) {
a13bd8c6b7a2 8186166: Generalize Atomic::cmpxchg with templates
eosterlund
parents: 46625
diff changeset
   781
  STATIC_ASSERT(sizeof(Type) == sizeof(T));
a13bd8c6b7a2 8186166: Generalize Atomic::cmpxchg with templates
eosterlund
parents: 46625
diff changeset
   782
  return PrimitiveConversions::cast<T>(
a13bd8c6b7a2 8186166: Generalize Atomic::cmpxchg with templates
eosterlund
parents: 46625
diff changeset
   783
    fn(PrimitiveConversions::cast<Type>(exchange_value),
a13bd8c6b7a2 8186166: Generalize Atomic::cmpxchg with templates
eosterlund
parents: 46625
diff changeset
   784
       reinterpret_cast<Type volatile*>(dest),
a13bd8c6b7a2 8186166: Generalize Atomic::cmpxchg with templates
eosterlund
parents: 46625
diff changeset
   785
       PrimitiveConversions::cast<Type>(compare_value)));
a13bd8c6b7a2 8186166: Generalize Atomic::cmpxchg with templates
eosterlund
parents: 46625
diff changeset
   786
}
a13bd8c6b7a2 8186166: Generalize Atomic::cmpxchg with templates
eosterlund
parents: 46625
diff changeset
   787
a13bd8c6b7a2 8186166: Generalize Atomic::cmpxchg with templates
eosterlund
parents: 46625
diff changeset
   788
template<typename T>
a13bd8c6b7a2 8186166: Generalize Atomic::cmpxchg with templates
eosterlund
parents: 46625
diff changeset
   789
inline T Atomic::CmpxchgByteUsingInt::operator()(T exchange_value,
a13bd8c6b7a2 8186166: Generalize Atomic::cmpxchg with templates
eosterlund
parents: 46625
diff changeset
   790
                                                 T volatile* dest,
a13bd8c6b7a2 8186166: Generalize Atomic::cmpxchg with templates
eosterlund
parents: 46625
diff changeset
   791
                                                 T compare_value,
a13bd8c6b7a2 8186166: Generalize Atomic::cmpxchg with templates
eosterlund
parents: 46625
diff changeset
   792
                                                 cmpxchg_memory_order order) const {
a13bd8c6b7a2 8186166: Generalize Atomic::cmpxchg with templates
eosterlund
parents: 46625
diff changeset
   793
  STATIC_ASSERT(sizeof(T) == sizeof(uint8_t));
a13bd8c6b7a2 8186166: Generalize Atomic::cmpxchg with templates
eosterlund
parents: 46625
diff changeset
   794
  uint8_t canon_exchange_value = exchange_value;
a13bd8c6b7a2 8186166: Generalize Atomic::cmpxchg with templates
eosterlund
parents: 46625
diff changeset
   795
  uint8_t canon_compare_value = compare_value;
a13bd8c6b7a2 8186166: Generalize Atomic::cmpxchg with templates
eosterlund
parents: 46625
diff changeset
   796
  volatile uint32_t* aligned_dest
a13bd8c6b7a2 8186166: Generalize Atomic::cmpxchg with templates
eosterlund
parents: 46625
diff changeset
   797
    = reinterpret_cast<volatile uint32_t*>(align_down(dest, sizeof(uint32_t)));
a13bd8c6b7a2 8186166: Generalize Atomic::cmpxchg with templates
eosterlund
parents: 46625
diff changeset
   798
  size_t offset = pointer_delta(dest, aligned_dest, 1);
a13bd8c6b7a2 8186166: Generalize Atomic::cmpxchg with templates
eosterlund
parents: 46625
diff changeset
   799
  uint32_t cur = *aligned_dest;
a13bd8c6b7a2 8186166: Generalize Atomic::cmpxchg with templates
eosterlund
parents: 46625
diff changeset
   800
  uint8_t* cur_as_bytes = reinterpret_cast<uint8_t*>(&cur);
40669
252f9d8272af 8157904: Atomic::cmpxchg for jbyte is missing a fence on initial failure
dholmes
parents: 40655
diff changeset
   801
252f9d8272af 8157904: Atomic::cmpxchg for jbyte is missing a fence on initial failure
dholmes
parents: 40655
diff changeset
   802
  // current value may not be what we are looking for, so force it
252f9d8272af 8157904: Atomic::cmpxchg for jbyte is missing a fence on initial failure
dholmes
parents: 40655
diff changeset
   803
  // to that value so the initial cmpxchg will fail if it is different
46958
a13bd8c6b7a2 8186166: Generalize Atomic::cmpxchg with templates
eosterlund
parents: 46625
diff changeset
   804
  cur_as_bytes[offset] = canon_compare_value;
40669
252f9d8272af 8157904: Atomic::cmpxchg for jbyte is missing a fence on initial failure
dholmes
parents: 40655
diff changeset
   805
252f9d8272af 8157904: Atomic::cmpxchg for jbyte is missing a fence on initial failure
dholmes
parents: 40655
diff changeset
   806
  // always execute a real cmpxchg so that we get the required memory
252f9d8272af 8157904: Atomic::cmpxchg for jbyte is missing a fence on initial failure
dholmes
parents: 40655
diff changeset
   807
  // barriers even on initial failure
252f9d8272af 8157904: Atomic::cmpxchg for jbyte is missing a fence on initial failure
dholmes
parents: 40655
diff changeset
   808
  do {
252f9d8272af 8157904: Atomic::cmpxchg for jbyte is missing a fence on initial failure
dholmes
parents: 40655
diff changeset
   809
    // value to swap in matches current value ...
46958
a13bd8c6b7a2 8186166: Generalize Atomic::cmpxchg with templates
eosterlund
parents: 46625
diff changeset
   810
    uint32_t new_value = cur;
48468
7cc7de9bf4a4 8186903: Remove j-types from Atomic
coleenp
parents: 47634
diff changeset
   811
    // ... except for the one byte we want to update
46958
a13bd8c6b7a2 8186166: Generalize Atomic::cmpxchg with templates
eosterlund
parents: 46625
diff changeset
   812
    reinterpret_cast<uint8_t*>(&new_value)[offset] = canon_exchange_value;
40669
252f9d8272af 8157904: Atomic::cmpxchg for jbyte is missing a fence on initial failure
dholmes
parents: 40655
diff changeset
   813
46958
a13bd8c6b7a2 8186166: Generalize Atomic::cmpxchg with templates
eosterlund
parents: 46625
diff changeset
   814
    uint32_t res = cmpxchg(new_value, aligned_dest, cur, order);
a13bd8c6b7a2 8186166: Generalize Atomic::cmpxchg with templates
eosterlund
parents: 46625
diff changeset
   815
    if (res == cur) break;      // success
40669
252f9d8272af 8157904: Atomic::cmpxchg for jbyte is missing a fence on initial failure
dholmes
parents: 40655
diff changeset
   816
46958
a13bd8c6b7a2 8186166: Generalize Atomic::cmpxchg with templates
eosterlund
parents: 46625
diff changeset
   817
    // at least one byte in the int changed value, so update
a13bd8c6b7a2 8186166: Generalize Atomic::cmpxchg with templates
eosterlund
parents: 46625
diff changeset
   818
    // our view of the current int
40655
9f644073d3a0 8157907: Incorrect inclusion of atomic.hpp instead of atomic.inline.hpp
dholmes
parents: 39404
diff changeset
   819
    cur = res;
46958
a13bd8c6b7a2 8186166: Generalize Atomic::cmpxchg with templates
eosterlund
parents: 46625
diff changeset
   820
    // if our byte is still as cur we loop and try again
a13bd8c6b7a2 8186166: Generalize Atomic::cmpxchg with templates
eosterlund
parents: 46625
diff changeset
   821
  } while (cur_as_bytes[offset] == canon_compare_value);
40669
252f9d8272af 8157904: Atomic::cmpxchg for jbyte is missing a fence on initial failure
dholmes
parents: 40655
diff changeset
   822
46958
a13bd8c6b7a2 8186166: Generalize Atomic::cmpxchg with templates
eosterlund
parents: 46625
diff changeset
   823
  return PrimitiveConversions::cast<T>(cur_as_bytes[offset]);
40655
9f644073d3a0 8157907: Incorrect inclusion of atomic.hpp instead of atomic.inline.hpp
dholmes
parents: 39404
diff changeset
   824
}
40669
252f9d8272af 8157904: Atomic::cmpxchg for jbyte is missing a fence on initial failure
dholmes
parents: 40655
diff changeset
   825
47578
09c41c4913d9 8187977: Generalize Atomic::xchg to use templates
eosterlund
parents: 47552
diff changeset
   826
// Handle xchg for integral and enum types.
09c41c4913d9 8187977: Generalize Atomic::xchg to use templates
eosterlund
parents: 47552
diff changeset
   827
//
09c41c4913d9 8187977: Generalize Atomic::xchg to use templates
eosterlund
parents: 47552
diff changeset
   828
// All the involved types must be identical.
09c41c4913d9 8187977: Generalize Atomic::xchg to use templates
eosterlund
parents: 47552
diff changeset
   829
template<typename T>
09c41c4913d9 8187977: Generalize Atomic::xchg to use templates
eosterlund
parents: 47552
diff changeset
   830
struct Atomic::XchgImpl<
09c41c4913d9 8187977: Generalize Atomic::xchg to use templates
eosterlund
parents: 47552
diff changeset
   831
  T, T,
09c41c4913d9 8187977: Generalize Atomic::xchg to use templates
eosterlund
parents: 47552
diff changeset
   832
  typename EnableIf<IsIntegral<T>::value || IsRegisteredEnum<T>::value>::type>
09c41c4913d9 8187977: Generalize Atomic::xchg to use templates
eosterlund
parents: 47552
diff changeset
   833
  VALUE_OBJ_CLASS_SPEC
09c41c4913d9 8187977: Generalize Atomic::xchg to use templates
eosterlund
parents: 47552
diff changeset
   834
{
09c41c4913d9 8187977: Generalize Atomic::xchg to use templates
eosterlund
parents: 47552
diff changeset
   835
  T operator()(T exchange_value, T volatile* dest) const {
09c41c4913d9 8187977: Generalize Atomic::xchg to use templates
eosterlund
parents: 47552
diff changeset
   836
    // Forward to the platform handler for the size of T.
09c41c4913d9 8187977: Generalize Atomic::xchg to use templates
eosterlund
parents: 47552
diff changeset
   837
    return PlatformXchg<sizeof(T)>()(exchange_value, dest);
09c41c4913d9 8187977: Generalize Atomic::xchg to use templates
eosterlund
parents: 47552
diff changeset
   838
  }
09c41c4913d9 8187977: Generalize Atomic::xchg to use templates
eosterlund
parents: 47552
diff changeset
   839
};
09c41c4913d9 8187977: Generalize Atomic::xchg to use templates
eosterlund
parents: 47552
diff changeset
   840
09c41c4913d9 8187977: Generalize Atomic::xchg to use templates
eosterlund
parents: 47552
diff changeset
   841
// Handle xchg for pointer types.
09c41c4913d9 8187977: Generalize Atomic::xchg to use templates
eosterlund
parents: 47552
diff changeset
   842
//
09c41c4913d9 8187977: Generalize Atomic::xchg to use templates
eosterlund
parents: 47552
diff changeset
   843
// The exchange_value must be implicitly convertible to the
09c41c4913d9 8187977: Generalize Atomic::xchg to use templates
eosterlund
parents: 47552
diff changeset
   844
// destination's type; it must be type-correct to store the
09c41c4913d9 8187977: Generalize Atomic::xchg to use templates
eosterlund
parents: 47552
diff changeset
   845
// exchange_value in the destination.
09c41c4913d9 8187977: Generalize Atomic::xchg to use templates
eosterlund
parents: 47552
diff changeset
   846
template<typename T, typename D>
09c41c4913d9 8187977: Generalize Atomic::xchg to use templates
eosterlund
parents: 47552
diff changeset
   847
struct Atomic::XchgImpl<
09c41c4913d9 8187977: Generalize Atomic::xchg to use templates
eosterlund
parents: 47552
diff changeset
   848
  T*, D*,
09c41c4913d9 8187977: Generalize Atomic::xchg to use templates
eosterlund
parents: 47552
diff changeset
   849
  typename EnableIf<Atomic::IsPointerConvertible<T*, D*>::value>::type>
09c41c4913d9 8187977: Generalize Atomic::xchg to use templates
eosterlund
parents: 47552
diff changeset
   850
  VALUE_OBJ_CLASS_SPEC
09c41c4913d9 8187977: Generalize Atomic::xchg to use templates
eosterlund
parents: 47552
diff changeset
   851
{
09c41c4913d9 8187977: Generalize Atomic::xchg to use templates
eosterlund
parents: 47552
diff changeset
   852
  D* operator()(T* exchange_value, D* volatile* dest) const {
09c41c4913d9 8187977: Generalize Atomic::xchg to use templates
eosterlund
parents: 47552
diff changeset
   853
    // Allow derived to base conversion, and adding cv-qualifiers.
09c41c4913d9 8187977: Generalize Atomic::xchg to use templates
eosterlund
parents: 47552
diff changeset
   854
    D* new_value = exchange_value;
09c41c4913d9 8187977: Generalize Atomic::xchg to use templates
eosterlund
parents: 47552
diff changeset
   855
    return PlatformXchg<sizeof(D*)>()(new_value, dest);
09c41c4913d9 8187977: Generalize Atomic::xchg to use templates
eosterlund
parents: 47552
diff changeset
   856
  }
09c41c4913d9 8187977: Generalize Atomic::xchg to use templates
eosterlund
parents: 47552
diff changeset
   857
};
09c41c4913d9 8187977: Generalize Atomic::xchg to use templates
eosterlund
parents: 47552
diff changeset
   858
09c41c4913d9 8187977: Generalize Atomic::xchg to use templates
eosterlund
parents: 47552
diff changeset
   859
// Handle xchg for types that have a translator.
09c41c4913d9 8187977: Generalize Atomic::xchg to use templates
eosterlund
parents: 47552
diff changeset
   860
//
09c41c4913d9 8187977: Generalize Atomic::xchg to use templates
eosterlund
parents: 47552
diff changeset
   861
// All the involved types must be identical.
09c41c4913d9 8187977: Generalize Atomic::xchg to use templates
eosterlund
parents: 47552
diff changeset
   862
//
09c41c4913d9 8187977: Generalize Atomic::xchg to use templates
eosterlund
parents: 47552
diff changeset
   863
// This translates the original call into a call on the decayed
09c41c4913d9 8187977: Generalize Atomic::xchg to use templates
eosterlund
parents: 47552
diff changeset
   864
// arguments, and returns the recovered result of that translated
09c41c4913d9 8187977: Generalize Atomic::xchg to use templates
eosterlund
parents: 47552
diff changeset
   865
// call.
09c41c4913d9 8187977: Generalize Atomic::xchg to use templates
eosterlund
parents: 47552
diff changeset
   866
template<typename T>
09c41c4913d9 8187977: Generalize Atomic::xchg to use templates
eosterlund
parents: 47552
diff changeset
   867
struct Atomic::XchgImpl<
09c41c4913d9 8187977: Generalize Atomic::xchg to use templates
eosterlund
parents: 47552
diff changeset
   868
  T, T,
09c41c4913d9 8187977: Generalize Atomic::xchg to use templates
eosterlund
parents: 47552
diff changeset
   869
  typename EnableIf<PrimitiveConversions::Translate<T>::value>::type>
09c41c4913d9 8187977: Generalize Atomic::xchg to use templates
eosterlund
parents: 47552
diff changeset
   870
  VALUE_OBJ_CLASS_SPEC
09c41c4913d9 8187977: Generalize Atomic::xchg to use templates
eosterlund
parents: 47552
diff changeset
   871
{
09c41c4913d9 8187977: Generalize Atomic::xchg to use templates
eosterlund
parents: 47552
diff changeset
   872
  T operator()(T exchange_value, T volatile* dest) const {
09c41c4913d9 8187977: Generalize Atomic::xchg to use templates
eosterlund
parents: 47552
diff changeset
   873
    typedef PrimitiveConversions::Translate<T> Translator;
09c41c4913d9 8187977: Generalize Atomic::xchg to use templates
eosterlund
parents: 47552
diff changeset
   874
    typedef typename Translator::Decayed Decayed;
09c41c4913d9 8187977: Generalize Atomic::xchg to use templates
eosterlund
parents: 47552
diff changeset
   875
    STATIC_ASSERT(sizeof(T) == sizeof(Decayed));
09c41c4913d9 8187977: Generalize Atomic::xchg to use templates
eosterlund
parents: 47552
diff changeset
   876
    return Translator::recover(
09c41c4913d9 8187977: Generalize Atomic::xchg to use templates
eosterlund
parents: 47552
diff changeset
   877
      xchg(Translator::decay(exchange_value),
09c41c4913d9 8187977: Generalize Atomic::xchg to use templates
eosterlund
parents: 47552
diff changeset
   878
           reinterpret_cast<Decayed volatile*>(dest)));
09c41c4913d9 8187977: Generalize Atomic::xchg to use templates
eosterlund
parents: 47552
diff changeset
   879
  }
09c41c4913d9 8187977: Generalize Atomic::xchg to use templates
eosterlund
parents: 47552
diff changeset
   880
};
09c41c4913d9 8187977: Generalize Atomic::xchg to use templates
eosterlund
parents: 47552
diff changeset
   881
09c41c4913d9 8187977: Generalize Atomic::xchg to use templates
eosterlund
parents: 47552
diff changeset
   882
template<typename Type, typename Fn, typename T>
09c41c4913d9 8187977: Generalize Atomic::xchg to use templates
eosterlund
parents: 47552
diff changeset
   883
inline T Atomic::xchg_using_helper(Fn fn,
09c41c4913d9 8187977: Generalize Atomic::xchg to use templates
eosterlund
parents: 47552
diff changeset
   884
                                   T exchange_value,
09c41c4913d9 8187977: Generalize Atomic::xchg to use templates
eosterlund
parents: 47552
diff changeset
   885
                                   T volatile* dest) {
09c41c4913d9 8187977: Generalize Atomic::xchg to use templates
eosterlund
parents: 47552
diff changeset
   886
  STATIC_ASSERT(sizeof(Type) == sizeof(T));
09c41c4913d9 8187977: Generalize Atomic::xchg to use templates
eosterlund
parents: 47552
diff changeset
   887
  return PrimitiveConversions::cast<T>(
09c41c4913d9 8187977: Generalize Atomic::xchg to use templates
eosterlund
parents: 47552
diff changeset
   888
    fn(PrimitiveConversions::cast<Type>(exchange_value),
09c41c4913d9 8187977: Generalize Atomic::xchg to use templates
eosterlund
parents: 47552
diff changeset
   889
       reinterpret_cast<Type volatile*>(dest)));
09c41c4913d9 8187977: Generalize Atomic::xchg to use templates
eosterlund
parents: 47552
diff changeset
   890
}
09c41c4913d9 8187977: Generalize Atomic::xchg to use templates
eosterlund
parents: 47552
diff changeset
   891
09c41c4913d9 8187977: Generalize Atomic::xchg to use templates
eosterlund
parents: 47552
diff changeset
   892
template<typename T, typename D>
09c41c4913d9 8187977: Generalize Atomic::xchg to use templates
eosterlund
parents: 47552
diff changeset
   893
inline D Atomic::xchg(T exchange_value, volatile D* dest) {
09c41c4913d9 8187977: Generalize Atomic::xchg to use templates
eosterlund
parents: 47552
diff changeset
   894
  return XchgImpl<T, D>()(exchange_value, dest);
40655
9f644073d3a0 8157907: Incorrect inclusion of atomic.hpp instead of atomic.inline.hpp
dholmes
parents: 39404
diff changeset
   895
}
9f644073d3a0 8157907: Incorrect inclusion of atomic.hpp instead of atomic.inline.hpp
dholmes
parents: 39404
diff changeset
   896
7397
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 5547
diff changeset
   897
#endif // SHARE_VM_RUNTIME_ATOMIC_HPP