diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-27 18:24:20 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-27 18:24:20 +0000 |
commit | 483eb2f56657e8e7f419ab1a4fab8dce9ade8609 (patch) | |
tree | e5d88d25d870d5dedacb6bbdbe2a966086a0a5cf /src/boost/libs/fiber/test/test_barrier_dispatch.cpp | |
parent | Initial commit. (diff) | |
download | ceph-upstream.tar.xz ceph-upstream.zip |
Adding upstream version 14.2.21.upstream/14.2.21upstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'src/boost/libs/fiber/test/test_barrier_dispatch.cpp')
-rw-r--r-- | src/boost/libs/fiber/test/test_barrier_dispatch.cpp | 71 |
1 files changed, 71 insertions, 0 deletions
diff --git a/src/boost/libs/fiber/test/test_barrier_dispatch.cpp b/src/boost/libs/fiber/test/test_barrier_dispatch.cpp new file mode 100644 index 00000000..8f1716d5 --- /dev/null +++ b/src/boost/libs/fiber/test/test_barrier_dispatch.cpp @@ -0,0 +1,71 @@ + +// Copyright Oliver Kowalke 2013. +// Distributed under the Boost Software License, Version 1.0. +// (See accompanying file LICENSE_1_0.txt or copy at +// http://www.boost.org/LICENSE_1_0.txt) +// +// This test is based on the tests of Boost.Thread + +#include <sstream> +#include <string> + +#include <boost/test/unit_test.hpp> + +#include <boost/fiber/all.hpp> + +int value1 = 0; +int value2 = 0; + +void fn1( boost::fibers::barrier & b) { + ++value1; + boost::this_fiber::yield(); + + b.wait(); + + ++value1; + boost::this_fiber::yield(); + ++value1; + boost::this_fiber::yield(); + ++value1; + boost::this_fiber::yield(); + ++value1; +} + +void fn2( boost::fibers::barrier & b) { + ++value2; + boost::this_fiber::yield(); + ++value2; + boost::this_fiber::yield(); + ++value2; + boost::this_fiber::yield(); + + b.wait(); + + ++value2; + boost::this_fiber::yield(); + ++value2; +} + +void test_barrier() { + value1 = 0; + value2 = 0; + + boost::fibers::barrier b( 2); + boost::fibers::fiber f1( boost::fibers::launch::dispatch, fn1, std::ref( b) ); + boost::fibers::fiber f2( boost::fibers::launch::dispatch, fn2, std::ref( b) ); + + f1.join(); + f2.join(); + + BOOST_CHECK_EQUAL( 5, value1); + BOOST_CHECK_EQUAL( 5, value2); +} + +boost::unit_test::test_suite * init_unit_test_suite( int, char* []) { + boost::unit_test::test_suite * test = + BOOST_TEST_SUITE("Boost.Fiber: barrier test suite"); + + test->add( BOOST_TEST_CASE( & test_barrier) ); + + return test; +} |