Skip to content
This repository has been archived by the owner on Jul 8, 2022. It is now read-only.

Commit

Permalink
Merge pull request #817 from t-b/fix-686-9.4-lts
Browse files Browse the repository at this point in the history
Fix API_EventTimeOut
  • Loading branch information
t-b authored Dec 1, 2020
2 parents 95f5086 + 596aa38 commit fe934f0
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 6 deletions.
6 changes: 4 additions & 2 deletions cppapi/client/eventconsumer.h
Original file line number Diff line number Diff line change
Expand Up @@ -628,9 +628,11 @@ private :
DevErrorList_var del;

int old_poll_nb;
TangoMonitor subscription_monitor;
TangoMonitor subscription_monitor;
omni_mutex sock_bound_mutex;
bool ctrl_socket_bound;
bool ctrl_socket_bound;
// variable to count the number of ZMQ_DELAY_EVENT requests currently in progress:
int nb_current_delay_event_requests;


void *run_undetached(void *arg) override;
Expand Down
26 changes: 22 additions & 4 deletions cppapi/client/zmqeventconsumer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ ZmqEventConsumer *ZmqEventConsumer::_instance = NULL;
/************************************************************************/

ZmqEventConsumer::ZmqEventConsumer(ApiUtil *ptr) : EventConsumer(ptr),
omni_thread((void *)ptr),zmq_context(1),ctrl_socket_bound(false)
omni_thread((void *)ptr),zmq_context(1),ctrl_socket_bound(false), nb_current_delay_event_requests(0)
{
cout3 << "calling Tango::ZmqEventConsumer::ZmqEventConsumer() \n";
_instance = this;
Expand Down Expand Up @@ -1075,14 +1075,32 @@ bool ZmqEventConsumer::process_ctrl(zmq::message_t &received_ctrl,zmq::pollitem_

case ZMQ_DELAY_EVENT:
{
old_poll_nb = poll_nb;
poll_nb = 1;
// If poll_nb == 1, then we are already in a situation where events are being delayed
// and we are currently only taking care of messages received on the control socket
// No need to update old_poll_nb in this case because it is already correct
// otherwise this would lead to issues like https://github.com/tango-controls/cppTango/issues/686
// where events would no longer be received if someone subscribes or unsubscribes to events in
// an event callback and when the callback is executed during a subscribe_event call
if (poll_nb != 1)
{
old_poll_nb = poll_nb;
poll_nb = 1;
}
nb_current_delay_event_requests++;
}
break;

case ZMQ_RELEASE_EVENT:
{
poll_nb = old_poll_nb;
if(nb_current_delay_event_requests >= 1)
{
nb_current_delay_event_requests--;
}
if(nb_current_delay_event_requests == 0)
{
// Stop delaying events only if there is no other ZMQ_DELAY_EVENT command requested
poll_nb = old_poll_nb;
}
}
break;

Expand Down

0 comments on commit fe934f0

Please sign in to comment.