| OLD | NEW |
| (Empty) |
| 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 // Note: This header should be compilable as C. | |
| 13 | |
| 14 #include "mojo/public/c/system/system_export.h" | |
| 15 #include "mojo/public/c/system/types.h" | |
| 16 | |
| 17 #ifdef __cplusplus | |
| 18 extern "C" { | |
| 19 #endif | |
| 20 | |
| 21 // Note: Pointer parameters that are labelled "optional" may be null (at least | |
| 22 // under some circumstances). Non-const pointer parameters are also labeled | |
| 23 // "in", "out", or "in/out", to indicate how they are used. (Note that how/if | |
| 24 // such a parameter is used may depend on other parameters or the requested | |
| 25 // operation's success/failure. E.g., a separate |flags| parameter may control | |
| 26 // whether a given "in/out" parameter is used for input, output, or both.) | |
| 27 | |
| 28 // Platform-dependent monotonically increasing tick count representing "right | |
| 29 // now." The resolution of this clock is ~1-15ms. Resolution varies depending | |
| 30 // on hardware/operating system configuration. | |
| 31 MOJO_SYSTEM_EXPORT MojoTimeTicks MojoGetTimeTicksNow(void); | |
| 32 | |
| 33 // Closes the given |handle|. | |
| 34 // | |
| 35 // Returns: | |
| 36 // |MOJO_RESULT_OK| on success. | |
| 37 // |MOJO_RESULT_INVALID_ARGUMENT| if |handle| is not a valid handle. | |
| 38 // | |
| 39 // Concurrent operations on |handle| may succeed (or fail as usual) if they | |
| 40 // happen before the close, be cancelled with result |MOJO_RESULT_CANCELLED| if | |
| 41 // they properly overlap (this is likely the case with |MojoWait()|, etc.), or | |
| 42 // fail with |MOJO_RESULT_INVALID_ARGUMENT| if they happen after. | |
| 43 MOJO_SYSTEM_EXPORT MojoResult MojoClose(MojoHandle handle); | |
| 44 | |
| 45 // Waits on the given handle until one of the following happens: | |
| 46 // - A signal indicated by |signals| is satisfied. | |
| 47 // - It becomes known that no signal indicated by |signals| will ever be | |
| 48 // satisfied. (See the description of the |MOJO_RESULT_CANCELLED| and | |
| 49 // |MOJO_RESULT_FAILED_PRECONDITION| return values below.) | |
| 50 // - Until |deadline| has passed. | |
| 51 // | |
| 52 // If |deadline| is |MOJO_DEADLINE_INDEFINITE|, this will wait "forever" (until | |
| 53 // one of the other wait termination conditions is satisfied). If |deadline| is | |
| 54 // 0, this will return |MOJO_RESULT_DEADLINE_EXCEEDED| only if one of the other | |
| 55 // termination conditions (e.g., a signal is satisfied, or all signals are | |
| 56 // unsatisfiable) is not already satisfied. | |
| 57 // | |
| 58 // |signals_state| (optional): See documentation for |MojoHandleSignalsState|. | |
| 59 // | |
| 60 // Returns: | |
| 61 // |MOJO_RESULT_OK| if some signal in |signals| was satisfied (or is already | |
| 62 // satisfied). | |
| 63 // |MOJO_RESULT_CANCELLED| if |handle| was closed (necessarily from another | |
| 64 // thread) during the wait. | |
| 65 // |MOJO_RESULT_INVALID_ARGUMENT| if |handle| is not a valid handle (e.g., if | |
| 66 // it has already been closed). The |signals_state| value is unchanged. | |
| 67 // |MOJO_RESULT_DEADLINE_EXCEEDED| if the deadline has passed without any of | |
| 68 // the signals being satisfied. | |
| 69 // |MOJO_RESULT_FAILED_PRECONDITION| if it becomes known that none of the | |
| 70 // signals in |signals| can ever be satisfied (e.g., when waiting on one | |
| 71 // end of a message pipe and the other end is closed). | |
| 72 // | |
| 73 // If there are multiple waiters (on different threads, obviously) waiting on | |
| 74 // the same handle and signal, and that signal becomes is satisfied, all waiters | |
| 75 // will be awoken. | |
| 76 MOJO_SYSTEM_EXPORT MojoResult | |
| 77 MojoWait(MojoHandle handle, | |
| 78 MojoHandleSignals signals, | |
| 79 MojoDeadline deadline, | |
| 80 struct MojoHandleSignalsState* signals_state); // Optional out. | |
| 81 | |
| 82 // Waits on |handles[0]|, ..., |handles[num_handles-1]| until: | |
| 83 // - (At least) one handle satisfies a signal indicated in its respective | |
| 84 // |signals[0]|, ..., |signals[num_handles-1]|. | |
| 85 // - It becomes known that no signal in some |signals[i]| will ever be | |
| 86 // satisfied. | |
| 87 // - |deadline| has passed. | |
| 88 // | |
| 89 // This means that |MojoWaitMany()| behaves as if |MojoWait()| were called on | |
| 90 // each handle/signals pair simultaneously, completing when the first | |
| 91 // |MojoWait()| would complete. | |
| 92 // | |
| 93 // See |MojoWait()| for more details about |deadline|. | |
| 94 // | |
| 95 // |result_index| (optional) is used to return the index of the handle that | |
| 96 // caused the call to return. For example, the index |i| (from 0 to | |
| 97 // |num_handles-1|) if |handle[i]| satisfies a signal from |signals[i]|. You | |
| 98 // must manually initialize this to a suitable sentinel value (e.g. -1) | |
| 99 // before you make this call because this value is not updated if there is | |
| 100 // no specific handle that causes the function to return. Pass null if you | |
| 101 // don't need this value to be returned. | |
| 102 // | |
| 103 // |signals_states| (optional) points to an array of size |num_handles| of | |
| 104 // MojoHandleSignalsState. See |MojoHandleSignalsState| for more details | |
| 105 // about the meaning of each array entry. This array is not an atomic | |
| 106 // snapshot. The array will be updated if the function does not return | |
| 107 // |MOJO_RESULT_INVALID_ARGUMENT| or |MOJO_RESULT_RESOURCE_EXHAUSTED|. | |
| 108 // | |
| 109 // Returns: | |
| 110 // |MOJO_RESULT_CANCELLED| if some |handle[i]| was closed (necessarily from | |
| 111 // another thread) during the wait. | |
| 112 // |MOJO_RESULT_RESOURCE_EXHAUSTED| if there are too many handles. The | |
| 113 // |signals_state| array is unchanged. | |
| 114 // |MOJO_RESULT_INVALID_ARGUMENT| if some |handle[i]| is not a valid handle | |
| 115 // (e.g., if it is zero or if it has already been closed). The | |
| 116 // |signals_state| array is unchanged. | |
| 117 // |MOJO_RESULT_DEADLINE_EXCEEDED| if the deadline has passed without any of | |
| 118 // handles satisfying any of its signals. | |
| 119 // |MOJO_RESULT_FAILED_PRECONDITION| if it is or becomes impossible that SOME | |
| 120 // |handle[i]| will ever satisfy any of the signals in |signals[i]|. | |
| 121 MOJO_SYSTEM_EXPORT MojoResult | |
| 122 MojoWaitMany(const MojoHandle* handles, | |
| 123 const MojoHandleSignals* signals, | |
| 124 uint32_t num_handles, | |
| 125 MojoDeadline deadline, | |
| 126 uint32_t* result_index, // Optional out | |
| 127 struct MojoHandleSignalsState* signals_states); // Optional out | |
| 128 | |
| 129 #ifdef __cplusplus | |
| 130 } // extern "C" | |
| 131 #endif | |
| 132 | |
| 133 #endif // MOJO_PUBLIC_C_SYSTEM_FUNCTIONS_H_ | |
| OLD | NEW |