1 // Copyright 2014 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 // This file contains basic functions common to different Mojo system APIs. 6 // 7 // Note: This header should be compilable as C. 8 9 #ifndef MOJO_PUBLIC_C_SYSTEM_FUNCTIONS_H_ 10 #define MOJO_PUBLIC_C_SYSTEM_FUNCTIONS_H_ 11 12 #include <stddef.h> 13 #include <stdint.h> 14 15 #include "mojo/public/c/system/system_export.h" 16 #include "mojo/public/c/system/types.h" 17 18 #ifdef __cplusplus 19 extern "C" { 20 #endif 21 22 // Initializes Mojo in the calling application. 23 // 24 // With the exception of Mojo Core embedders, applications using Mojo APIs must 25 // call this function before any others. 26 // 27 // |options| may be null. 28 // 29 // Returns: 30 // |MOJO_RESULT_OK| if Mojo intiailization was successful. 31 // |MOJO_RESULT_INVALID_ARGUMENT| if |options| was null or invalid. 32 // |MOJO_RESULT_FAILED_PRECONDITION| if |MojoInitialize()| was already called 33 // once or if the application already explicitly initialized a Mojo Core 34 // environment as an embedder. 35 MOJO_SYSTEM_EXPORT MojoResult 36 MojoInitialize(const struct MojoInitializeOptions* options); 37 38 // Returns the time, in microseconds, since some undefined point in the past. 39 // The values are only meaningful relative to other values that were obtained 40 // from the same device without an intervening system restart. Such values are 41 // guaranteed to be monotonically non-decreasing with the passage of real time. 42 // Although the units are microseconds, the resolution of the clock may vary and 43 // is typically in the range of ~1-15 ms. 44 MOJO_SYSTEM_EXPORT MojoTimeTicks MojoGetTimeTicksNow(void); 45 46 // Closes the given |handle|. 47 // 48 // Returns: 49 // |MOJO_RESULT_OK| on success. 50 // |MOJO_RESULT_INVALID_ARGUMENT| if |handle| is not a valid handle. 51 // 52 // Concurrent operations on |handle| may succeed (or fail as usual) if they 53 // happen before the close, be cancelled with result |MOJO_RESULT_CANCELLED| if 54 // they properly overlap (this is likely the case with traps), or fail with 55 // |MOJO_RESULT_INVALID_ARGUMENT| if they happen after. 56 MOJO_SYSTEM_EXPORT MojoResult MojoClose(MojoHandle handle); 57 58 // Queries the last known signals state of a handle. 59 // 60 // Note that no guarantees can be made about the accuracy of the returned 61 // signals state by the time this returns, as other threads in the system may 62 // change the handle's state at any time. Use with appropriate discretion. 63 // 64 // Returns: 65 // |MOJO_RESULT_OK| on success. |*signals_state| is populated with the 66 // last known signals state of |handle|. 67 // |MOJO_RESULT_INVALID_ARGUMENT| if |handle| is not a valid handle or 68 // |signals_state| is null. 69 MOJO_SYSTEM_EXPORT MojoResult 70 MojoQueryHandleSignalsState(MojoHandle handle, 71 struct MojoHandleSignalsState* signals_state); 72 73 #ifdef __cplusplus 74 } // extern "C" 75 #endif 76 77 #endif // MOJO_PUBLIC_C_SYSTEM_FUNCTIONS_H_ 78