@@ -115,9 +115,15 @@ pub fn decode_error_kind(code: i32) -> ErrorKind {
115
115
// timeouts in SGX model. The enclave runner serving usercalls may lie about
116
116
// current time and/or ignore timeout values.
117
117
//
118
+ // Once the event is observed, `stop` will be used to determine whether or not
119
+ // we should continue to wait.
120
+ //
118
121
// FIXME: note these caveats in documentation of all public types that use this
119
122
// function in their execution path.
120
- pub fn wait_timeout_sgx ( event_mask : u64 , duration : crate :: time:: Duration ) {
123
+ pub fn wait_timeout_sgx < F > ( event_mask : u64 , duration : crate :: time:: Duration , stop : F )
124
+ where
125
+ F : Fn ( ) -> bool ,
126
+ {
121
127
use self :: abi:: usercalls;
122
128
use crate :: cmp;
123
129
use crate :: io:: ErrorKind ;
@@ -129,11 +135,13 @@ pub fn wait_timeout_sgx(event_mask: u64, duration: crate::time::Duration) {
129
135
let timeout = cmp:: min ( ( u64:: MAX - 1 ) as u128 , remaining. as_nanos ( ) ) as u64 ;
130
136
match usercalls:: wait ( event_mask, timeout) {
131
137
Ok ( eventset) => {
132
- if event_mask != 0 {
133
- rtassert ! ( eventset & event_mask == event_mask) ;
138
+ if event_mask == 0 {
139
+ rtabort ! ( "expected usercalls::wait() to return Err, found Ok." ) ;
140
+ }
141
+ rtassert ! ( eventset & event_mask == event_mask) ;
142
+ if stop ( ) {
134
143
return ;
135
144
}
136
- rtabort ! ( "expected usercalls::wait() to return Err, found Ok." ) ;
137
145
}
138
146
Err ( e) => {
139
147
rtassert ! ( e. kind( ) == ErrorKind :: TimedOut || e. kind( ) == ErrorKind :: WouldBlock )
0 commit comments