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 main()16int main() 17 { 18 long x = 0, r; 19 20 r = BOOST_SP_INTERLOCKED_INCREMENT( &x ); 21 22 BOOST_TEST( x == 1 ); 23 BOOST_TEST( r == 1 ); 24 25 r = BOOST_SP_INTERLOCKED_DECREMENT( &x ); 26 27 BOOST_TEST( x == 0 ); 28 BOOST_TEST( r == 0 ); 29 30 r = BOOST_SP_INTERLOCKED_EXCHANGE( &x, 3 ); 31 32 BOOST_TEST( x == 3 ); 33 BOOST_TEST( r == 0 ); 34 35 r = BOOST_SP_INTERLOCKED_EXCHANGE_ADD( &x, 2 ); 36 37 BOOST_TEST( x == 5 ); 38 BOOST_TEST( r == 3 ); 39 40 r = BOOST_SP_INTERLOCKED_COMPARE_EXCHANGE( &x, 0, 3 ); 41 42 BOOST_TEST( x == 5 ); 43 BOOST_TEST( r == 5 ); 44 45 r = BOOST_SP_INTERLOCKED_COMPARE_EXCHANGE( &x, 0, 5 ); 46 47 BOOST_TEST( x == 0 ); 48 BOOST_TEST( r == 5 ); 49 50 return boost::report_errors(); 51 } 52 53 #else 54 main()55int main() 56 { 57 return 0; 58 } 59 60 #endif 61