Skip to content
Snippets Groups Projects
Commit b092c4ad authored by Martin Christoph Hierholzer's avatar Martin Christoph Hierholzer
Browse files

fixed readAny no longer working due to a broken TestDecoratorTransferFuture

parent 8b5d6553
No related branches found
No related tags found
No related merge requests found
...@@ -24,21 +24,23 @@ namespace ChimeraTK { ...@@ -24,21 +24,23 @@ namespace ChimeraTK {
TestDecoratorTransferFuture() : _originalFuture{nullptr} {} TestDecoratorTransferFuture() : _originalFuture{nullptr} {}
TestDecoratorTransferFuture(TransferFuture &originalFuture, TestDecoratorTransferFuture(TransferFuture &originalFuture, TestDecoratorRegisterAccessor<UserType> *accessor)
boost::shared_ptr<TestDecoratorRegisterAccessor<UserType>> accessor)
: _originalFuture(&originalFuture), _accessor(accessor) : _originalFuture(&originalFuture), _accessor(accessor)
{ {
TransferFuture::_theFuture = _originalFuture->getBoostFuture(); TransferFuture::_theFuture = _originalFuture->getBoostFuture();
TransferFuture::_transferElement = &(_originalFuture->getTransferElement()); TransferFuture::_transferElement = &(_originalFuture->getTransferElement());
} }
virtual ~TestDecoratorTransferFuture() {}
void wait() override { void wait() override {
try { try {
Application::getTestableModeLockObject().unlock(); Application::getTestableModeLockObject().unlock();
} }
catch(std::system_error &e) { // ignore operation not permitted errors, since they happen the first time (lock not yet owned) catch(std::system_error &e) { // ignore operation not permitted errors, since they happen the first time (lock not yet owned)
if(e.code() != std::errc::operation_not_permitted) throw e; if(e.code() != std::errc::operation_not_permitted) throw;
} }
boost::this_thread::interruption_point();
_originalFuture->wait(); _originalFuture->wait();
_accessor->postRead(); _accessor->postRead();
_accessor->hasActiveFuture = false; _accessor->hasActiveFuture = false;
...@@ -46,11 +48,27 @@ namespace ChimeraTK { ...@@ -46,11 +48,27 @@ namespace ChimeraTK {
--Application::getInstance().testableMode_counter; --Application::getInstance().testableMode_counter;
} }
TestDecoratorTransferFuture& operator=(const TestDecoratorTransferFuture &&other) {
TransferFuture::_theFuture = other._theFuture;
TransferFuture::_transferElement = other._transferElement;
_originalFuture = other._originalFuture;
_accessor = other._accessor;
return *this;
}
TestDecoratorTransferFuture(TestDecoratorTransferFuture &&other)
: TransferFuture(other._theFuture, other._transferElement),
_originalFuture(other._originalFuture),
_accessor(other._accessor)
{}
TestDecoratorTransferFuture(const TestDecoratorTransferFuture &other) = delete;
protected: protected:
TransferFuture *_originalFuture; TransferFuture *_originalFuture;
boost::shared_ptr<TestDecoratorRegisterAccessor<UserType>> _accessor; TestDecoratorRegisterAccessor<UserType> *_accessor;
}; };
/*******************************************************************************************************************/ /*******************************************************************************************************************/
...@@ -66,6 +84,9 @@ namespace ChimeraTK { ...@@ -66,6 +84,9 @@ namespace ChimeraTK {
for(size_t i=0; i<_accessor->getNumberOfChannels(); ++i) buffer_2D[i] = _accessor->accessChannel(i); for(size_t i=0; i<_accessor->getNumberOfChannels(); ++i) buffer_2D[i] = _accessor->accessChannel(i);
} }
virtual ~TestDecoratorRegisterAccessor() {}
void write() override { void write() override {
preWrite(); preWrite();
auto &myLock = Application::getTestableModeLockObject(); auto &myLock = Application::getTestableModeLockObject();
...@@ -92,10 +113,12 @@ namespace ChimeraTK { ...@@ -92,10 +113,12 @@ namespace ChimeraTK {
} }
TransferFuture& readAsync() override { TransferFuture& readAsync() override {
if(TransferElement::hasActiveFuture) {
return activeTestDecoratorFuture;
}
auto &future = _accessor->readAsync(); auto &future = _accessor->readAsync();
auto sharedThis = boost::static_pointer_cast<TestDecoratorRegisterAccessor<UserType>>(this->shared_from_this());
TransferElement::hasActiveFuture = true; TransferElement::hasActiveFuture = true;
activeTestDecoratorFuture = TestDecoratorTransferFuture<UserType>(future, sharedThis); activeTestDecoratorFuture = TestDecoratorTransferFuture<UserType>(future, this);
return activeTestDecoratorFuture; return activeTestDecoratorFuture;
} }
......
...@@ -279,7 +279,6 @@ BOOST_AUTO_TEST_CASE_TEMPLATE( testReadAny, T, test_types ) { ...@@ -279,7 +279,6 @@ BOOST_AUTO_TEST_CASE_TEMPLATE( testReadAny, T, test_types ) {
auto v3 = test.getScalar<T>("input/v3"); auto v3 = test.getScalar<T>("input/v3");
auto v4 = test.getScalar<T>("input/v4"); auto v4 = test.getScalar<T>("input/v4");
test.runApplication(); test.runApplication();
// check that we don't receive anything yet // check that we don't receive anything yet
usleep(10000); usleep(10000);
BOOST_CHECK(value.readNonBlocking() == false); BOOST_CHECK(value.readNonBlocking() == false);
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment