@@ -87,9 +87,11 @@ fn open_fd() -> Result<libc::c_int, Error> {
87
87
88
88
#[ cfg( not( any( target_os = "android" , target_os = "linux" ) ) ) ]
89
89
mod sync {
90
- // On non-Linux targets the critical section only opens file,
91
- // which should not block, so in the unlikely contended case,
92
- // we can sleep-wait for the opening operation to finish.
90
+ /// Sleep 1 ms before checking `FD` again.
91
+ ///
92
+ /// On non-Linux targets the critical section only opens file,
93
+ /// which should not block, so in the unlikely contended case,
94
+ /// we can sleep-wait for the opening operation to finish.
93
95
pub ( super ) fn wait ( ) {
94
96
let rqtp = libc:: timespec {
95
97
tv_sec : 0 ,
@@ -114,6 +116,12 @@ mod sync {
114
116
use super :: { Error , FD , FD_ONGOING_INIT } ;
115
117
use crate :: util_libc:: { last_os_error, open_readonly} ;
116
118
119
+ /// Wait for atomic `FD` to change value from `FD_ONGOING_INIT` to something else.
120
+ ///
121
+ /// Futex syscall with `FUTEX_WAIT` op puts the current thread to sleep
122
+ /// until futex syscall with `FUTEX_WAKE` op gets executed for `FD`.
123
+ ///
124
+ /// For more information read: https://www.man7.org/linux/man-pages/man2/futex.2.html
117
125
pub ( super ) fn wait ( ) {
118
126
let op = libc:: FUTEX_WAIT | libc:: FUTEX_PRIVATE_FLAG ;
119
127
let timeout_ptr = core:: ptr:: null :: < libc:: timespec > ( ) ;
@@ -128,6 +136,7 @@ mod sync {
128
136
} ) ;
129
137
}
130
138
139
+ /// Wake up all threads which wait for value of atomic `FD` to change.
131
140
pub ( super ) fn wake ( ) {
132
141
let op = libc:: FUTEX_WAKE | libc:: FUTEX_PRIVATE_FLAG ;
133
142
let ret = unsafe { libc:: syscall ( libc:: SYS_futex , & FD , op, libc:: INT_MAX ) } ;
0 commit comments