-
Notifications
You must be signed in to change notification settings - Fork 455
CDRIVER-4227 Add a shared_mutex, and use it when locking in shared_ptr atomic operations #895
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
CDRIVER-4227 Add a shared_mutex, and use it when locking in shared_ptr atomic operations #895
Conversation
…ations Tag CDRIVER-4002
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.
+1. This looks good; please consider renaming to something closer to the underlying platform functions, see comments. Excited to see the performance improvements! :-)
*/ | ||
typedef struct bson_shared_mutex_t { | ||
BSON_IF_WINDOWS (SRWLOCK native;) | ||
BSON_IF_POSIX (pthread_rwlock_t native;) |
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.
to consider: Note that pthreads also has a pthread_mutex_t, which makes me wonder if bson_shared_mutex_t is the right name, especially as the platforms also make that distinction. bson_shared_rwlock? "Archibald"?
Co-authored-by: Kevin Albertson <[email protected]>
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.
A very nice and welcome addition! 👍
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.
LGTM!
This change only applies to private code, and does not expose any changes in the public API.
At very high thread counts, locking on the shared_ptr atomic mutex begins to dominate. Using a shared_mutex significantly reduces the time spent in locking code and increases the performance under high contention. It could be improved further with a smarter use of the shared_ptr, but this is a significant basic improvement.