-
-
Notifications
You must be signed in to change notification settings - Fork 406
#4649 Feature/4649 thread safe broken rules #4819
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
ce901fb
52eea0f
402cb9c
cd22a20
3480f3c
0c43625
1ba2c8f
fd55070
aa79395
1e8fa68
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -6,6 +6,7 @@ | |
| // <summary>A collection of currently broken rules.</summary> | ||
| //----------------------------------------------------------------------- | ||
|
|
||
| using System.Collections.ObjectModel; | ||
| using Csla.Properties; | ||
| using Csla.Serialization.Mobile; | ||
|
|
||
|
|
@@ -446,8 +447,11 @@ public void AddRange(List<BrokenRule> list) | |
| { | ||
| if (list is null) | ||
| throw new ArgumentNullException(nameof(list)); | ||
| foreach (var item in list) | ||
| Add(item); | ||
| lock (_syncRoot) | ||
| { | ||
| foreach (var item in list) | ||
| Add(item); | ||
| } | ||
| } | ||
|
|
||
| /// <summary> | ||
|
|
@@ -479,5 +483,19 @@ protected override void OnSetState(SerializationInfo info) | |
| InformationCount = info.GetValue<int>("_infoCount"); | ||
| base.OnSetState(info); | ||
| } | ||
|
|
||
| /// <summary> | ||
| /// Returns a thread-safe copy of the current broken rules. | ||
| /// This method should be used instead of ToList() when a copy of the | ||
| /// broken rules list is desired that | ||
| /// </summary> | ||
| /// <returns>A new <see cref="ReadOnlyCollection{BrokenRule}"/> containing the broken rules at the time of the call.</returns> | ||
| public ReadOnlyCollection<BrokenRule> ToThreadSafeList() | ||
| { | ||
| lock (_syncRoot) | ||
| { | ||
| return this.ToList().AsReadOnly(); | ||
| } | ||
|
Comment on lines
+495
to
+498
|
||
| } | ||
Bowman74 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| } | ||
| } | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The AddRange method now acquires the _syncRoot lock and then calls Add() in a loop. However, the Add() method is declared with the 'new' keyword (line 144) rather than 'override', which means callers using the base class reference type could bypass this method and the associated counter updates. Additionally, since Add() is not protected by any lock internally, calling it within the lock doesn't actually provide thread safety for the Add operation itself - it only ensures AddRange iterations aren't interrupted. Consider reviewing whether Add() should also be protected by the lock or if there are scenarios where the base class Add() could be called directly.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This limitation was explained in the notes for the checkin