Fix #8695: til::spsc assignment operators don't return anything (#8811)

The following code didn't previously work as the assignment operators
didn't return a self reference:

```cpp
auto channel = til::spsc::channel<QueueItem>(100);
auto producer = std::move(channel.first);
channel.first = std::move(producer);
```

## Validation Steps Performed

I've added a basic smoke test for `til::spsc`.

Closes #8695
This commit is contained in:
Leonard Hecker 2021-01-19 12:41:08 +01:00 committed by GitHub
parent 2b4b8dd1bd
commit de49cf1d0d
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 34 additions and 0 deletions

View file

@ -425,6 +425,7 @@ namespace til::spsc
{
drop();
_arc = std::exchange(other._arc, nullptr);
return *this;
}
~producer()
@ -543,6 +544,7 @@ namespace til::spsc
{
drop();
_arc = std::exchange(other._arc, nullptr);
return *this;
}
~consumer()

View file

@ -50,12 +50,44 @@ class SPSCTests
TEST_CLASS_PROPERTY(L"TestTimeout", L"0:0:10") // 10s timeout
END_TEST_CLASS()
TEST_METHOD(SmokeTest);
TEST_METHOD(DropEmptyTest);
TEST_METHOD(DropSameRevolutionTest);
TEST_METHOD(DropDifferentRevolutionTest);
TEST_METHOD(IntegrationTest);
};
void SPSCTests::SmokeTest()
{
// This test mostly ensures that the API wasn't broken.
// construction
auto [tx, rx] = til::spsc::channel<int>(32);
std::array<int, 3> data{};
// move constructor
til::spsc::producer tx2(std::move(tx));
til::spsc::consumer rx2(std::move(rx));
// move assignment operator
tx = std::move(tx2);
rx = std::move(rx2);
// push
tx.emplace(0);
tx.push(data.begin(), data.end());
tx.push(til::spsc::block_initially, data.begin(), data.end());
tx.push(til::spsc::block_forever, data.begin(), data.end());
tx.push_n(data.begin(), data.size());
tx.push_n(til::spsc::block_initially, data.begin(), data.size());
tx.push_n(til::spsc::block_forever, data.begin(), data.size());
// pop
std::optional<int> x = rx.pop();
rx.pop_n(til::spsc::block_initially, data.begin(), data.size());
rx.pop_n(til::spsc::block_forever, data.begin(), data.size());
}
void SPSCTests::DropEmptyTest()
{
auto [tx, rx] = til::spsc::channel<drop_indicator>(5);