Skip to content

Commit

Permalink
1. The library version has been raised to 1.0.2.
Browse files Browse the repository at this point in the history
2. Added feature `point` to enable or disable `synchonized_macro` from assembly.
3. Build.rs has been corrected.
  • Loading branch information
denisandroid committed Aug 31, 2022
1 parent c82be8b commit 2239367
Show file tree
Hide file tree
Showing 9 changed files with 180 additions and 153 deletions.
5 changes: 2 additions & 3 deletions .github/workflows/CI.yml
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@ jobs:
- name: Run cargo alltest
run: cargo test --all-features --verbose
- name: Std
run: cargo test --no-default-features --features std,get_point_name --lib --verbose
run: cargo test --no-default-features --features std,point,get_point_name --lib --verbose
- name: PL
run: cargo test --no-default-features --features parking_lot,get_point_name --lib --verbose

run: cargo test --no-default-features --features parking_lot,point,get_point_name --lib --verbose
8 changes: 5 additions & 3 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
[package]
name = "synchronized"
version = "1.0.1"
version = "1.0.2"
authors = ["Denis Kotlyarov (Денис Котляров) <denis2005991@gmail.com>"]
repository = "https://github.com/clucompany/synchronized.git"
edition = "2021"
build = "build.rs"

license = "Apache-2.0"
readme = "README.md"
Expand All @@ -23,12 +24,13 @@ rustdoc-args = ["--cfg", "docsrs"]
default = ["std", "get_point_name"]
# Ability to get the name of the synchronization point.
get_point_name = []
# Adds or removes support for the `synchronized_point` macro.
point = []
# Use synchronization primitives from `std`. Note that is_lock is not supported in it.
#
# Note that you can just use `parking_lot` instead of `std`.
std = []

[dependencies]
# Choose between `std` or `parking_lot` as
# the default synchronization primitive.
# The synchronization primitive is implemented using the `parking_lot` library.
parking_lot = { version = "0.12.1", optional = true }
6 changes: 4 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -222,10 +222,11 @@ For a `synchronized` macro, use the primitives implemented by the default `std`

