Skip to content

Commit eb22b13

Browse files
committed
1. Minor bugs have been fixed
1 parent 5ef1553 commit eb22b13

File tree

4 files changed

+76
-42
lines changed

4 files changed

+76
-42
lines changed

src/beh/async.rs

Lines changed: 25 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -7,16 +7,19 @@ extern crate tokio;
77
pub use tokio::sync::Mutex;
88
pub use tokio::sync::MutexGuard;
99
use crate::core::SyncPointBeh;
10-
use crate::cfg_not_async;
11-
use crate::cfg_async;
10+
use crate::cfg_not_only_async;
11+
use crate::cfg_only_async;
1212

13-
cfg_async! {
13+
cfg_only_async! {
14+
/// A macro that determines whether to add asynchronous fn support for traits.
1415
macro_rules! async_or_sync_impltraitcode {
1516
[
1617
$(#[$($addmeta:tt)*])*
17-
impl[$($left:tt)*] $name_trait: ident for $impl_ty: ty {
18-
#async { $($async_code:tt)* }
19-
#sync { $($sync_code:tt)* }
18+
impl $([$($left:tt)*])? $name_trait: ident for $impl_ty: ty {
19+
$(#[$doc_hide0:meta])* // doc hidden
20+
#only_async { $($async_code:tt)* }
21+
$(#[$doc_hide1:meta])* // doc hidden
22+
#only_sync { $($sync_code:tt)* }
2023

2124
$($code:tt)+
2225
}
@@ -27,27 +30,30 @@ cfg_async! {
2730

2831
$(#[$($addmeta)*])*
2932
#[async_trait]
30-
impl<$($left)*> $name_trait for $impl_ty {
33+
impl $(<$($left)*>)? $name_trait for $impl_ty {
3134
$($async_code)*
3235

3336
$($code)+
3437
}
3538
};
3639
}
3740
}
38-
cfg_not_async! {
41+
cfg_not_only_async! {
42+
/// A macro that determines whether to add asynchronous fn support for traits.
3943
macro_rules! async_or_sync_impltraitcode {
4044
[
4145
$(#[$($addmeta:tt)*])*
42-
impl[$($left:tt)*] $name_trait: ident for $impl_ty: ty {
43-
#async { $($async_code:tt)* }
44-
#sync { $($sync_code:tt)* }
46+
impl $([$($left:tt)*])? $name_trait: ident for $impl_ty: ty {
47+
$(#[$doc_hide0:meta])* // doc hidden
48+
#only_async { $($async_code:tt)* }
49+
$(#[$doc_hide1:meta])* // doc hidden
50+
#only_sync { $($sync_code:tt)* }
4551

4652
$($code:tt)+
4753
}
4854
] => {
4955
$(#[$($addmeta)*])*
50-
impl<$($left)*> $name_trait for $impl_ty {
56+
impl $(<$($left)*>)? $name_trait for $impl_ty {
5157
$($sync_code)*
5258

5359
$($code)+
@@ -58,7 +64,9 @@ cfg_not_async! {
5864

5965
async_or_sync_impltraitcode! {
6066
impl['a, T: Send] SyncPointBeh for &'a Mutex<T> {
61-
#async {
67+
/// This section of code is connected only if
68+
/// the current library is asynchronous.
69+
#only_async {
6270
#[inline(always)]
6371
async fn new_lock(&self) -> Self::LockType {
6472
Mutex::lock(self).await
@@ -77,7 +85,9 @@ async_or_sync_impltraitcode! {
7785
drop(lock_type)
7886
}
7987
}
80-
#sync {
88+
/// This section of code is connected only if
89+
/// the current library is synchronous.
90+
#only_sync {
8191
#[inline(always)]
8292
fn new_lock(&self) -> Self::LockType {
8393
unimplemented!();
@@ -123,7 +133,7 @@ macro_rules! __synchronized_beh {
123133
{
124134
// Definition of the current implementation
125135
#name
126-
} => { "async(tokio+parking_lot)" };
136+
} => { "async(tokio+parking_lot+async_trait)" };
127137

128138
{
129139
// Defining a new synchronization point, usually implements static

src/core.rs

Lines changed: 24 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -5,16 +5,19 @@ use core::marker::PhantomData;
55

66
use core::ops::Deref;
77
use core::ops::DerefMut;
8-
use crate::cfg_async;
9-
use crate::cfg_not_async;
8+
use crate::cfg_only_async;
9+
use crate::cfg_not_only_async;
1010

11-
cfg_async! {
11+
cfg_only_async! {
12+
/// A macro that determines whether to add asynchronous fn support for traits.
1213
macro_rules! async_or_sync_newtraitcode {
1314
[
1415
$(#[$($addmeta:tt)*])*
1516
pub trait $name_trait: ident {
16-
#async { $($async_code:tt)* }
17-
#sync { $($sync_code:tt)* }
17+
$(#[$doc_hide0:meta])* // doc hidden
18+
#only_async { $($async_code:tt)* }
19+
$(#[$doc_hide1:meta])* // doc hidden
20+
#only_sync { $($sync_code:tt)* }
1821

1922
$($code:tt)+
2023
}
@@ -26,27 +29,30 @@ cfg_async! {
2629
$(#[$($addmeta)*])*
2730
#[async_trait]
2831
pub trait $name_trait {
29-
$($async_code)*
32+
$($async_code)* // < -- ONLY ASYNC CODE
3033

3134
$($code)+
3235
}
3336
};
3437
}
3538
}
36-
cfg_not_async! {
39+
cfg_not_only_async! {
40+
/// A macro that determines whether to add asynchronous fn support for traits.
3741
macro_rules! async_or_sync_newtraitcode {
3842
[
3943
$(#[$($addmeta:tt)*])*
4044
pub trait $name_trait: ident {
41-
#async { $($async_code:tt)* }
42-
#sync { $($sync_code:tt)* }
45+
$(#[$doc_hide0:meta])* // doc hidden
46+
#only_async { $($async_code:tt)* }
47+
$(#[$doc_hide1:meta])* // doc hidden
48+
#only_sync { $($sync_code:tt)* }
4349

4450
$($code:tt)+
4551
}
4652
] => {
4753
$(#[$($addmeta)*])*
4854
pub trait $name_trait {
49-
$($sync_code)*
55+
$($sync_code)* // < -- ONLY SYNC CODE
5056

5157
$($code)+
5258
}
@@ -57,7 +63,9 @@ cfg_not_async! {
5763
async_or_sync_newtraitcode! {
5864
/// Implementation of the behavior for the used synchronization structure.
5965
pub trait SyncPointBeh {
60-
#async {
66+
/// This section of code is connected only if
67+
/// the current library is asynchronous.
68+
#only_async {
6169
/// Create a new hold lock.
6270
async fn new_lock(&self) -> Self::LockType;
6371

@@ -69,7 +77,9 @@ async_or_sync_newtraitcode! {
6977
/// the lock (usually always involves just a drop)
7078
async fn unlock(&self, lock_type: Self::LockType);
7179
}
72-
#sync {
80+
/// This section of code is connected only if
81+
/// the current library is synchronous.
82+
#only_sync {
7383
/// Create a new hold lock.
7484
fn new_lock(&self) -> Self::LockType;
7585

@@ -143,14 +153,13 @@ impl<T, N> SyncPoint<T, N> where T: SyncPointBeh {
143153
}
144154
}
145155

146-
cfg_not_async! {
156+
cfg_not_only_async! {
147157
/// Create a new hold lock.
148158
#[inline(always)]
149159
pub fn new_lock(&self) -> T::LockType {
150160
T::new_lock(&self.mutex_builder)
151161
}
152162

153-
154163
/// If the lock exists and is not released, then return None,
155164
/// if there is no lock, then create it and return Some.
156165
#[inline(always)]
@@ -166,7 +175,7 @@ impl<T, N> SyncPoint<T, N> where T: SyncPointBeh {
166175
}
167176
}
168177

169-
cfg_async! {
178+
cfg_only_async! {
170179
/// Create a new hold lock.
171180
#[inline(always)]
172181
pub async fn new_lock(&self) -> T::LockType {

src/lib.rs

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -315,7 +315,7 @@ pub mod beh {
315315

316316
#[cfg_attr(docsrs, doc(cfg( feature = "async" )))]
317317
#[cfg( feature = "async" )]
318-
//cfg_async! {
318+
//cfg_only_async! {
319319
pub mod r#async;
320320
//}
321321

@@ -473,10 +473,9 @@ macro_rules! synchronized {
473473

474474
/// Describes the selected default lock for the `synchronized` macro. Currently it is `
475475
#[doc = crate::__synchronized_beh!( #name )]
476-
/// ` by default.
476+
/// `.
477477
pub const CURRENT_DEF_BEH: &'static str = crate::__synchronized_beh!( #name );
478478

479-
480479
/// Whether `get_point_name` was enabled in this build.
481480
///
482481
/// The `get_point_name` feature determines whether the connection
@@ -504,3 +503,15 @@ pub const IS_SYNC_POINT_SUPPORT: bool = {
504503
true
505504
}
506505
};
506+
507+
cfg_only_async! {
508+
/// Determines if the library code and its locks are fully asynchronous.
509+
/// Currently it is `true`.
510+
pub const IS_ALWAYS_ASYNC: bool = true;
511+
}
512+
513+
cfg_not_only_async! {
514+
/// Determines if the library code and its locks are fully asynchronous.
515+
/// Currently it is `false`.
516+
pub const IS_ALWAYS_ASYNC: bool = false;
517+
}

src/macro_features.rs

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11

2-
// # cfg_async
2+
//! Additional macros for code generation depending on the `features` used.
33
4+
// # cfg_only_async
5+
6+
/// Code is passed from the macro only if the `async` function is clearly defined.
47
#[doc(hidden)]
58
#[macro_export]
69
#[cfg(all(
@@ -9,13 +12,14 @@
912
not(feature = "parking_lot"),
1013
not(feature = "std"),
1114
))]
12-
macro_rules! cfg_async {
15+
macro_rules! cfg_only_async {
1316
[ $($code:tt)+ ] => {
1417
#[cfg_attr(docsrs, doc(cfg( feature = "async" )))]
1518
$($code)+
1619
}
1720
}
1821

22+
/// Code is passed from the macro only if the `async` function is clearly defined.
1923
#[doc(hidden)]
2024
#[macro_export]
2125
#[cfg(not(all(
@@ -24,12 +28,13 @@ macro_rules! cfg_async {
2428
not(feature = "parking_lot"),
2529
not(feature = "std"),
2630
)))]
27-
macro_rules! cfg_async {
31+
macro_rules! cfg_only_async {
2832
[ $($code:tt)+ ] => {}
2933
}
3034

31-
// # cfg_not_async
35+
// # cfg_not_only_async
3236

37+
/// Code is not passed from a macro only if the asynchronous function is clearly defined.
3338
#[doc(hidden)]
3439
#[macro_export]
3540
#[cfg(all(
@@ -38,12 +43,11 @@ macro_rules! cfg_async {
3843
not(feature = "parking_lot"),
3944
not(feature = "std"),
4045
))]
41-
macro_rules! cfg_not_async {
42-
[ $($code:tt)+ ] => {
43-
44-
}
46+
macro_rules! cfg_not_only_async {
47+
[ $($code:tt)+ ] => {}
4548
}
4649

50+
/// Code is not passed from a macro only if the asynchronous function is clearly defined.
4751
#[doc(hidden)]
4852
#[macro_export]
4953
#[cfg(not(all(
@@ -52,7 +56,7 @@ macro_rules! cfg_not_async {
5256
not(feature = "parking_lot"),
5357
not(feature = "std"),
5458
)))]
55-
macro_rules! cfg_not_async {
59+
macro_rules! cfg_not_only_async {
5660
[ $($code:tt)+ ] => {
5761
#[cfg_attr(docsrs, doc(cfg( not(feature = "async") )))]
5862
$($code)+

0 commit comments

Comments
 (0)