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

Commit 5f89566

Browse files
committed
Protect event subscription timestamps with mutex
Fixes data race between: * omni worker thread (DServer::event_subscription) * and user thread pushing events (Attribute::fire_xxx_event) This is a backport of ee262d4 from tango-9-lts.
1 parent 82f1b89 commit 5f89566

File tree

1 file changed

+25
-12
lines changed

1 file changed

+25
-12
lines changed

cppapi/server/attribute.cpp

Lines changed: 25 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -3774,9 +3774,13 @@ void Attribute::fire_change_event(DevFailed *except)
37743774
time_t change3_subscription,change4_subscription,change5_subscription;
37753775

37763776
now = time(NULL);
3777-
change3_subscription = now - event_change3_subscription;
3778-
change4_subscription = now - event_change4_subscription;
3779-
change5_subscription = now - event_change5_subscription;
3777+
3778+
{
3779+
omni_mutex_lock oml(EventSupplier::get_event_mutex());
3780+
change3_subscription = now - event_change3_subscription;
3781+
change4_subscription = now - event_change4_subscription;
3782+
change5_subscription = now - event_change5_subscription;
3783+
}
37803784

37813785
//
37823786
// Get the event supplier(s)
@@ -4203,9 +4207,12 @@ void Attribute::fire_archive_event(DevFailed *except)
42034207

42044208
now = time(NULL);
42054209

4206-
archive3_subscription = now - event_archive3_subscription;
4207-
archive4_subscription = now - event_archive4_subscription;
4208-
archive5_subscription = now - event_archive5_subscription;
4210+
{
4211+
omni_mutex_lock oml(EventSupplier::get_event_mutex());
4212+
archive3_subscription = now - event_archive3_subscription;
4213+
archive4_subscription = now - event_archive4_subscription;
4214+
archive5_subscription = now - event_archive5_subscription;
4215+
}
42094216

42104217
//
42114218
// Get the event supplier(s)
@@ -4659,9 +4666,12 @@ void Attribute::fire_event(vector<string> &filt_names,vector<double> &filt_vals,
46594666

46604667
now = time(NULL);
46614668

4662-
user3_subscription = now - event_user3_subscription;
4663-
user4_subscription = now - event_user4_subscription;
4664-
user5_subscription = now - event_user5_subscription;
4669+
{
4670+
omni_mutex_lock oml(EventSupplier::get_event_mutex());
4671+
user3_subscription = now - event_user3_subscription;
4672+
user4_subscription = now - event_user4_subscription;
4673+
user5_subscription = now - event_user5_subscription;
4674+
}
46654675

46664676
//
46674677
// Get the event supplier(s)
@@ -4931,9 +4941,12 @@ void Attribute::fire_error_periodic_event(DevFailed *except)
49314941

49324942
now = time(NULL);
49334943

4934-
periodic3_subscription = now - event_periodic3_subscription;
4935-
periodic4_subscription = now - event_periodic4_subscription;
4936-
periodic5_subscription = now - event_periodic5_subscription;
4944+
{
4945+
omni_mutex_lock oml(EventSupplier::get_event_mutex());
4946+
periodic3_subscription = now - event_periodic3_subscription;
4947+
periodic4_subscription = now - event_periodic4_subscription;
4948+
periodic5_subscription = now - event_periodic5_subscription;
4949+
}
49374950

49384951
vector<int> client_libs = get_client_lib(PERIODIC_EVENT); // We want a copy
49394952

0 commit comments

Comments
 (0)