1 //
2 //  sp_interlocked_test.cpp
3 //
4 //  Copyright 2014 Peter Dimov
5 //
6 //  Distributed under the Boost Software License, Version 1.0.
7 //  See accompanying file LICENSE_1_0.txt or copy at
8 //  http://www.boost.org/LICENSE_1_0.txt
9 //
10 
11 #if defined( WIN32 ) || defined( _WIN32 ) || defined( __WIN32__ ) || defined( __CYGWIN__ )
12 
13 #include <boost/smart_ptr/detail/sp_interlocked.hpp>
14 #include <boost/detail/lightweight_test.hpp>
15 
16 #ifndef __LP64__
17 
18 typedef long long_type;
19 
20 #else
21 
22 // On Cygwin 64, long is 64 bit
23 typedef int long_type;
24 
25 #endif
26 
main()27 int main()
28 {
29     long_type x = 0, r;
30 
31     r = BOOST_SP_INTERLOCKED_INCREMENT( &x );
32 
33     BOOST_TEST( x == 1 );
34     BOOST_TEST( r == 1 );
35 
36     r = BOOST_SP_INTERLOCKED_DECREMENT( &x );
37 
38     BOOST_TEST( x == 0 );
39     BOOST_TEST( r == 0 );
40 
41     r = BOOST_SP_INTERLOCKED_EXCHANGE( &x, 3 );
42 
43     BOOST_TEST( x == 3 );
44     BOOST_TEST( r == 0 );
45 
46     r = BOOST_SP_INTERLOCKED_EXCHANGE_ADD( &x, 2 );
47 
48     BOOST_TEST( x == 5 );
49     BOOST_TEST( r == 3 );
50 
51     r = BOOST_SP_INTERLOCKED_COMPARE_EXCHANGE( &x, 0, 3 );
52 
53     BOOST_TEST( x == 5 );
54     BOOST_TEST( r == 5 );
55 
56     r = BOOST_SP_INTERLOCKED_COMPARE_EXCHANGE( &x, 0, 5 );
57 
58     BOOST_TEST( x == 0 );
59     BOOST_TEST( r == 5 );
60 
61     return boost::report_errors();
62 }
63 
64 #else
65 
main()66 int main()
67 {
68     return 0;
69 }
70 
71 #endif
72