@@ -100,8 +100,8 @@ impl Context {
100
100
101
101
/// Returns the remaining time in the execution in milliseconds. This is based on the
102
102
/// deadline header passed by Lambda's Runtime APIs.
103
- pub fn get_time_remaining_mills ( & self ) -> u128 {
104
- ( self . deadline - systime:: get_time_ns ( ) ) / 1000 / 1000
103
+ pub fn get_time_remaining_millis ( & self ) -> u128 {
104
+ self . deadline - systime:: get_time_ms ( )
105
105
}
106
106
}
107
107
@@ -112,17 +112,17 @@ mod systime {
112
112
use libc;
113
113
114
114
#[ cfg( any( target_os = "macos" , target_os = "ios" ) ) ]
115
- pub ( super ) fn get_time_ns ( ) -> u128 {
116
- unsafe { u128:: from ( libc:: mach_absolute_time ( ) ) }
115
+ pub ( super ) fn get_time_ms ( ) -> u128 {
116
+ unsafe { u128:: from ( libc:: mach_absolute_time ( ) ) / 1_000_000 }
117
117
}
118
118
119
119
#[ cfg( not( any( windows, target_os = "macos" , target_os = "ios" ) ) ) ]
120
- pub ( super ) fn get_time_ns ( ) -> u128 {
120
+ pub ( super ) fn get_time_ms ( ) -> u128 {
121
121
let mut ts = libc:: timespec { tv_sec : 0 , tv_nsec : 0 } ;
122
122
unsafe {
123
- libc:: clock_gettime ( libc:: CLOCK_MONOTONIC , & mut ts) ;
123
+ libc:: clock_gettime ( libc:: CLOCK_REALTIME , & mut ts) ;
124
124
}
125
- return ( ts. tv_sec as u128 ) * 1000000000 + ( ts. tv_nsec as u128 ) ;
125
+ return ( ( ts. tv_sec as u128 ) * 1_000 ) + ( ( ts. tv_nsec as u128 ) / 1_000_000 ) ;
126
126
}
127
127
}
128
128
@@ -133,7 +133,7 @@ pub(crate) mod tests {
133
133
use std:: { thread:: sleep, time} ;
134
134
135
135
fn get_deadline ( secs : u8 ) -> u128 {
136
- systime:: get_time_ns ( ) + ( u128:: from ( secs) * 1000 * 1000 * 1000 )
136
+ systime:: get_time_ms ( ) + ( u128:: from ( secs) * 1_000 )
137
137
}
138
138
139
139
pub ( crate ) fn test_context ( deadline : u8 ) -> Context {
@@ -160,7 +160,7 @@ pub(crate) mod tests {
160
160
println ! ( "Set deadline to: {}" , ctx. deadline) ;
161
161
sleep ( time:: Duration :: new ( 2 , 0 ) ) ;
162
162
163
- let remaining = ctx. get_time_remaining_mills ( ) ;
163
+ let remaining = ctx. get_time_remaining_millis ( ) ;
164
164
assert ! (
165
165
remaining > 7800 && remaining < 8200 ,
166
166
"Remaining time in millis outside the expected range: {}" ,
0 commit comments