Chromium Code Reviews| 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 // Add a wait on |handle| to |wait_set_handle|. | |
|
yzshen1
2015/11/18 23:50:58
Nit: please use "Adds" because the omitted subject
Anand Mistry (off Chromium)
2015/11/19 04:13:45
Done? Sorry, grammar has never been my strong poin
| |
| 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 | |
| 49 // thread. | |
| 50 MOJO_SYSTEM_EXPORT MojoResult MojoAddWaiter( | |
| 51 MojoHandle wait_set_handle, | |
| 52 MojoHandle handle, | |
| 53 MojoHandleSignals signals); | |
| 54 | |
| 55 // Remove |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 | |
| 65 // another thread. | |
| 66 MOJO_SYSTEM_EXPORT MojoResult MojoRemoveWaiter( | |
| 67 MojoHandle wait_set_handle, | |
| 68 MojoHandle handle); | |
| 69 | |
| 70 // Retreive a ready from |wait_set_handle|. A handle is ready if: | |
| 71 // - Its signals are satisfied. | |
| 72 // - It becomes known that no signal for the handle will ever be satisfied. | |
| 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. | |
|
yzshen1
2015/11/18 23:50:58
I wonder how the wait set will determine the order
Anand Mistry (off Chromium)
2015/11/19 04:13:45
Added a comment, and explanation inline.
On 2015/
yzshen1
2015/11/19 06:52:25
Thanks for the detailed reply!
I totally agree th
| |
| 102 // | |
| 103 MOJO_SYSTEM_EXPORT MojoResult MojoGetReadyHandle( | |
| 104 MojoHandle wait_set_handle, | |
| 105 MojoHandle *handle, // Out. | |
|
yzshen1
2015/11/18 23:50:58
style nit: '*' should be adjacent to the type inst
Anand Mistry (off Chromium)
2015/11/19 04:13:45
Done.
| |
| 106 struct MojoHandleSignalsState *signals_state); // Optional out. | |
| 107 | |
| 108 #ifdef __cplusplus | |
| 109 } // extern "C" | |
| 110 #endif | |
| 111 | |
| 112 #endif // MOJO_PUBLIC_C_SYSTEM_WAIT_SET_H_ | |
| OLD | NEW |