Skip to content

Commit 5ac175f

Browse files
committed
Tidy up the old codebase for Rust Edition 2024.
1. Remove the ability to retrieve the name of synchronization points, along with all related functions. 2. Update Rust Edition to version 2024. 3. Update `tokio` and exclude `async-trait`. 4. Simplify the writing of synchronized and synchronized_point macros by shortening their names. 5. Conduct general refactoring. 6. Add missing configuration files: `.editorconfig`, `rustfmt.toml`, and `rust-toolchain.toml`. 7. Simplify the writing of code generator macros. 8. Change the structure of the `core.rs` and `async_core.rs` files. 9. Remove `build.rs` and slightly rework functions. 10. Update documentation. 11. Fix strange naming warnings and address requirements flagged by clippy.
1 parent 1ece1cf commit 5ac175f

File tree

22 files changed

+570
-883
lines changed

22 files changed

+570
-883
lines changed

.github/workflows/CI.yml

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,13 @@ name: CI
22

33
on:
44
push:
5-
branches: [ master ]
5+
branches:
6+
- master
7+
- dev
68
pull_request:
7-
branches: [ master ]
9+
branches:
10+
- master
11+
- dev
812

913
env:
1014
CARGO_TERM_COLOR: always
@@ -35,8 +39,8 @@ jobs:
3539
- name: Run cargo alltest
3640
run: cargo test --all-features --verbose
3741
- name: Std
38-
run: cargo test --no-default-features --features std,point,get_point_name --lib --verbose --examples
42+
run: cargo test --no-default-features --features std,point --lib --verbose --examples
3943
- name: PL
40-
run: cargo test --no-default-features --features parking_lot,point,get_point_name --lib --verbose --examples
44+
run: cargo test --no-default-features --features parking_lot,point --lib --verbose --examples
4145
- name: ASYNC(TOKIO+PL)
42-
run: cargo test --no-default-features --features async,point,get_point_name --lib --verbose --tests
46+
run: cargo test --no-default-features --features async,point --lib --verbose --tests

Cargo.toml

Lines changed: 7 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,9 @@
11
[package]
22
name = "synchronized"
3-
version = "1.0.4"
3+
version = "1.1.0"
44
authors = ["Denis Kotlyarov (Денис Котляров) <denis2005991@gmail.com>"]
55
repository = "https://github.com/clucompany/synchronized.git"
6-
edition = "2021"
7-
build = "build.rs"
6+
edition = "2024"
87

98
license = "Apache-2.0"
109
readme = "README.md"
@@ -21,10 +20,8 @@ all-features = true
2120
rustdoc-args = ["--cfg", "docsrs"]
2221

2322
[features]
24-
default = ["std", "point", "get_point_name"]
25-
# Ability to get the name of the synchronization point.
26-
get_point_name = []
27-
# Adds or removes support for the `synchronized_point` macro.
23+
default = ["std", "point"]
24+
# Adds or removes support for the `sync_point` macro.
2825
point = []
2926
# Use synchronization primitives from `std`. Note that is_lock is not supported in it.
3027
#
@@ -33,12 +30,11 @@ std = []
3330

3431
# The synchronization primitive is implemented using the `tokio`+`parking_lot`
3532
# library for an asynchronous environment.
36-
async = ["tokio", "async-trait"]
33+
async = ["tokio"]
3734

3835
[dependencies]
3936
# The synchronization primitive is implemented using the `parking_lot` library.
40-
parking_lot = { version = "0.12.1", optional = true }
37+
parking_lot = { version = "0.12.3", optional = true }
4138

4239
# The synchronization primitive is implemented using the `tokio`+`parking_lot` library.
43-
tokio = { version = "1.21.2", optional = true, default-features = false, features = ["parking_lot", "sync"]}
44-
async-trait = { version = "0.1.58", optional = true }
40+
tokio = { version = "1.44.2", optional = true, default-features = false, features = ["parking_lot", "sync"]}

README.md

Lines changed: 15 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ Convenient and simple macro for code synchronization in multithreading.
1111
### 1. easy/sync
1212

