1 // Copyright (c) 2023 Huawei Device Co., Ltd. 2 // Licensed under the Apache License, Version 2.0 (the "License"); 3 // you may not use this file except in compliance with the License. 4 // You may obtain a copy of the License at 5 // 6 // http://www.apache.org/licenses/LICENSE-2.0 7 // 8 // Unless required by applicable law or agreed to in writing, software 9 // distributed under the License is distributed on an "AS IS" BASIS, 10 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 11 // See the License for the specific language governing permissions and 12 // limitations under the License. 13 14 macro_rules! cfg_net { 15 ($($item:item)*) => { 16 $( 17 #[cfg(feature = "net")] 18 $item 19 )* 20 } 21 } 22 23 macro_rules! cfg_time { 24 ($($item:item)*) => { 25 $( 26 #[cfg(feature = "time")] 27 $item 28 )* 29 } 30 } 31 32 macro_rules! cfg_ffrt { 33 ($($item:item)*) => { 34 $( 35 #[cfg(feature = "ffrt")] 36 $item 37 )* 38 } 39 } 40 41 macro_rules! cfg_signal { 42 ($($item:item)*) => { 43 $( 44 #[cfg(feature = "signal")] 45 $item 46 )* 47 } 48 } 49 50 #[cfg(target_os = "linux")] 51 macro_rules! cfg_process { 52 ($($item:item)*) => { 53 $( 54 #[cfg(feature = "process")] 55 $item 56 )* 57 } 58 } 59 60 macro_rules! cfg_sync { 61 ($($item:item)*) => { 62 $( 63 #[cfg(feature = "sync")] 64 $item 65 )* 66 } 67 } 68 69 macro_rules! cfg_macros { 70 ($($item:item)*) => { 71 $( 72 #[cfg(feature = "macros")] 73 $item 74 )* 75 } 76 } 77 78 macro_rules! cfg_fs { 79 ($($item:item)*) => { 80 $( 81 #[cfg(feature = "fs")] 82 $item 83 )* 84 } 85 } 86 87 #[cfg(not(feature = "ffrt"))] 88 macro_rules! cfg_event { 89 ($($item:item)*) => { 90 $( 91 #[cfg(any(feature = "net", feature = "time"))] 92 $item 93 )* 94 } 95 } 96 97 macro_rules! cfg_not_ffrt { 98 ($($item:item)*) => { 99 $( 100 #[cfg(not(feature = "ffrt"))] 101 $item 102 )* 103 } 104 } 105 106 macro_rules! cfg_metrics { 107 ($($item:item)*) => { 108 $( 109 #[cfg(feature = "metrics")] 110 $item 111 )* 112 } 113 } 114 115 #[cfg(all(target_os = "linux", any(feature = "net", feature = "process")))] 116 macro_rules! syscall { 117 ($fn: ident ( $($arg: expr),* $(,)* ) ) => {{ 118 let res = unsafe { libc::$fn($($arg, )*) }; 119 if res == -1 { 120 Err(std::io::Error::last_os_error()) 121 } else { 122 Ok(res) 123 } 124 }}; 125 } 126