```rust,ignore
[dependencies.synchronized]
version = "1.0.1"
version = "1.0.2"
default-features = false
features = [
"std",
#"point",
#"get_point_name"
]
```
Expand All @@ -236,10 +237,11 @@ For a `synchronized` macro, use the primitives implemented by the default `parki

```rust,ignore
[dependencies.synchronized]
version = "1.0.1"
version = "1.0.2"
default-features = false
features = [
"parking_lot",
#"point",
#"get_point_name"
]
```
Expand Down
3 changes: 2 additions & 1 deletion build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
feature = "std",
)
)]
#[inline(always)]
fn main() {
/// CargoWarningPrintln
macro_rules! cwarning {
Expand All @@ -26,7 +27,7 @@ fn main() {
};
}

cwarning!("synchronized: The choice of synchronization between `std` and `parking_lot` was expected by default for `synchronized` macro. It is not possible to use both synchronization methods at the same time, `std` is now used.");
cwarning!(@const: "synchronized: The choice of synchronization between `std` and `parking_lot` was expected by default for `synchronized` macro. It is not possible to use both synchronization methods at the same time, `std` is now used.");
}

#[cfg(
Expand Down
2 changes: 1 addition & 1 deletion src/beh/pl.rs
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ macro_rules! __synchronized_beh {
#[allow(non_upper_case_globals)]
pub static $v_point_name: $crate::core::SyncPoint<
&'static $crate::beh::pl::Mutex<$t>,
$crate::__make_name!(#get_name<_HIDDEN_NAME>)
$crate::__make_name!( #get_name<_HIDDEN_NAME> )
> = $crate::core::SyncPoint::new(&CONST_MUTEX);
};
{
Expand Down
2 changes: 1 addition & 1 deletion src/beh/std.rs
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ macro_rules! __synchronized_beh {
#[allow(non_upper_case_globals)]
pub static $v_point_name: $crate::core::SyncPoint<
&'static $crate::beh::std::Mutex<$t>,
$crate::__make_name!(#get_name<_HIDDEN_NAME>)
$crate::__make_name!( #get_name<_HIDDEN_NAME> )
> = $crate::core::SyncPoint::new(&CONST_MUTEX);
};
{
Expand Down
162 changes: 22 additions & 140 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -235,10 +235,11 @@ For a `synchronized` macro, use the primitives implemented by the default `std`
```rust,ignore
[dependencies.synchronized]
version = "1.0.1"
version = "1.0.2"
default-features = false
features = [
"std",
#"point",
#"get_point_name"
]
```
Expand All @@ -249,10 +250,11 @@ For a `synchronized` macro, use the primitives implemented by the default `parki
```rust,ignore
[dependencies.synchronized]
version = "1.0.1"
version = "1.0.2"
default-features = false
features = [
"parking_lot",
#"point",
#"get_point_name"
]
```
Expand All @@ -269,11 +271,14 @@ features = [
#![cfg_attr(not(feature = "std"), no_std)]

pub mod core;
#[cfg( feature = "point" )]
#[cfg_attr(docsrs, doc(cfg(feature = "point")))]
mod point;

/// Various synchronization primitives used in the `synchronized` macro.
pub mod beh {
#[cfg( feature = "parking_lot" )]
#[cfg_attr(docsrs, doc(cfg(feature = "parking_lot")))]
#[cfg( feature = "parking_lot" )]
pub mod pl;

#[cfg_attr(docsrs, doc(cfg(feature = "std")))]
Expand Down Expand Up @@ -424,143 +429,6 @@ macro_rules! synchronized {
[] => {}
}

/// Create a named code synchronization point.
/// It is required in order to combine two or more synchronized places in the code,
/// excluding their simultaneous execution.
///
/// ### 1. One named sync point and two or more sync codes for it.
/// ```rust
/// use synchronized::synchronized_point;
/// use synchronized::synchronized;
///
/// synchronized_point! {(COMB_SYNC) {
/// static mut POINT: usize = 0;
///
/// // #1 Anonymous synchronized code that operates on a single named synchronization point.
/// let result0 = synchronized! ((->COMB_SYNC) {
/// println!("SyncCode, name_point: {}", COMB_SYNC.get_sync_point_name());
/// unsafe {
/// POINT += 1;
///
/// POINT
/// }
/// });
///
/// // This line of code is not synchronized and can run concurrently on all threads.
/// println!("Unsynchronized code");
///
/// // #2 Anonymous synchronized code that operates on a single named synchronization point.
/// let result1 = synchronized! ((->COMB_SYNC) {
/// println!("SyncCode, name_point: {}", COMB_SYNC.get_sync_point_name());
/// unsafe {
/// POINT += 1;
///
/// POINT
/// }
/// });
/// }}
/// ```
///
/// ### 2. One named sync point and two or more sync codes for it. With one mutable variable.
/// ```rust
/// use synchronized::synchronized;
/// use synchronized::synchronized_point;
///
/// synchronized_point! {COMB_SYNC (String = String::new()) {
/// static mut POINT: usize = 0;
///
/// // #1 Anonymous synchronized code that operates on a single named synchronization point.
/// let result0 = synchronized! ((->COMB_SYNC) {
/// println!("SyncCode, name_point: {}", COMB_SYNC.get_sync_point_name());
/// unsafe {
/// POINT += 1;
///
/// POINT
/// }
/// });
///
/// // #1 This line of code is not synchronized and can run concurrently on all threads.
/// println!("Unsynchronized code");
///
/// // Synchronized code by `COMB_SYNC` label with `sync_let: String` mutable variable
/// let result1 = synchronized!(->COMB_SYNC(sync_let) {
/// // sync_let <-- String (COMB_SYNC)
/// *sync_let = "test".to_string();
/// });
///
/// // #2 This line of code is not synchronized and can run concurrently on all threads.
/// println!("Unsynchronized code");
///
/// // #2 Anonymous synchronized code that operates on a single named synchronization point.
/// let result2 = synchronized! ((->COMB_SYNC) {
/// println!("SyncCode, name_point: {}", COMB_SYNC.get_sync_point_name());
/// unsafe {
/// POINT += 1;
///
/// POINT
/// }
/// });
/// }}
#[macro_export]
macro_rules! synchronized_point {
{
// Named sync point named `$sync_point_name`.
//
// With a mutable synchronized variable of type `$ty`
// with a default value of `$expr`.
$sync_point_name:ident ( $ty: ty = $expr:expr $(,)? ) {$($all:tt)*} $(; $($unk:tt)*)?
} => {
{
$crate::__synchronized_beh!(#new_point<$ty: [$expr]>: $sync_point_name);

$($all)*
}

$($crate::synchronized_point! {
$($unk)*
})?
};
{
// Named sync point named `$sync_point_name`.
//
// With mutable synchronized comma-separated variables of type `$ty`
// with a default value of `$expr`.
$sync_point_name:ident ( $($ty: ty = $expr:expr),* $(,)? ) {$($all:tt)*} $(; $($unk:tt)*)?
} => {
{
$crate::__synchronized_beh!(#new_point<($($ty),*): [($($expr),*)]>: $sync_point_name);

$($all)*
}

$($crate::synchronized_point! {
$($unk)*
})?
};
{
// Named sync point named `$sync_point_name`
($sync_point_name:ident) {$($all:tt)*} $(; $($unk:tt)*)?
} => {
$crate::synchronized_point! {
$sync_point_name (() = ()) { $($all)* }

$(; $($unk)*)?
}
};

{
// COMPILE_ERROR
$($unk:tt)+
} => {
compile_error!(concat!(
"Error writing macro `synchronized_point`, incode: ",
stringify!($($unk)+),
));
};

[] => {}
}

/// Describes the selected default lock for the `synchronized` macro. Currently it is `
#[doc = crate::__synchronized_beh!( #name )]
/// ` by default.
Expand All @@ -579,3 +447,17 @@ pub const IS_GET_POINT_NAME_SUPPORT: bool = {
true
}
};

/// Whether synchronized `point` was enabled in this build.
///
/// The `synchronized_point` macro allows you to create shared synchronization
/// points that prevent certain code from being executed at the same time.
pub const IS_SYNC_POINT_SUPPORT: bool = {
#[cfg( not(feature = "point") )] {
false
}

#[cfg( feature = "point" )] {
true
}
};
Loading

0 comments on commit 2239367

Please sign in to comment.