1313
```rust
14-
use synchronized::synchronized;
14+
use synchronized::sync;
1515

1616
/*
1717
Quick implementation examples of blocking anonymous code.
@@ -20,21 +20,21 @@ use synchronized::synchronized;
2020
fn main() {
2121
// #1 Anonymous inter-threaded synchronized code,
2222
// in the case of multi-threading, one thread will wait for the completion of another.
23-
synchronized! {
23+
sync! {
2424
println!("1");
2525
}
2626

2727
// #2 Anonymous inter-threaded synchronized code,
2828
// in the case of multi-threading, one thread will wait for the completion of another.
29-
synchronized!( println!("1"); );
29+
sync!( println!("1"); );
3030
}
3131
```
3232

3333
### 2. sync_static
3434

3535
```rust
3636
use std::thread::spawn;
37-
use synchronized::synchronized;
37+
use synchronized::sync;
3838

3939
/*
4040
A more illustrative example of code blocking implementation
@@ -73,7 +73,7 @@ fn sync_fn() -> usize {
7373
//
7474
// The code will never run at the same time. If one thread is executing
7575
// this code, the second thread will wait for this code to finish executing.
76-
let result = synchronized! {
76+
let result = sync! {
7777
static mut POINT0: usize = 0;
7878
static mut POINT1: usize = 0;
7979

@@ -93,7 +93,7 @@ fn sync_fn() -> usize {
9393

9494
```rust
9595
use std::thread::spawn;
96-
use synchronized::synchronized;
96+
use synchronized::sync;
9797

9898
/*
9999
An example that describes how to quickly create an anonymous
@@ -111,7 +111,7 @@ fn main() {
111111
for thread_id in 0..5 {
112112
let join = spawn(move || {
113113
// Create anonymous synchronized code with one mutable variable `sync_let` and `count`.
114-
let result = synchronized!(
114+
let result = sync!(
115115
(sync_let: String = String::new(), count: usize = 0) {
116116
// If it's the first thread,
117117
// then theoretically `sync_let` is String::new().
@@ -167,21 +167,12 @@ fn main() {
167167
!!! In this example, the assembly requires the `point` feature to be active.
168168
*/
169169

170-
#[cfg( feature = "point" )]
171-
use synchronized::synchronized_point;
172-
#[cfg( feature = "point" )]
173-
use synchronized::synchronized;
174-
175-
#[cfg( not(feature = "point") )]
176-
macro_rules! synchronized_point {
177-
[ $($unk:tt)* ] => {
178-
println!("!!! This example requires support for the `point` feature. Run the example with `cargo run --example point --all-features`.");
179-
};
180-
}
170+
use synchronized::sync_point;
171+
use synchronized::sync;
181172

