ChimeraTK-DeviceAccess  03.18.00
AsyncAccessorManager.cc
Go to the documentation of this file.
1 // SPDX-FileCopyrightText: Deutsches Elektronen-Synchrotron DESY, MSK, ChimeraTK Project <chimeratk-support@desy.de>
2 // SPDX-License-Identifier: LGPL-3.0-or-later
3 
5 
6 namespace ChimeraTK::async {
7 
8  thread_local AsyncAccessorManager* AsyncAccessorManager::_isHoldingDomainLock{nullptr};
9 
10  /********************************************************************************************************************/
13  // The destructor of the AsyncVariable implementation must do all necessary clean-up
14  _asyncVariables.erase(id);
15  }
16  /********************************************************************************************************************/
18  if(_isHoldingDomainLock == this) {
19  _delayedUnsubscriptions.push_back(id);
20  }
21  else {
22  auto domainLock = _asyncDomain->getDomainLock();
23  unsubscribeImpl(id);
24  }
25  }
26 
27  /********************************************************************************************************************/
28  void AsyncAccessorManager::sendException(const std::exception_ptr& e) {
29  _isHoldingDomainLock = this;
30  assert(_delayedUnsubscriptions.empty());
31 
32  for(auto& var : _asyncVariables) {
33  var.second->sendException(e);
34  }
35  _isHoldingDomainLock = nullptr;
36 
37  for(auto id : _delayedUnsubscriptions) {
38  unsubscribeImpl(id);
39  }
41  }
42 
43 } // namespace ChimeraTK::async
ChimeraTK::async::AsyncAccessorManager::unsubscribe
void unsubscribe(TransferElementID id)
This function must only be called from the destructor of the AsyncNDRegisterAccessor which is created...
Definition: AsyncAccessorManager.cc:17
ChimeraTK::async
Definition: design_AsyncNDRegisterAcessor_and_NumericAddressedBackend.dox:1
ChimeraTK::async::AsyncAccessorManager::_asyncVariables
std::map< TransferElementID, std::unique_ptr< AsyncVariable > > _asyncVariables
Definition: AsyncAccessorManager.h:103
ChimeraTK::async::AsyncAccessorManager::sendException
void sendException(const std::exception_ptr &e)
Send an exception to all accessors.
Definition: AsyncAccessorManager.cc:28
ChimeraTK::async::AsyncAccessorManager::_isHoldingDomainLock
static thread_local AsyncAccessorManager * _isHoldingDomainLock
We have to remember that we are holding the domain lock before we lock a weak pointer to an AsyncNDRe...
Definition: AsyncAccessorManager.h:123
ChimeraTK::async::AsyncAccessorManager::_asyncDomain
boost::shared_ptr< Domain > _asyncDomain
Definition: AsyncAccessorManager.h:106
AsyncAccessorManager.h
ChimeraTK::TransferElementID
Simple class holding a unique ID for a TransferElement.
Definition: TransferElementID.h:17
ChimeraTK::async::AsyncAccessorManager::unsubscribeImpl
void unsubscribeImpl(TransferElementID id)
Internal helper function to avoid code duplication.
Definition: AsyncAccessorManager.cc:11
ChimeraTK::async::AsyncAccessorManager::asyncVariableMapChanged
virtual void asyncVariableMapChanged(TransferElementID)
This virtual function lets derived classes react on subscribe / unsubscribe.
Definition: AsyncAccessorManager.h:109
ChimeraTK::async::AsyncAccessorManager::_delayedUnsubscriptions
std::list< TransferElementID > _delayedUnsubscriptions
If an unsubscription request is coming in while iterating the _asyncVariables container,...
Definition: AsyncAccessorManager.h:128