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

Commit 82f1b89

Browse files
committed
Change mutex used for EventSupplier::detect_change
Remove detect_mutex and protect detect_change method with event_mutex to synchronize access to the old attribute value. Fixes data race between: * polling thread (EventSupplier::detect_and_push_xxx_event) * and user thread pushing events (EventSupplier::detect_change) This is a backport of 8d4a1bb from tango-9-lts.
1 parent 0af852d commit 82f1b89

File tree

3 files changed

+23
-22
lines changed

3 files changed

+23
-22
lines changed

cppapi/server/attribute.cpp

Lines changed: 22 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -4462,29 +4462,33 @@ void Attribute::fire_archive_event(DevFailed *except)
44624462
{
44634463

44644464
//
4465-
// Execute detect_change only to calculate the delta_change_rel and
4466-
// delta_change_abs and force_change !
44674465
//
44684466

44694467
bool force_change = false;
44704468
bool quality_change = false;
44714469
double delta_change_rel = 0.0;
44724470
double delta_change_abs = 0.0;
44734471

4474-
if (event_supplier_nd != NULL)
4475-
event_supplier_nd->detect_change(*this, ad,true,delta_change_rel,delta_change_abs,except,force_change,dev);
4476-
else if (event_supplier_zmq != NULL)
4477-
event_supplier_zmq->detect_change(*this, ad,true,delta_change_rel,delta_change_abs,except,force_change,dev);
4478-
4479-
4480-
vector<string> filterable_names;
4481-
vector<double> filterable_data;
4482-
vector<string> filterable_names_lg;
4483-
vector<long> filterable_data_lg;
4484-
44854472
{
44864473
omni_mutex_lock oml(EventSupplier::get_event_mutex());
44874474

4475+
// Execute detect_change only to calculate the delta_change_rel and
4476+
// delta_change_abs and force_change !
4477+
4478+
if (event_supplier_nd || event_supplier_zmq)
4479+
{
4480+
EventSupplier* event_supplier = event_supplier_nd ? event_supplier_nd : event_supplier_zmq;
4481+
event_supplier->detect_change(
4482+
*this,
4483+
ad,
4484+
true,
4485+
delta_change_rel,
4486+
delta_change_abs,
4487+
except,
4488+
force_change,
4489+
dev);
4490+
}
4491+
44884492
if (except != NULL)
44894493
{
44904494
prev_archive_event.err = true;
@@ -4521,6 +4525,11 @@ void Attribute::fire_archive_event(DevFailed *except)
45214525
prev_archive_event.inited = true;
45224526
}
45234527

4528+
vector<string> filterable_names;
4529+
vector<double> filterable_data;
4530+
vector<string> filterable_names_lg;
4531+
vector<long> filterable_data_lg;
4532+
45244533
filterable_names.push_back("forced_event");
45254534
if (force_change == true)
45264535
filterable_data.push_back((double)1.0);

cppapi/server/eventsupplier.cpp

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1182,12 +1182,6 @@ bool EventSupplier::detect_change(Attribute &attr, struct SuppliedEventData &att
11821182
the_new_any = &(attr_value.attr_val->value);
11831183
}
11841184

1185-
//
1186-
// get the mutex to synchronize the sending of events
1187-
//
1188-
1189-
omni_mutex_lock l(detect_mutex);
1190-
11911185
//
11921186
// Send event, if the read_attribute failed or if it is the first time that the read_attribute succeed after a failure.
11931187
// Same thing if the attribute quality factor changes to INVALID

cppapi/server/eventsupplier.h

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -174,9 +174,7 @@ protected :
174174
static omni_mutex push_mutex;
175175
static omni_condition push_cond;
176176

177-
// Added a mutex to synchronize the access to
178-
// detect_event which is used
179-
// from different threads
177+
// Unused, replaced with event_mutex. Left for backward compatibility.
180178
static omni_mutex detect_mutex;
181179

182180
private:

0 commit comments

Comments
 (0)