749: Rename spawn_allocate to spawn_mark_used r=Dirbaio a=danbev

This commit contains a suggestion to rename `TaskStorage::spawn_allocate`.

The motivation for this is when reading through the code I was
expecting something else to happen in this method, due to `allocate` in
the method name.

I'm very new to this code base so I may be wrong in thinking this
is a good change, but I wanted to open this PR to get some feedback.

Co-authored-by: Daniel Bevenius <daniel.bevenius@gmail.com>
This commit is contained in:
bors[bot] 2022-05-03 14:58:24 +00:00 committed by GitHub
commit 85c0525e01
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -164,14 +164,14 @@ impl<F: Future + 'static> TaskStorage<F> {
/// Once the task has finished running, you may spawn it again. It is allowed to spawn it /// Once the task has finished running, you may spawn it again. It is allowed to spawn it
/// on a different executor. /// on a different executor.
pub fn spawn(&'static self, future: impl FnOnce() -> F) -> SpawnToken<impl Sized> { pub fn spawn(&'static self, future: impl FnOnce() -> F) -> SpawnToken<impl Sized> {
if self.spawn_allocate() { if self.spawn_mark_used() {
unsafe { SpawnToken::<F>::new(self.spawn_initialize(future)) } unsafe { SpawnToken::<F>::new(self.spawn_initialize(future)) }
} else { } else {
SpawnToken::<F>::new_failed() SpawnToken::<F>::new_failed()
} }
} }
fn spawn_allocate(&'static self) -> bool { fn spawn_mark_used(&'static self) -> bool {
let state = STATE_SPAWNED | STATE_RUN_QUEUED; let state = STATE_SPAWNED | STATE_RUN_QUEUED;
self.raw self.raw
.state .state
@ -234,7 +234,7 @@ impl<F: Future + 'static, const N: usize> TaskPool<F, N> {
/// which will cause [`Spawner::spawn()`] to return the error. /// which will cause [`Spawner::spawn()`] to return the error.
pub fn spawn(&'static self, future: impl FnOnce() -> F) -> SpawnToken<impl Sized> { pub fn spawn(&'static self, future: impl FnOnce() -> F) -> SpawnToken<impl Sized> {
for task in &self.pool { for task in &self.pool {
if task.spawn_allocate() { if task.spawn_mark_used() {
return unsafe { SpawnToken::<F>::new(task.spawn_initialize(future)) }; return unsafe { SpawnToken::<F>::new(task.spawn_initialize(future)) };
} }
} }
@ -282,7 +282,7 @@ impl<F: Future + 'static, const N: usize> TaskPool<F, N> {
// by the user, with arbitrary hand-implemented futures. This is why these return `SpawnToken<F>`. // by the user, with arbitrary hand-implemented futures. This is why these return `SpawnToken<F>`.
for task in &self.pool { for task in &self.pool {
if task.spawn_allocate() { if task.spawn_mark_used() {
return SpawnToken::<FutFn>::new(task.spawn_initialize(future)); return SpawnToken::<FutFn>::new(task.spawn_initialize(future));
} }
} }