-
-
Notifications
You must be signed in to change notification settings - Fork 2.8k
Description
Is your feature request related to a problem? Please describe.
The following Semaphore APIs use a u32 count of permits:
Semaphore::acquire_manySemaphore::try_acquire_manySemaphore::acquire_many_ownedSemaphore::try_acquire_many_owned
Whereas the following Semaphore APIs use a usize count of permits:
Semaphore::newSemaphore::const_newSemaphore::available_permitsSemaphore::add_permits
This incongruity in the API is awkward, but it also prohibits a key usecase for the Semaphore type: protecting access to memory, e.g. memory leases. In fact the PR which added the u32 APIs mentions this usecase, but presumably the author didn't need to support leases of more than 4GiB (#2607).
Describe the solution you'd like
- Change
[Owned]SemaphorePermitto hold ausizepermit count internally instead ofu32. I haven't confirmed, but I believe the size_ofSemaphorePermitwon't change due to padding, so hopefully this won't have any performance impact. - Add four new methods replacing each permutation of
[try_]acquire_many[_owned], and which take ausizepermit count. To kick off the painting, I propose potential names below. - [optional] Deprecate
Semaphore::[try_]acquire_many[_owned].
Describe alternatives you've considered
For applications which need to acquire more than 2^32 permits there really isn't a way to use the current semaphore API - it's not correct to acquire permits in a loop due to risk of deadlock.
Additional context
Potential names for the new methods:
[try_]acquire_many_permits[_owned][try_]acquire_permits[_owned][try_]acquire_n[_owned]