Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions .rustfmt.toml
Original file line number Diff line number Diff line change
Expand Up @@ -22,15 +22,15 @@ enum_discrim_align_threshold = 0
match_arm_blocks = true
match_arm_leading_pipes = "Never"
force_multiline_blocks = false
fn_args_layout = "Tall"
fn_params_layout = "Tall"
brace_style = "SameLineWhere"
control_brace_style = "AlwaysSameLine"
trailing_semicolon = true
trailing_comma = "Vertical"
match_block_trailing_comma = false
blank_lines_upper_bound = 1
blank_lines_lower_bound = 0
version = "Two"
style_edition = "2024"
inline_attribute_width = 0
merge_derives = true
use_try_shorthand = false
Expand Down
10 changes: 5 additions & 5 deletions src/futures/atomic_waker.rs
Original file line number Diff line number Diff line change
Expand Up @@ -126,12 +126,12 @@ pub struct AtomicWaker {
//
// Because of this, the waker will do one of two things.
//
// 1) Observe the application state change that Thread B is woken for. In this
// case, it is OK for Thread B's wake to be lost.
// 1) Observe the application state change that Thread B is woken for. In this case, it is OK for
// Thread B's wake to be lost.
//
// 2) Call register before attempting to observe the application state. Since
// Thread A still holds the `wake` lock, the call to `register` will result
// in the task waking itself and get scheduled again.
// 2) Call register before attempting to observe the application state. Since Thread A still holds
// the `wake` lock, the call to `register` will result in the task waking itself and get
// scheduled again.

/// Idle state
const WAITING: usize = 0;
Expand Down
4 changes: 2 additions & 2 deletions src/futures/task.rs
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
use super::{abort, waker_ref::WakerRef, ArcWake, ReadyToRunQueue};
use super::{ArcWake, ReadyToRunQueue, abort, waker_ref::WakerRef};
// use futures::task::{waker_ref, ArcWake, WakerRef};
use std::{
cell::UnsafeCell,
sync::{
Arc, Weak,
atomic::{
AtomicBool, AtomicPtr, AtomicU64,
Ordering::{self, SeqCst},
},
Arc, Weak,
},
};

Expand Down
18 changes: 11 additions & 7 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
// this is vendored code from the `futures-rs` crate, to avoid
// having a huge dependency when we only need a little bit
mod futures;
use crate::futures::{enter::enter, waker_ref, ArcWake, FuturesUnordered};
use crate::futures::{ArcWake, FuturesUnordered, enter::enter, waker_ref};

mod serial;
pub use serial::SerialCosync;
Expand All @@ -24,8 +24,8 @@ use std::{
ops,
pin::Pin,
sync::{
atomic::{AtomicBool, Ordering},
Arc, Weak,
atomic::{AtomicBool, Ordering},
},
task::{Context, Poll},
thread::{self, Thread},
Expand Down Expand Up @@ -98,7 +98,9 @@ impl<T: 'static + ?Sized> Cosync<T> {
/// This returns `true` on success and `false` on failure.
pub fn unqueue_task(&mut self, task_id: CosyncTaskId) -> bool {
let incoming = &mut unlock_mutex(&self.queue).incoming;
let Some(index) = incoming.iter().position(|future_obj| future_obj.1 == task_id) else { return false };
let Some(index) = incoming.iter().position(|future_obj| future_obj.1 == task_id) else {
return false;
};
incoming.remove(index);

true
Expand Down Expand Up @@ -191,7 +193,7 @@ impl<T: 'static + ?Sized> Cosync<T> {
/// on any task.
///
/// ```
/// use cosync::{yield_now, Cosync};
/// use cosync::{Cosync, yield_now};
///
/// let mut cosync = Cosync::new();
/// cosync.queue(move |mut input| async move {
Expand Down Expand Up @@ -343,7 +345,9 @@ impl<T: 'static + ?Sized> CosyncQueueHandle<T> {
pub fn unqueue_task(&mut self, task_id: CosyncTaskId) -> Option<bool> {
self.queue.upgrade().map(|queue_handle| {
let incoming = &mut unlock_mutex(&queue_handle).incoming;
let Some(index) = incoming.iter().position(|future_obj| future_obj.1 == task_id) else { return false };
let Some(index) = incoming.iter().position(|future_obj| future_obj.1 == task_id) else {
return false;
};
incoming.remove(index);

true
Expand Down Expand Up @@ -512,9 +516,9 @@ impl<T: 'static + ?Sized> CosyncInput<T> {
}

/// Queues a new task. This goes to the back of queue.
///
///
/// ## Panics
///
///
/// It is possible for this function to panic if the [`CosyncInput`] was somehow moved
/// out of the closure it was created it. This should not be possible.
pub fn queue<Task, Out>(&self, task: Task) -> CosyncTaskId
Expand Down
6 changes: 4 additions & 2 deletions src/serial.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ use std::{
};

use crate::{
create_future_object, next_cosync_task_id, unlock_mutex, Cosync, CosyncInput, CosyncQueueHandle, CosyncTaskId,
Cosync, CosyncInput, CosyncQueueHandle, CosyncTaskId, create_future_object, next_cosync_task_id, unlock_mutex,
};

/// A `SerialCosync` has the same API as `Cosync`, but *only* runs one task at a time,
Expand Down Expand Up @@ -56,7 +56,9 @@ impl<T: ?Sized + 'static> SerialCosync<T> {
/// This returns `true` on success and `false` on failure.
pub fn unqueue_task(&mut self, task_id: CosyncTaskId) -> bool {
let incoming = &mut unlock_mutex(&self.0.queue).incoming;
let Some(index) = incoming.iter().position(|future_obj| future_obj.1 == task_id) else { return false };
let Some(index) = incoming.iter().position(|future_obj| future_obj.1 == task_id) else {
return false;
};
incoming.remove(index);

true
Expand Down
Loading