ChimeraTK-DeviceAccess
03.18.00
DeviceBackendImpl.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
4
#include "
DeviceBackendImpl.h
"
5
6
#include <unistd.h>
7
8
namespace
ChimeraTK
{
9
10
/********************************************************************************************************************/
11
12
void
DeviceBackendImpl::setOpenedAndClearException
() noexcept {
13
// busy-wait until all exceptions have been distributed to the AsyncAccessors
14
while
(
_asyncDomainsContainer
.
isSendingExceptions
()) {
15
usleep(10000);
16
}
17
18
_opened
=
true
;
19
_hasActiveException =
false
;
20
std::lock_guard<std::mutex> lk(_mx_activeExceptionMessage);
21
_activeExceptionMessage =
"(exception cleared)"
;
22
}
23
24
/********************************************************************************************************************/
25
26
void
DeviceBackendImpl::setException
(
const
std::string& message) noexcept {
27
// set exception flag and atomically get the previous state
28
bool
hadExceptionBefore = _hasActiveException.exchange(
true
);
29
30
// if previously backend was already in exception state, don't continue here
31
if
(hadExceptionBefore) {
32
return
;
33
}
34
35
// set exception message
36
{
37
std::lock_guard<std::mutex> lk(_mx_activeExceptionMessage);
38
_activeExceptionMessage = message;
39
}
40
41
// execute backend-specific code
42
setExceptionImpl();
43
44
// finally turn off all async accessors and distribute the exception to them
45
_asyncDomainsContainer.sendExceptions(message);
46
}
47
48
/********************************************************************************************************************/
49
50
std::string
DeviceBackendImpl::getActiveExceptionMessage
() noexcept {
51
std::lock_guard<std::mutex> lk(_mx_activeExceptionMessage);
52
return
_activeExceptionMessage;
53
}
54
55
/********************************************************************************************************************/
56
57
}
// namespace ChimeraTK
ChimeraTK::DeviceBackendImpl::setOpenedAndClearException
void setOpenedAndClearException() noexcept
Backends should call this function at the end of a (successful) open() call.
Definition:
DeviceBackendImpl.cc:12
ChimeraTK::async::DomainsContainer::isSendingExceptions
bool isSendingExceptions()
Check whether an exception distribution is started and not completed yet.
Definition:
DomainsContainer.h:45
DeviceBackendImpl.h
ChimeraTK::DeviceBackendImpl::_opened
std::atomic< bool > _opened
flag if backend is opened
Definition:
DeviceBackendImpl.h:60
ChimeraTK::DeviceBackendImpl::_asyncDomainsContainer
async::DomainsContainer _asyncDomainsContainer
Container for async::Domains to support wait_for_new_data.
Definition:
DeviceBackendImpl.h:66
ChimeraTK::DeviceBackendImpl::getActiveExceptionMessage
std::string getActiveExceptionMessage() noexcept
Definition:
DeviceBackendImpl.cc:50
ChimeraTK::DeviceBackendImpl::setException
void setException(const std::string &message) noexcept final
Set the backend into an exception state.
Definition:
DeviceBackendImpl.cc:26
ChimeraTK
Definition:
DummyBackend.h:16
sources
ChimeraTK-DeviceAccess
src
DeviceBackendImpl.cc
Generated by
1.8.17