This repository was archived by the owner on Oct 13, 2023. It is now read-only.
File tree Expand file tree Collapse file tree 1 file changed +29
-5
lines changed Expand file tree Collapse file tree 1 file changed +29
-5
lines changed Original file line number Diff line number Diff line change @@ -171,19 +171,43 @@ pub unsafe extern "C" fn environ_sizes_get(
171
171
/// return `errno::inval`.
172
172
/// Note: This is similar to `clock_getres` in POSIX.
173
173
#[ no_mangle]
174
- pub unsafe extern "C" fn clock_res_get ( id : Clockid , resolution : * mut Timestamp ) -> Errno {
175
- unreachable ( )
174
+ pub extern "C" fn clock_res_get ( id : Clockid , resolution : & mut Timestamp ) -> Errno {
175
+ match id {
176
+ CLOCKID_MONOTONIC => {
177
+ let res = wasi_clocks:: monotonic_clock_resolution (
178
+ wasi_default_clocks:: default_monotonic_clock ( ) ,
179
+ ) ;
180
+ * resolution = res;
181
+ }
182
+ CLOCKID_REALTIME => {
183
+ let res = wasi_clocks:: wall_clock_resolution ( wasi_default_clocks:: default_wall_clock ( ) ) ;
184
+ * resolution = u64:: from ( res. nanoseconds ) + res. seconds * 1_000_000_000 ;
185
+ }
186
+ _ => unreachable ( ) ,
187
+ }
188
+ ERRNO_SUCCESS
176
189
}
177
190
178
191
/// Return the time value of a clock.
179
192
/// Note: This is similar to `clock_gettime` in POSIX.
180
193
#[ no_mangle]
181
194
pub unsafe extern "C" fn clock_time_get (
182
195
id : Clockid ,
183
- precision : Timestamp ,
184
- time : * mut Timestamp ,
196
+ _precision : Timestamp ,
197
+ time : & mut Timestamp ,
185
198
) -> Errno {
186
- unreachable ( )
199
+ match id {
200
+ CLOCKID_MONOTONIC => {
201
+ * time =
202
+ wasi_clocks:: monotonic_clock_now ( wasi_default_clocks:: default_monotonic_clock ( ) ) ;
203
+ }
204
+ CLOCKID_REALTIME => {
205
+ let res = wasi_clocks:: wall_clock_now ( wasi_default_clocks:: default_wall_clock ( ) ) ;
206
+ * time = u64:: from ( res. nanoseconds ) + res. seconds * 1_000_000_000 ;
207
+ }
208
+ _ => unreachable ( ) ,
209
+ }
210
+ ERRNO_SUCCESS
187
211
}
188
212
189
213
/// Provide file advisory information on a file descriptor.
You can’t perform that action at this time.
0 commit comments