Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(328)

Side by Side Diff: mojo/public/c/system/wait_set.h

Issue 1429553002: API definition for WaitSet. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Rebase. Created 5 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « mojo/public/c/system/core.h ('k') | third_party/mojo/mojo_public.gyp » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(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 // It is safe to add a handle to a wait set while performing a wait on another
42 // thread. If the added handle already has its signals satisfied, the waiting
43 // thread will be woken.
44 //
45 // Returns:
46 // |MOJO_RESULT_OK| if |handle| was successfully added to |wait_set_handle|.
47 // |MOJO_RESULT_INVALID_ARGUMENT| if |handle| is not a valid handle, or
48 // |wait_set_handle| is not a valid wait set.
49 // |MOJO_RESULT_ALREADY_EXISTS| if |handle| already exists in
50 // |wait_set_handle|.
51 MOJO_SYSTEM_EXPORT MojoResult MojoAddHandle(
52 MojoHandle wait_set_handle,
53 MojoHandle handle,
54 MojoHandleSignals signals);
55
56 // Removes |handle| from |wait_set_handle|.
57 //
58 // It is safe to remove a handle from a wait set while performing a wait on
59 // another thread. If handle has its signals satisfied while it is being
60 // removed, the waiting thread may be woken up, but no handle may be available
61 // when |MojoGetReadyHandles()| is called.
62 //
63 // Returns:
64 // |MOJO_RESULT_OK| if |handle| was successfully removed from
65 // |wait_set_handle|.
66 // |MOJO_RESULT_INVALID_ARGUMENT| if |handle| is not a valid handle, or
67 // |wait_set_handle| is not a valid wait set.
68 // |MOJO_RESULT_NOT_FOUND| if |handle| does not exist in |wait_set_handle|.
69 MOJO_SYSTEM_EXPORT MojoResult MojoRemoveHandle(
70 MojoHandle wait_set_handle,
71 MojoHandle handle);
72
73 // Retrieves a set of ready handles from |wait_set_handle|. A handle is ready if
74 // at least of of the following is true:
75 // - The handle's signals are satisfied.
76 // - It becomes known that no signal for the handle will ever be satisfied.
77 // - The handle is closed.
78 //
79 // A wait set may have ready handles when it satisfies the
80 // |MOJO_HANDLE_SIGNAL_READABLE| signal. Since handles may be added and removed
81 // from a wait set concurrently, it is possible for a wait set to satisfy
82 // |MOJO_HANDLE_SIGNAL_READABLE|, but not have any ready handles when
83 // |MojoGetReadyHandle()| is called. These spurious wake-ups must be gracefully
84 // handled.
85 //
86 // |*count| on input, must contain the maximum number of ready handles to be
87 // returned. On output, it will contain the number of ready handles returned.
88 //
89 // |handles| must point to an array of size |*count| of |MojoHandle|. It will be
90 // populated with handles that are considered ready. The number of handles
91 // returned will be in |*count|.
92 //
93 // |results| must point to an array of size |*count| of |MojoResult|. It will be
94 // populated with the wait result of the corresponding handle in |*handles|.
95 // Care should be taken that if a handle is closed on another thread, the handle
96 // would be invalid, but the result may not be |MOJO_RESULT_CANCELLED|. See
97 // documentation for |MojoWait()| for possible results.
98 //
99 // |signals_state| (optional) if non-null, must point to an array of size
100 // |*count| of |MojoHandleSignalsState|. It will be populated with the signals
101 // state of the corresponding handle in |*handles|. See documentation for
102 // |MojoHandleSignalsState|.
103 //
104 // Mojo signals and satisfiability are logically 'level-triggered'. Therefore,
105 // if a signal continues to be satisfied and is not removed from the wait set,
106 // subsequent calls to |MojoGetReadyHandle()| will return the same handle.
107 //
108 // If multiple handles have their signals satisfied, the order in which handles
109 // are returned is undefined. The same handle, if not removed, may be returned
110 // in consecutive calls. Callers must not rely on any fairness and handles
111 // could be starved if not acted on.
112 //
113 // Returns:
114 // |MOJO_RESULT_OK| if ready handles are available.
115 // |MOJO_RESULT_INVALID_ARGUMENT| if |wait_set_handle| is not a valid wait
116 // set, if |*count| is 0, or if either |count|, |handles|, or |results| is
117 // null.
118 // |MOJO_RESULT_SHOULD_WAIT| if there are no ready handles.
119 MOJO_SYSTEM_EXPORT MojoResult MojoGetReadyHandles(
120 MojoHandle wait_set_handle,
121 uint32_t* count, // In/out.
122 MojoHandle* handles, // Out.
123 MojoResult* results, // Out.
124 struct MojoHandleSignalsState *signals_states); // Optional out.
125
126 #ifdef __cplusplus
127 } // extern "C"
128 #endif
129
130 #endif // MOJO_PUBLIC_C_SYSTEM_WAIT_SET_H_
OLDNEW
« no previous file with comments | « mojo/public/c/system/core.h ('k') | third_party/mojo/mojo_public.gyp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698