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

Commit a8f07bf

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)
1 parent e49d600 commit a8f07bf

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
@@ -3827,9 +3827,13 @@ void Attribute::fire_change_event(DevFailed *except)
38273827
time_t change3_subscription,change4_subscription,change5_subscription;
38283828

38293829
now = time(NULL);
3830-
change3_subscription = now - event_change3_subscription;
3831-
change4_subscription = now - event_change4_subscription;
3832-
change5_subscription = now - event_change5_subscription;
3830+
3831+
{
3832+
omni_mutex_lock oml(EventSupplier::get_event_mutex());
3833+
change3_subscription = now - event_change3_subscription;
3834+
change4_subscription = now - event_change4_subscription;
3835+
change5_subscription = now - event_change5_subscription;
3836+
}
38333837

38343838
//
38353839
// Get the event supplier(s)
@@ -4232,9 +4236,12 @@ void Attribute::fire_archive_event(DevFailed *except)
42324236

42334237
now = time(NULL);
42344238

4235-
archive3_subscription = now - event_archive3_subscription;
4236-
archive4_subscription = now - event_archive4_subscription;
4237-
archive5_subscription = now - event_archive5_subscription;
4239+
{
4240+
omni_mutex_lock oml(EventSupplier::get_event_mutex());
4241+
archive3_subscription = now - event_archive3_subscription;
4242+
archive4_subscription = now - event_archive4_subscription;
4243+
archive5_subscription = now - event_archive5_subscription;
4244+
}
42384245

42394246
//
42404247
// Get the event supplier(s)
@@ -4658,9 +4665,12 @@ void Attribute::fire_event(std::vector<std::string> &filt_names,std::vector<doub
46584665

46594666
now = time(NULL);
46604667

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

46654675
//
46664676
// Get the event supplier(s)
@@ -4930,9 +4940,12 @@ void Attribute::fire_error_periodic_event(DevFailed *except)
49304940

49314941
now = time(NULL);
49324942

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

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

0 commit comments

Comments
 (0)