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