WIP state for Hugo to potentially fix a segfault

This commit is contained in:
2026-04-20 14:24:50 +02:00
parent 28e5cd4ec4
commit df66d4341d
3 changed files with 14 additions and 17 deletions
+3 -17
View File
@@ -122,21 +122,6 @@ mEpicsCa<T>::mEpicsCa(const char *pChanName, bool subscribe,
dbfFromType<T>();
int status = CM_SUCCESS;
/*
ca_disable_preemptive_callback: No callback thread is created and CA context
has to be "polled" (e.g. via ca_pend_event or ca_pend_io). All callbacks
happen in the main thread.
ca_enable_preemptive_callback: EPICS creates a dedicated callback thread
where the callback is run.
Obviously, ca_enable_preemptive_callback is the variant we want for
subscription.
*/
auto choice = ca_preemptive_callback_select::ca_disable_preemptive_callback;
if (subscribe) {
choice = ca_preemptive_callback_select::ca_enable_preemptive_callback;
}
/*
Try to create the Channel access context explicitly:
https://docs.epics-controls.org/projects/base/en/latest/cadef_h.html#_CPPv417ca_context_create29ca_preemptive_callback_select
@@ -146,7 +131,8 @@ mEpicsCa<T>::mEpicsCa(const char *pChanName, bool subscribe,
convertAndHandleEcaCode. Preemptive callbacks are disabled by default for
this driver.
*/
status = ca_context_create(choice);
status = ca_context_create(
ca_preemptive_callback_select::ca_enable_preemptive_callback);
if (status != ECA_NOTTHREADED) {
status = convertAndHandleEcaCode(status, this->_chanName.c_str());
}
@@ -490,7 +476,7 @@ template <typename T> int mEpicsCa<T>::putRaw(int *value) {
template <typename T>
void mEpicsCa<T>::connStateCallback(struct connection_handler_args args) {
mEpicsCa *self = static_cast<mEpicsCa *>(ca_puser(args.chid));
mEpicsCa<T> *self = static_cast<mEpicsCa<T> *>(ca_puser(args.chid));
if (args.op == CA_OP_CONN_UP) {
struct ChInfo info;
+4
View File
@@ -5,6 +5,10 @@ record(longin, "MEPICSCA:TEST:LONGIN") {
field(PINI, "YES")
}
record(longout, "MEPICSCA:TEST:LONGOUT") {
field(VAL, 256)
}
record(ai, "MEPICSCA:TEST:AI") {
field(VAL, 84)
}
+7
View File
@@ -102,6 +102,7 @@ int main() {
// interact with the spawned IOC.
auto int_ca = mEpicsCa<int>("MEPICSCA:TEST:LONGIN", false);
auto int_hopr_ca = mEpicsCa<int>("MEPICSCA:TEST:LONGIN.HOPR", false);
auto int_longout_ca = mEpicsCa<int>("MEPICSCA:TEST:LONGOUT", false);
auto double_ca = mEpicsCa<double>("MEPICSCA:TEST:AI", false);
auto string_ca = mEpicsCa<std::string>("MEPICSCA:TEST:STRINGIN", false);
auto waveform_ca = mEpicsCa<std::string>("MEPICSCA:TEST:WAVEFORM", false);
@@ -198,6 +199,12 @@ int main() {
EQUAL(status, CM_SUCCESS);
EQUAL(int_val, 100);
// Read an integer from a longout
int_val = 0;
status = int_longout_ca.get(&int_val);
EQUAL(status, CM_SUCCESS);
EQUAL(int_val, 256);
// Read a double from a record
double double_val = 0.0;
status = double_ca.get(&double_val);