sp_interlocked_test.cpp 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  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. #if defined( WIN32 ) || defined( _WIN32 ) || defined( __WIN32__ ) || defined( __CYGWIN__ )
  11. #include <boost/smart_ptr/detail/sp_interlocked.hpp>
  12. #include <boost/detail/lightweight_test.hpp>
  13. #ifndef __LP64__
  14. typedef long long_type;
  15. #else
  16. // On Cygwin 64, long is 64 bit
  17. typedef int long_type;
  18. #endif
  19. int main()
  20. {
  21. long_type x = 0, r;
  22. r = BOOST_SP_INTERLOCKED_INCREMENT( &x );
  23. BOOST_TEST( x == 1 );
  24. BOOST_TEST( r == 1 );
  25. r = BOOST_SP_INTERLOCKED_DECREMENT( &x );
  26. BOOST_TEST( x == 0 );
  27. BOOST_TEST( r == 0 );
  28. r = BOOST_SP_INTERLOCKED_EXCHANGE( &x, 3 );
  29. BOOST_TEST( x == 3 );
  30. BOOST_TEST( r == 0 );
  31. r = BOOST_SP_INTERLOCKED_EXCHANGE_ADD( &x, 2 );
  32. BOOST_TEST( x == 5 );
  33. BOOST_TEST( r == 3 );
  34. r = BOOST_SP_INTERLOCKED_COMPARE_EXCHANGE( &x, 0, 3 );
  35. BOOST_TEST( x == 5 );
  36. BOOST_TEST( r == 5 );
  37. r = BOOST_SP_INTERLOCKED_COMPARE_EXCHANGE( &x, 0, 5 );
  38. BOOST_TEST( x == 0 );
  39. BOOST_TEST( r == 5 );
  40. return boost::report_errors();
  41. }
  42. #else
  43. int main()
  44. {
  45. return 0;
  46. }
  47. #endif