Return the new value from wxAtomicInc() too

This is easy to do and can be useful when using an atomic initialization
counter.

The only platform where not returning the new value might be more
efficient than returning it is Solaris which is not really relevant any
more and on all the other platforms the functions we were already using
provided this value already (or almost, in case of using gcc builtins,
when we just have to use a different one).
This commit is contained in:
Vadim Zeitlin
2022-05-11 00:12:43 +02:00
parent e82290f0da
commit cf66ce5f94
5 changed files with 29 additions and 36 deletions

View File

@@ -77,15 +77,14 @@ TEST_CASE("Atomic::NoThread", "[atomic]")
CHECK( int2 == -ITERATIONS_NUM );
}
TEST_CASE("Atomic::DecReturn", "[atomic]")
TEST_CASE("Atomic::ReturnValue", "[atomic]")
{
wxAtomicInt i(0);
wxAtomicInc(i);
wxAtomicInc(i);
CHECK( i == 2 );
REQUIRE( wxAtomicInc(i) == 1 );
REQUIRE( wxAtomicInc(i) == 2 );
CHECK( wxAtomicDec(i) > 0 );
CHECK( wxAtomicDec(i) == 0 );
REQUIRE( wxAtomicDec(i) == 1 );
REQUIRE( wxAtomicDec(i) == 0 );
}
TEST_CASE("Atomic::WithThreads", "[atomic]")