OLD | NEW |
| (Empty) |
1 // Copyright 2016 The Chromium Authors. All rights reserved. | |
2 // Use of this source code is governed by a BSD-style license that can be | |
3 // found in the LICENSE file. | |
4 | |
5 use std::ptr; | |
6 use std::u32; | |
7 use std::vec; | |
8 | |
9 use system::ffi; | |
10 // This full import is intentional; nearly every type in mojo_types needs to be
used. | |
11 use system::mojo_types::*; | |
12 use system::handle; | |
13 | |
14 /// Get the time ticks now according to the Mojo IPC. As | |
15 /// can be seen in the documentation for the Mojo C API, | |
16 /// time ticks are meaningless in an absolute sense. Instead, | |
17 /// one should compare the results of two of these calls to | |
18 /// get a proper notion of time passing. | |
19 pub fn get_time_ticks_now() -> MojoTimeTicks { | |
20 unsafe { ffi::MojoGetTimeTicksNow() } | |
21 } | |
22 | |
23 /// Waits on many handles (or rather any structures that wrap | |
24 /// handles) until the signals declared in 'signals' for each handle | |
25 /// are triggered, waiting for a maximum global time of 'deadline'. | |
26 /// This function blocks. | |
27 pub fn wait_many(handles: &[&handle::Handle], | |
28 signals: &[HandleSignals], | |
29 states: &mut [SignalsState], | |
30 deadline: MojoDeadline) | |
31 -> (i32, MojoResult) { | |
32 assert_eq!(handles.len(), signals.len()); | |
33 assert!(states.len() == handles.len() || states.len() == 0); | |
34 let num_inputs = handles.len(); | |
35 if num_inputs == 0 { | |
36 let result = MojoResult::from_code(unsafe { | |
37 ffi::MojoWaitMany(ptr::null(), | |
38 ptr::null(), | |
39 0, | |
40 deadline, | |
41 ptr::null_mut(), | |
42 ptr::null_mut()) | |
43 }); | |
44 return (-1, result); | |
45 } | |
46 let states_ptr = if states.len() != 0 { | |
47 states.as_mut_ptr() | |
48 } else { | |
49 ptr::null_mut() | |
50 }; | |
51 let mut index: u32 = u32::MAX; | |
52 let result = unsafe { | |
53 let mut raw_handles: vec::Vec<MojoHandle> = vec::Vec::with_capacity(num_
inputs); | |
54 for handle in handles.iter() { | |
55 raw_handles.push(handle.get_native_handle()) | |
56 } | |
57 MojoResult::from_code(ffi::MojoWaitMany(raw_handles.as_ptr(), | |
58 signals.as_ptr(), | |
59 num_inputs as u32, | |
60 deadline, | |
61 &mut index as *mut u32, | |
62 states_ptr)) | |
63 }; | |
64 (index as i32, result) | |
65 } | |
OLD | NEW |