Skip to content
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

Add const constructors to RwLock, Notify, and Semaphore. #2833

Merged
merged 2 commits into from Sep 12, 2020
Merged

Add const constructors to RwLock, Notify, and Semaphore. #2833

merged 2 commits into from Sep 12, 2020

Conversation

steffahn
Copy link
Contributor

@steffahn steffahn commented Sep 12, 2020

Referring to the types in tokio::sync.
Also add const to new for the remaining atomic integers in src/loom (except for 64bit which is impossible) and to UnsafeCell.

Motivation and Solution

Builds upon previous work in #2790.
Closes #2756.

This PR adds const_new to sync::Notify, sync::RwLock, and sync::Semaphore, in addition to the previously added one for sync::Mutex as they can all be reasonably be used in static variables and this saves the need for (and overhead of) something like lazy_static in the case that parking_lot already is used internally anyways.

Also, upon encountering the problem of missing const for AtomicU8 in src/loom (used in Notify), I decided (also for consistency) to add const to all the constructors for the remaining types in that directory, whereas #2790 only added const to new for AtomicUSize.

Referring to the types in `tokio::sync`.
Also add `const` to `new` for the remaining atomic integers in `src/loom` and `UnsafeCell`.

Builds upon previous work in #2790.
Closes #2756.
Copy link
Contributor

@Darksonn Darksonn left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please try to avoid force-pushing, as it makes reading the change-history difficult for me to read.

tokio/src/sync/rwlock.rs Outdated Show resolved Hide resolved
@steffahn
Copy link
Contributor Author

Please try to avoid force-pushing, as it makes reading the change-history difficult for me to read.

I was going to stop force-pushing as soon as a review started or more than a typo-sized mistake was being fixed.

@Darksonn Darksonn merged commit 8d2e3bc into tokio-rs:master Sep 12, 2020
@Darksonn Darksonn added A-tokio Area: The main tokio crate C-enhancement Category: A PR with an enhancement or bugfix. M-sync Module: tokio/sync labels Sep 12, 2020
@steffahn steffahn deleted the const-notify-rwlock-semaphore branch September 13, 2020 14:42
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-tokio Area: The main tokio crate C-enhancement Category: A PR with an enhancement or bugfix. M-sync Module: tokio/sync
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Const constructors for Semaphore, Mutex, etc. with parking_lot.
3 participants