182173
fn main() {
183174
// A sync point named `COMB_SYNC` to group anonymous code syncs by name.
184-
synchronized_point! {(COMB_SYNC) {
175+
sync_point! {(COMB_SYNC) {
185176
static mut POINT: usize = 0;
186177
println!("GeneralSyncPoint, name_point: {}", COMB_SYNC.get_sync_point_name());
187178

@@ -190,7 +181,7 @@ fn main() {
190181
//
191182
// This code is not executed concurrently in a multi-threaded environment,
192183
// one thread is waiting for someone else's code to execute in this part of the code.
193-
let result0 = synchronized! ((->COMB_SYNC) {
184+
let result0 = sync! ((->COMB_SYNC) {
194185
println!("SyncCode, name_point: {}", COMB_SYNC.get_sync_point_name());
195186
unsafe {
196187
POINT += 1;
@@ -208,7 +199,7 @@ fn main() {
208199
// Note that `result0` and `result1` cannot be calculated at the same time,
209200
// this does not happen because `result0` or `result1` are calculated in
210201
// synchronized code with a single sync point of the same name.
211-
let result1 = synchronized! ((->COMB_SYNC) {
202+
let result1 = sync! ((->COMB_SYNC) {
212203
println!("SyncCode, name_point: {}", COMB_SYNC.get_sync_point_name());
213204
unsafe {
214205
POINT += 1;
@@ -238,7 +229,6 @@ default-features = false
238229
features = [
239230
"std",
240231
#"point",
241-
#"get_point_name"
242232
]
243233
```
244234

@@ -248,12 +238,11 @@ For a `synchronized` macro, use the primitives implemented by the default `parki
248238

249239
```rust,ignore
250240
[dependencies.synchronized]
251-
version = "1.0.4"
241+
version = "1.1.0"
252242
default-features = false
253243
features = [
254244
"parking_lot",
255245
#"point",
256-
#"get_point_name"
257246
]
258247
```
259248

@@ -263,12 +252,11 @@ For a `synchronized` macro, use the primitives implemented by the default `tokio
263252

264253
```rust,ignore
265254
[dependencies.synchronized]
266-
version = "1.0.4"
255+
version = "1.1.0"
267256
default-features = false
268257
features = [
269258
"async",
270259
#"point",
271-
#"get_point_name"
272260
]
273261
```
274262

@@ -280,6 +268,6 @@ features = [
280268

281269
# License
282270

283-
Copyright 2022 #UlinProject Denis Kotlyarov (Денис Котляров)
271+
Copyright 2022-2025 #UlinProject Denis Kotlyarov (Денис Котляров)
284272

285273
Licensed under the Apache License, Version 2.0

build.rs

Lines changed: 0 additions & 46 deletions
This file was deleted.

examples/point.rs

Lines changed: 21 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -1,66 +1,52 @@
1-
21
/*
3-
An example implementation of synchronized code with
2+
An example implementation of synchronized code with
43
one non-anonymous synchronization point.
5-
6-
This example creates a set of anonymous sync codes associated with a
7-
single named sync point. Each synchronization code executes in the same
8-
way as ordinary anonymous code, but execution occurs simultaneously in a
4+
5+
This example creates a set of anonymous sync codes associated with a
6+
single named sync point. Each synchronization code executes in the same
7+
way as ordinary anonymous code, but execution occurs simultaneously in a
98
multi-threaded environment in only one of them.
10-
9+
1110
!!! In this example, the assembly requires the `point` feature to be active.
1211
*/
1312

14-
#[cfg( feature = "point" )]
15-
use synchronized::synchronized_point;
16-
#[cfg( feature = "point" )]
17-
use synchronized::synchronized;
18-
19-
#[cfg( not(feature = "point") )]
20-
macro_rules! synchronized_point {
21-
[ $($unk:tt)* ] => {
22-
println!("!!! This example requires support for the `point` feature. Run the example with `cargo run --example point --all-features`.");
23-
};
24-
}
13+
use synchronized::{sync, sync_point};
2514

2615
fn main() {
2716
// A sync point named `COMB_SYNC` to group anonymous code syncs by name.
28-
synchronized_point! {(COMB_SYNC) {
17+
sync_point! {(COMB_SYNC) {
2918
static mut POINT: usize = 0;
30-
println!("GeneralSyncPoint, name_point: {}", COMB_SYNC.get_sync_point_name());
31-
32-
// #1 Anonymous synchronized code that operates on a
19+
20+
// #1 Anonymous synchronized code that operates on a
3321
// single named synchronization point.
3422
//
35-
// This code is not executed concurrently in a multi-threaded environment,
23+
// This code is not executed concurrently in a multi-threaded environment,
3624
// one thread is waiting for someone else's code to execute in this part of the code.
37-
let result0 = synchronized! ((->COMB_SYNC) {
38-
println!("SyncCode, name_point: {}", COMB_SYNC.get_sync_point_name());
25+
let result0 = sync! ((->COMB_SYNC) {
3926
unsafe {
4027
POINT += 1;
41-
28+
4229
POINT
4330
}
4431
});
45-
32+
4633
// This line of code is not synchronized and can run concurrently on all threads.
4734
println!("Unsynchronized code");
48-
49-
// #2 Anonymous synchronized code that operates on a
35+
36+
// #2 Anonymous synchronized code that operates on a
5037
// single named synchronization point.
5138
//
52-
// Note that `result0` and `result1` cannot be calculated at the same time,
53-
// this does not happen because `result0` or `result1` are calculated in
39+
// Note that `result0` and `result1` cannot be calculated at the same time,
40+
// this does not happen because `result0` or `result1` are calculated in
5441
// synchronized code with a single sync point of the same name.
55-
let result1 = synchronized! ((->COMB_SYNC) {
56-
println!("SyncCode, name_point: {}", COMB_SYNC.get_sync_point_name());
42+
let result1 = sync! ((->COMB_SYNC) {
5743
unsafe {
5844
POINT += 1;
59-
45+
6046
POINT
6147
}
6248
});
63-
49+
6450
// Display debug information.
6551
println!("result, res0: {:?}, res1: {:?}", result0, result1);
6652
}}

0 commit comments

Comments
 (0)