Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(646)

Side by Side Diff: mojo/public/rust/src/system/core.rs

Issue 2250183003: Make the fuchsia mojo/public repo the source of truth. (Closed) Base URL: https://github.com/domokit/mojo.git@master
Patch Set: Created 4 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « mojo/public/rust/src/lib.rs ('k') | mojo/public/rust/src/system/data_pipe.rs » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(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 }
OLDNEW
« no previous file with comments | « mojo/public/rust/src/lib.rs ('k') | mojo/public/rust/src/system/data_pipe.rs » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698