1 /* $NetBSD: cpp_atomic_ops_linkable.cc,v 1.3 2014/10/12 12:26:41 martin Exp $ */
4 * Copyright (c) 2014 The NetBSD Foundation, Inc.
7 * This code is derived from software contributed to The NetBSD Foundation
8 * by Martin Husemann <martin@NetBSD.org>.
10 * Redistribution and use in source and binary forms, with or without
11 * modification, are permitted provided that the following conditions
13 * 1. Redistributions of source code must retain the above copyright
14 * notice, this list of conditions and the following disclaimer.
15 * 2. Redistributions in binary form must reproduce the above copyright
16 * notice, this list of conditions and the following disclaimer in the
17 * documentation and/or other materials provided with the distribution.
19 * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
20 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
21 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
22 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
23 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
24 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
25 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
26 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
27 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
28 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
29 * POSSIBILITY OF SUCH DAMAGE.
33 * This is a simple link-time test to verify all builtin atomic sync
34 * operations for C++ <atomic> are available.
38 #include <machine/types.h> // for __HAVE_ATOMIC64_OPS
45 m_val
.exchange(std::atomic
<T
>(8));
53 m_val
.compare_exchange_weak(tval
, other
,
54 std::memory_order_release
, std::memory_order_relaxed
);
58 volatile std::atomic
<T
> m_val
;
61 int main(int argc
, char **argv
)
65 ATest
<unsigned char>();
67 ATest
<unsigned short>();
69 ATest
<unsigned int>();
71 ATest
<unsigned long>();
72 #ifdef __HAVE_ATOMIC64_OPS
74 ATest
<unsigned long long>();
79 ATest
<int_least8_t>();
80 ATest
<uint_least8_t>();
81 ATest
<int_least16_t>();
82 ATest
<uint_least16_t>();
83 ATest
<int_least32_t>();
84 ATest
<uint_least32_t>();
85 #ifdef __HAVE_ATOMIC64_OPS
86 ATest
<int_least64_t>();
87 ATest
<uint_least64_t>();
90 ATest
<uint_fast8_t>();
91 ATest
<int_fast16_t>();
92 ATest
<uint_fast16_t>();
93 ATest
<int_fast32_t>();
94 ATest
<uint_fast32_t>();
95 #ifdef __HAVE_ATOMIC64_OPS
96 ATest
<int_fast64_t>();
97 ATest
<uint_fast64_t>();
101 ATest
<std::size_t>();
102 ATest
<std::ptrdiff_t>();
103 #ifdef __HAVE_ATOMIC64_OPS