OLD | NEW |
---|---|
(Empty) | |
1 // Copyright 2015 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 types/constants and functions specific to wait sets. | |
6 // | |
7 // Note: This header should be compilable as C. | |
8 | |
9 #ifndef MOJO_PUBLIC_C_SYSTEM_WAIT_SET_H_ | |
10 #define MOJO_PUBLIC_C_SYSTEM_WAIT_SET_H_ | |
11 | |
12 #include "mojo/public/c/system/system_export.h" | |
13 #include "mojo/public/c/system/types.h" | |
14 | |
15 #ifdef __cplusplus | |
16 extern "C" { | |
17 #endif | |
18 | |
19 // Note: See the comment in functions.h about the meaning of the "optional" | |
20 // label for pointer parameters. | |
21 | |
22 // Creates a wait set. A wait set is a way to efficiently wait on multiple | |
23 // handles. | |
24 // | |
25 // On success, |*wait_set_handle| will contain a handle to a wait set. | |
26 // | |
27 // Returns: | |
28 // |MOJO_RESULT_OK| on success. | |
29 // |MOJO_RESULT_INVALID_ARGUMENT| if |wait_set_handle| is null. | |
30 // |MOJO_RESULT_RESOURCE_EXHAUSTED| if a process/system/quota/etc. limit has | |
31 // been reached. | |
32 MOJO_SYSTEM_EXPORT MojoResult MojoCreateWaitSet( | |
33 MojoHandle* wait_set_handle); // Out. | |
34 | |
35 // Adds a wait on |handle| to |wait_set_handle|. | |
36 // | |
37 // A handle can only be added to any given wait set once, but may be added to | |
38 // any number of different wait sets. To modify the signals being waited for, | |
39 // the handle must first be removed, and then added with the new signals. | |
40 // | |
41 // Returns: | |
42 // |MOJO_RESULT_OK| if |handle| was successfully added to |wait_set_handle|. | |
43 // |MOJO_RESULT_INVALID_ARGUMENT| if |handle| is not a valid handle, or | |
44 // |wait_set_handle| is not a valid wait set. | |
45 // |MOJO_RESULT_ALREADY_EXISTS| if |handle| already exists in | |
46 // |wait_set_handle|. | |
47 // | |
48 // It is safe to add a handle to a wait set while performing a wait on another | |
Sam McNally
2015/11/23 06:51:57
Is it specified what happens when this is done?
I
Anand Mistry (off Chromium)
2015/12/03 00:47:13
I thought that would be obvious. If the other thre
| |
49 // thread. | |
50 MOJO_SYSTEM_EXPORT MojoResult MojoAddWaiter( | |
darin (slow to review)
2015/11/23 22:19:01
naming nit (bikeshedding): I'm not sure the term "
Anand Mistry (off Chromium)
2015/12/03 00:47:13
Done.
| |
51 MojoHandle wait_set_handle, | |
52 MojoHandle handle, | |
53 MojoHandleSignals signals); | |
54 | |
55 // Removes |handle| from |wait_set_handle|. | |
56 // | |
57 // Returns: | |
58 // |MOJO_RESULT_OK| if |handle| was successfully removed from | |
59 // |wait_set_handle|. | |
60 // |MOJO_RESULT_INVALID_ARGUMENT| if |handle| is not a valid handle, or | |
61 // |wait_set_handle| is not a valid wait set. | |
62 // |MOJO_RESULT_NOT_FOUND| if |handle| does not exist in |wait_set_handle|. | |
63 // | |
64 // It is safe to remove a handle from a wait set while performing a wait on | |
Sam McNally
2015/11/23 06:51:56
Ditto.
Anand Mistry (off Chromium)
2015/12/03 00:47:13
Done.
| |
65 // another thread. | |
66 MOJO_SYSTEM_EXPORT MojoResult MojoRemoveWaiter( | |
67 MojoHandle wait_set_handle, | |
68 MojoHandle handle); | |
69 | |
70 // Retreives a ready from |wait_set_handle|. A handle is ready if: | |
Sam McNally
2015/11/23 06:51:56
Retrieves a ready handle from |wait_set_handle|.
Anand Mistry (off Chromium)
2015/12/03 00:47:13
Done.
| |
71 // - Its signals are satisfied. | |
72 // - It becomes known that no signal for the handle will ever be satisfied. | |
Sam McNally
2015/11/23 06:51:57
"It" refers to something different here compared t
Anand Mistry (off Chromium)
2015/12/03 00:47:13
Done... I think...
| |
73 // - It is closed. | |
74 // | |
75 // A wait set may have ready handles when it satisfies the | |
76 // |MOJO_HANDLE_SIGNAL_READABLE| signal. Since handles may be added and removed | |
77 // from a wait set concurrently, it is possible for a wait set to satisfy | |
78 // |MOJO_HANDLE_SIGNAL_READABLE|, but not have any ready handles when | |
79 // |MojoGetReadyHandle()| is called. These spurious wake-ups must be gracefully | |
80 // handled. | |
81 // | |
82 // |*handle| will contain a handle whose signal has been satisfied, or can not | |
83 // ever be satisfied. Care should be taken that if a handle is closed on another | |
84 // thread, |*handle| would be invalid, but the return value may not be | |
85 // |MOJO_RESULT_CANCELLED|. | |
86 // | |
87 // |signals_state| (optional): See documentation for |MojoHandleSignalsState|. | |
88 // | |
89 // Returns: | |
90 // |MOJO_RESULT_OK| if |*handle| has its signals satisfied. | |
91 // |MOJO_RESULT_CANCELLED| if |*handle| was closed (necessarily from another | |
92 // thread) during the wait. | |
93 // |MOJO_RESULT_INVALID_ARGUMENT| if |wait_set_handle| is not a valid wait | |
94 // set. | |
95 // |MOJO_RESULT_FAILED_PRECONDITION| if it is or becomes impossible that | |
96 // |*handle| will ever satisfy any of its signals. | |
97 // |MOJO_RESULT_SHOULD_WAIT| if there are no ready handles. | |
98 // | |
99 // Mojo signals and satisfiability are logically 'level-triggered'. Therefore, | |
100 // if a signal continues to be satisfied and is not removed from the wait set, | |
101 // subsequent calls to |MojoGetReadyHandle()| will return the same handle. | |
102 // | |
103 // If multiple handles have their signals satisfied, the order in which handles | |
104 // are returned is undefined. The same handle, if not removed, may be returned | |
105 // in consecutive calls. Callers should not rely on any fairness and handles | |
106 // could be starved if not acted on. | |
107 MOJO_SYSTEM_EXPORT MojoResult MojoGetReadyHandle( | |
108 MojoHandle wait_set_handle, | |
109 MojoHandle* handle, // Out. | |
110 struct MojoHandleSignalsState *signals_state); // Optional out. | |
111 | |
112 #ifdef __cplusplus | |
113 } // extern "C" | |
114 #endif | |
115 | |
116 #endif // MOJO_PUBLIC_C_SYSTEM_WAIT_SET_H_ | |
OLD | NEW |