From 34384e6b95395083e52913c3d006ee277e1d2226 Mon Sep 17 00:00:00 2001
From: Martin Hierholzer <martin.hierholzer@desy.de>
Date: Fri, 23 Dec 2016 15:36:51 +0100
Subject: [PATCH] make use of the new blocking read() implementation of the
 ControlSystemAdapter

---
 include/ArrayAccessor.h         |  6 ++----
 include/FanOut.h                | 26 +++++++++++---------------
 include/ImplementationAdapter.h |  5 +----
 include/ScalarAccessor.h        |  6 ++----
 4 files changed, 16 insertions(+), 27 deletions(-)

diff --git a/include/ArrayAccessor.h b/include/ArrayAccessor.h
index fb943c31..c82e8263 100644
--- a/include/ArrayAccessor.h
+++ b/include/ArrayAccessor.h
@@ -32,10 +32,8 @@ namespace ChimeraTK {
 
       void read() {
         if(Accessor<UserType>::_mode == UpdateMode::push) {
-          while(impl->readNonBlocking() == false) { /// @todo TODO proper blocking implementation
-            boost::this_thread::yield();
-            boost::this_thread::interruption_point();
-          }
+          impl->read();
+          boost::this_thread::interruption_point();
         }
         else {
           /// @todo TODO empty the queue to always receive the latest value
diff --git a/include/FanOut.h b/include/FanOut.h
index 75df2b9b..e17f9e11 100644
--- a/include/FanOut.h
+++ b/include/FanOut.h
@@ -110,34 +110,22 @@ namespace ChimeraTK {
       void run() {
         assert(_direction == VariableDirection::consuming);
         while(true) {
-          boost::this_thread::yield();
           boost::this_thread::interruption_point();
           if(hasExternalTrigger) {
             // wait for external trigger (if present)
-            /// @todo TODO replace with proper blocking implementation when supported by the CSA
-            while(externalTrigger->readNonBlocking() == false) {
-              boost::this_thread::yield();
-              boost::this_thread::interruption_point();
-            }
+            externalTrigger->read();
             // receive data
             impl->readNonBlocking();
           }
           else {
             // receive data
-            while(impl->readNonBlocking() == false) {
-              boost::this_thread::yield();
-              boost::this_thread::interruption_point();
-            }
+            impl->read();
           }
-          boost::this_thread::yield();
-          boost::this_thread::interruption_point();
           for(auto &slave : slaves) {     // send out copies to slaves
             // do not send copy if no data is expected (e.g. trigger)
             if(slave->getNumberOfSamples() != 0) {
               slave->accessChannel(0) = impl->accessChannel(0);
             }
-            boost::this_thread::yield();
-            boost::this_thread::interruption_point();
             slave->write();
           }
         }
@@ -180,7 +168,15 @@ namespace ChimeraTK {
       }
       
       void read() {
-        throw std::logic_error("Blocking read is not supported by process array.");
+        impl->read();
+        mtca4u::NDRegisterAccessor<UserType>::buffer_2D[0].swap(impl->accessChannel(0));
+        for(auto &slave : slaves) {     // send out copies to slaves
+          // do not send copy if no data is expected (e.g. trigger)
+          if(slave->getNumberOfSamples() != 0) {
+            slave->accessChannel(0) = mtca4u::NDRegisterAccessor<UserType>::buffer_2D[0];
+          }
+          slave->write();
+        }
       }
       
       bool readNonBlocking() {
diff --git a/include/ImplementationAdapter.h b/include/ImplementationAdapter.h
index be78ad86..71969af5 100644
--- a/include/ImplementationAdapter.h
+++ b/include/ImplementationAdapter.h
@@ -51,10 +51,7 @@ namespace ChimeraTK {
       /** Synchronise sender and receiver. This function is executed in the separate thread. */
       void run() {
         while(true) {
-          while(!_receiver->readNonBlocking()) {
-            boost::this_thread::yield();
-            boost::this_thread::interruption_point();
-          }
+          _receiver->read();
           _sender->accessChannel(0) = _receiver->accessChannel(0);
           _sender->write();
         }
diff --git a/include/ScalarAccessor.h b/include/ScalarAccessor.h
index 08e45809..84cdbd2e 100644
--- a/include/ScalarAccessor.h
+++ b/include/ScalarAccessor.h
@@ -32,10 +32,8 @@ namespace ChimeraTK {
 
       void read() {
         if(Accessor<UserType>::_mode == UpdateMode::push) {
-          while(impl->readNonBlocking() == false) { /// @todo TODO proper blocking implementation
-            boost::this_thread::yield();
-            boost::this_thread::interruption_point();
-          }
+          impl->read();
+          boost::this_thread::interruption_point();
         }
         else {
           /// @todo TODO empty the queue to always receive the latest value
-- 
GitLab