From b092c4ad2dc7267ca88cbfa1fbb6e54aded8d155 Mon Sep 17 00:00:00 2001 From: Martin Hierholzer <martin.hierholzer@desy.de> Date: Thu, 23 Feb 2017 09:22:58 +0100 Subject: [PATCH] fixed readAny no longer working due to a broken TestDecoratorTransferFuture --- include/TestDecoratorRegisterAccessor.h | 35 +++++++++++++++++---- tests/executables_src/testTestFacilities.cc | 1 - 2 files changed, 29 insertions(+), 7 deletions(-) diff --git a/include/TestDecoratorRegisterAccessor.h b/include/TestDecoratorRegisterAccessor.h index 70823acd..ed6ead50 100644 --- a/include/TestDecoratorRegisterAccessor.h +++ b/include/TestDecoratorRegisterAccessor.h @@ -24,21 +24,23 @@ namespace ChimeraTK { TestDecoratorTransferFuture() : _originalFuture{nullptr} {} - TestDecoratorTransferFuture(TransferFuture &originalFuture, - boost::shared_ptr<TestDecoratorRegisterAccessor<UserType>> accessor) + TestDecoratorTransferFuture(TransferFuture &originalFuture, TestDecoratorRegisterAccessor<UserType> *accessor) : _originalFuture(&originalFuture), _accessor(accessor) { TransferFuture::_theFuture = _originalFuture->getBoostFuture(); TransferFuture::_transferElement = &(_originalFuture->getTransferElement()); } + virtual ~TestDecoratorTransferFuture() {} + void wait() override { try { Application::getTestableModeLockObject().unlock(); } 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(); _accessor->postRead(); _accessor->hasActiveFuture = false; @@ -46,11 +48,27 @@ namespace ChimeraTK { --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: TransferFuture *_originalFuture; - boost::shared_ptr<TestDecoratorRegisterAccessor<UserType>> _accessor; + TestDecoratorRegisterAccessor<UserType> *_accessor; }; /*******************************************************************************************************************/ @@ -66,6 +84,9 @@ namespace ChimeraTK { for(size_t i=0; i<_accessor->getNumberOfChannels(); ++i) buffer_2D[i] = _accessor->accessChannel(i); } + virtual ~TestDecoratorRegisterAccessor() {} + + void write() override { preWrite(); auto &myLock = Application::getTestableModeLockObject(); @@ -92,10 +113,12 @@ namespace ChimeraTK { } TransferFuture& readAsync() override { + if(TransferElement::hasActiveFuture) { + return activeTestDecoratorFuture; + } auto &future = _accessor->readAsync(); - auto sharedThis = boost::static_pointer_cast<TestDecoratorRegisterAccessor<UserType>>(this->shared_from_this()); TransferElement::hasActiveFuture = true; - activeTestDecoratorFuture = TestDecoratorTransferFuture<UserType>(future, sharedThis); + activeTestDecoratorFuture = TestDecoratorTransferFuture<UserType>(future, this); return activeTestDecoratorFuture; } diff --git a/tests/executables_src/testTestFacilities.cc b/tests/executables_src/testTestFacilities.cc index 82a5faf0..99552d0f 100644 --- a/tests/executables_src/testTestFacilities.cc +++ b/tests/executables_src/testTestFacilities.cc @@ -279,7 +279,6 @@ BOOST_AUTO_TEST_CASE_TEMPLATE( testReadAny, T, test_types ) { auto v3 = test.getScalar<T>("input/v3"); auto v4 = test.getScalar<T>("input/v4"); test.runApplication(); - // check that we don't receive anything yet usleep(10000); BOOST_CHECK(value.readNonBlocking() == false); -- GitLab