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
51 changes: 51 additions & 0 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
# Contributing to Synchrony

Thanks for your help improving the project! We are so happy to have you! :tada:

There are opportunities to contribute to Synchrony at any level. It doesn't matter if
you are just getting started with Rust or are the most weathered expert, we can
use your help. If you have any question about Synchrony, feel free to join [our group](https://t.me/compio_rs) in telegram.

This guide will walk you through the process of contributing to Synchrony on following topics:
Comment thread
George-Miao marked this conversation as resolved.

- [General guidelines](#general-guidelines)
- [Develop Guide](#develop-guide)
- [Style Guide](#style-guide)
- [Contribute with issue](#contribute-with-issue)
- [Contribute with pull request](#contribute-with-pull-request)

## General guidelines

We adhere to [Rust Code of Conduct](https://www.rust-lang.org/policies/code-of-conduct). tl;dr: **be nice**. Before making any contribution, check existing issue and pull requests to avoid duplication of effort. Also, in case of bug, try updating to the latest version of Compio and/or rust might help.

### Develop Guide

Use nightly toolchain to develop and run `rustup update` regularly.

### Style Guide

- Use `cargo fmt --all` with nightly toolchain to format your code (for nightly `rustfmt` features, see detail in [`rustfmt.toml`]).
- Use `cargo clippy --all` to check any style/code problem.
- Use [Angular Convention](https://github.com/angular/angular/blob/main/CONTRIBUTING.md#-commit-message-format) when making commits

[`rustfmt.toml`]: https://github.com/compio-rs/synchrony/blob/master/rustfmt.toml

## Contribute with issue

If you find a bug or have a feature request, please [open an issue](https://github.com/compio-rs/synchrony/issues/new/choose) with detailed description. Issues that are lack of information or destructive will be requested for more information or closed.
Comment thread
George-Miao marked this conversation as resolved.

It's also helpful if you can provide the following information:

- A minimal reproducible example
- The version of Synchrony you are using.
- The version of Rust you are using.
- Your environment (OS, Platform, etc).

## Contribute with pull request

We welcome any code contributions. It's always welcome and recommended to open an issue to discuss on major changes before opening a PR. And pull requests should:

- follow the [Style Guide](#style-guide).
- pass CI tests and style check.
- be reviewed by at least one maintainer before getting merged.
- have a description of what it does and why it is needed in PR body.
12 changes: 0 additions & 12 deletions src/atomic/unsync.rs
Original file line number Diff line number Diff line change
Expand Up @@ -43,12 +43,6 @@ impl Debug for AtomicBool {
}
}

impl Display for AtomicBool {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
Display::fmt(&self.v.get(), f)
}
}

impl AtomicBool {
/// Creates a new [`AtomicBool`]
pub const fn new(val: bool) -> Self {
Expand Down Expand Up @@ -204,12 +198,6 @@ macro_rules! atomic_int {
}
}

impl Display for $t {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
Display::fmt(&self.v.get(), f)
}
}

impl $t {
#[doc = concat!("Creates a new [`", stringify!($t), "`]")]
pub const fn new(val: $i) -> Self {
Expand Down
7 changes: 7 additions & 0 deletions src/bilock/mod.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,13 @@
/// Multithreaded BiLock
pub mod sync {
super::impl_bilock!(sync);

unsafe impl<T: Send> Send for Inner<T> {}
unsafe impl<T: Send> Sync for Inner<T> {}

impl<T: Send> crate::AssertMt for BiLock<T> {}
impl<T: Send> crate::AssertMt for BiLockAcquire<'_, T> {}
impl<T: Send> crate::AssertMt for BiLockGuard<'_, T> {}
Comment thread
George-Miao marked this conversation as resolved.
}

/// Singlethreaded BiLock
Expand Down
3 changes: 3 additions & 0 deletions src/event.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
/// Notify async tasks or threads.
pub mod sync {
pub use event_listener::{Event, EventListener};

impl crate::AssertMt for Event {}
impl crate::AssertMt for EventListener {}
}
#[doc(inline)]
pub use local_event as unsync;
2 changes: 2 additions & 0 deletions src/flag.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
/// Multithreaded boolean flag based on [`std::sync::atomic::AtomicBool`]
pub mod sync {
super::impl_flag!(sync);

impl crate::AssertMt for Flag {}
}

/// Singlethreaded boolean flag based on [`std::cell::Cell`]
Expand Down
4 changes: 4 additions & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -95,3 +95,7 @@ pub mod unsync {
flag::unsync as flag, mutex_blocking::unsync as mutex_blocking, shared::unsync as shared,
};
}

/// A trait to assert that a type is `Send + Sync`.
#[allow(dead_code)]
trait AssertMt: Send + Sync {}
34 changes: 34 additions & 0 deletions src/mutex/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,41 @@

/// Multithreaded async Mutex
pub mod sync {
use crate::AssertMt;

super::impl_mutex!(sync);

// Mutexes can be moved freely between threads and acquired on any thread so
// long as the inner value can be safely sent between threads.
unsafe impl<T: ?Sized + Send> Send for Mutex<T> {}
unsafe impl<T: ?Sized + Send> Sync for Mutex<T> {}

// It's safe to switch which thread the acquire is being attempted on so long as
// `T` can be accessed on that thread.
unsafe impl<T: ?Sized + Send> Send for MutexLockFuture<'_, T> {}

// doesn't have any interesting `&self` methods (only Debug)
unsafe impl<T: ?Sized> Sync for MutexLockFuture<'_, T> {}

// It's safe to switch which thread the acquire is being attempted on so long as
// `T` can be accessed on that thread.
unsafe impl<T: ?Sized + Send> Send for OwnedMutexLockFuture<T> {}

// doesn't have any interesting `&self` methods (only Debug)
unsafe impl<T: ?Sized> Sync for OwnedMutexLockFuture<T> {}

// Safe to send since we don't track any thread-specific details-- the inner
// lock is essentially spinlock-equivalent (attempt to flip an atomic bool)
unsafe impl<T: ?Sized + Send> Send for MutexGuard<'_, T> {}
unsafe impl<T: ?Sized + Sync> Sync for MutexGuard<'_, T> {}

unsafe impl<T: ?Sized + Send> Send for OwnedMutexGuard<T> {}
unsafe impl<T: ?Sized + Sync> Sync for OwnedMutexGuard<T> {}

unsafe impl<T: ?Sized + Send, U: ?Sized + Send> Send for MappedMutexGuard<'_, T, U> {}
unsafe impl<T: ?Sized + Sync, U: ?Sized + Sync> Sync for MappedMutexGuard<'_, T, U> {}

impl<T: Send> AssertMt for Mutex<T> {}
}

/// Singlethreaded async Mutex
Expand Down
2 changes: 2 additions & 0 deletions src/mutex_blocking.rs
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,8 @@ pub mod sync {
&mut *self.0
}
}

impl<T: Send> crate::AssertMt for Mutex<T> {}
}

/// Singlethreaded blocking Mutex
Expand Down
2 changes: 2 additions & 0 deletions src/waker_slot.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
/// Multithreaded `WakerSlot` based on [`futures::task::AtomicWaker`].
pub mod sync {
pub use futures::task::AtomicWaker as WakerSlot;

impl crate::AssertMt for WakerSlot {}
}

/// Singlethreaded `WakerSlot`
Expand Down