summaryrefslogtreecommitdiff
path: root/mojo/public/c
diff options
context:
space:
mode:
authorKen Rockot <rockot@chromium.org>2018-03-09 09:11:19 +0900
committerQijiang Fan <fqj@google.com>2020-06-05 08:43:40 +0900
commit50c604d33aff0624958d477c3d2a2db13577b1a6 (patch)
treec6ae501730885a7344c72455f17e0ef93c4fd837 /mojo/public/c
parent04b542d019f421b7b856125b33cd12f77592555b (diff)
downloadlibchrome-50c604d33aff0624958d477c3d2a2db13577b1a6.tar.gz
Mojo: Watchers -> Traps
Refactors the watcher APIs a bit to support some exensibility. Also renames them in the process because "trap" seems like a better analogy. Some remnants of the watcher concept are left intact to keep the CL size small. TBR=dcheng@chromium.org Bug: 819046 Change-Id: Ie469f715c32080824d99b3a4f85834c030cbd181 Reviewed-on: https://chromium-review.googlesource.com/952081 Reviewed-by: Ken Rockot <rockot@chromium.org> Reviewed-by: Daniel Cheng <dcheng@chromium.org> Reviewed-by: Jay Civelli <jcivelli@chromium.org> Commit-Queue: Ken Rockot <rockot@chromium.org> Cr-Commit-Position: refs/heads/master@{#541949} CrOS-Libchrome-Original-Commit: 13e55a33207c004ade4a43d3e177ed026d7a64bb
Diffstat (limited to 'mojo/public/c')
-rw-r--r--mojo/public/c/system/core.h2
-rw-r--r--mojo/public/c/system/functions.h2
-rw-r--r--mojo/public/c/system/thunks.cc62
-rw-r--r--mojo/public/c/system/thunks.h31
-rw-r--r--mojo/public/c/system/trap.h320
-rw-r--r--mojo/public/c/system/types.h50
-rw-r--r--mojo/public/c/system/watcher.h186
7 files changed, 380 insertions, 273 deletions
diff --git a/mojo/public/c/system/core.h b/mojo/public/c/system/core.h
index 03c0652a57..bc6ef8c646 100644
--- a/mojo/public/c/system/core.h
+++ b/mojo/public/c/system/core.h
@@ -16,7 +16,7 @@
#include "mojo/public/c/system/message_pipe.h"
#include "mojo/public/c/system/platform_handle.h"
#include "mojo/public/c/system/system_export.h"
+#include "mojo/public/c/system/trap.h"
#include "mojo/public/c/system/types.h"
-#include "mojo/public/c/system/watcher.h"
#endif // MOJO_PUBLIC_C_SYSTEM_CORE_H_
diff --git a/mojo/public/c/system/functions.h b/mojo/public/c/system/functions.h
index d0656c67fc..5ce0dabb34 100644
--- a/mojo/public/c/system/functions.h
+++ b/mojo/public/c/system/functions.h
@@ -42,7 +42,7 @@ MOJO_SYSTEM_EXPORT MojoTimeTicks MojoGetTimeTicksNow(void);
//
// Concurrent operations on |handle| may succeed (or fail as usual) if they
// happen before the close, be cancelled with result |MOJO_RESULT_CANCELLED| if
-// they properly overlap (this is likely the case with watchers), or fail with
+// they properly overlap (this is likely the case with traps), or fail with
// |MOJO_RESULT_INVALID_ARGUMENT| if they happen after.
MOJO_SYSTEM_EXPORT MojoResult MojoClose(MojoHandle handle);
diff --git a/mojo/public/c/system/thunks.cc b/mojo/public/c/system/thunks.cc
index 89cbf750a8..b3a0564463 100644
--- a/mojo/public/c/system/thunks.cc
+++ b/mojo/public/c/system/thunks.cc
@@ -138,34 +138,40 @@ MojoResult MojoUnmapBuffer(void* buffer) {
return g_thunks.UnmapBuffer(buffer);
}
-MojoResult MojoCreateWatcher(MojoWatcherCallback callback,
- MojoHandle* watcher_handle) {
- assert(g_thunks.CreateWatcher);
- return g_thunks.CreateWatcher(callback, watcher_handle);
-}
-
-MojoResult MojoWatch(MojoHandle watcher_handle,
- MojoHandle handle,
- MojoHandleSignals signals,
- MojoWatchCondition condition,
- uintptr_t context) {
- assert(g_thunks.Watch);
- return g_thunks.Watch(watcher_handle, handle, signals, condition, context);
-}
-
-MojoResult MojoCancelWatch(MojoHandle watcher_handle, uintptr_t context) {
- assert(g_thunks.CancelWatch);
- return g_thunks.CancelWatch(watcher_handle, context);
-}
-
-MojoResult MojoArmWatcher(MojoHandle watcher_handle,
- uint32_t* num_ready_contexts,
- uintptr_t* ready_contexts,
- MojoResult* ready_results,
- MojoHandleSignalsState* ready_signals_states) {
- assert(g_thunks.ArmWatcher);
- return g_thunks.ArmWatcher(watcher_handle, num_ready_contexts, ready_contexts,
- ready_results, ready_signals_states);
+MojoResult MojoCreateTrap(MojoTrapEventHandler handler,
+ const MojoCreateTrapOptions* options,
+ MojoHandle* trap_handle) {
+ assert(g_thunks.CreateTrap);
+ return g_thunks.CreateTrap(handler, options, trap_handle);
+}
+
+MojoResult MojoAddTrigger(MojoHandle trap_handle,
+ MojoHandle handle,
+ MojoHandleSignals signals,
+ MojoTriggerCondition condition,
+ uintptr_t context,
+ const MojoAddTriggerOptions* options) {
+ assert(g_thunks.AddTrigger);
+ return g_thunks.AddTrigger(trap_handle, handle, signals, condition, context,
+ options);
+}
+
+MojoResult MojoRemoveTrigger(MojoHandle trap_handle,
+ uintptr_t context,
+ const MojoRemoveTriggerOptions* options) {
+ assert(g_thunks.RemoveTrigger);
+ return g_thunks.RemoveTrigger(trap_handle, context, options);
+}
+
+MojoResult MojoArmTrap(MojoHandle trap_handle,
+ const MojoArmTrapOptions* options,
+ uint32_t* num_ready_triggers,
+ uintptr_t* ready_triggers,
+ MojoResult* ready_results,
+ MojoHandleSignalsState* ready_signals_states) {
+ assert(g_thunks.ArmTrap);
+ return g_thunks.ArmTrap(trap_handle, options, num_ready_triggers,
+ ready_triggers, ready_results, ready_signals_states);
}
MojoResult MojoFuseMessagePipes(MojoHandle handle0, MojoHandle handle1) {
diff --git a/mojo/public/c/system/thunks.h b/mojo/public/c/system/thunks.h
index e19d2f14c3..0564ea6025 100644
--- a/mojo/public/c/system/thunks.h
+++ b/mojo/public/c/system/thunks.h
@@ -72,19 +72,24 @@ struct MojoSystemThunks {
void** buffer,
MojoMapBufferFlags flags);
MojoResult (*UnmapBuffer)(void* buffer);
- MojoResult (*CreateWatcher)(MojoWatcherCallback callback,
- MojoHandle* watcher_handle);
- MojoResult (*Watch)(MojoHandle watcher_handle,
- MojoHandle handle,
- MojoHandleSignals signals,
- MojoWatchCondition condition,
- uintptr_t context);
- MojoResult (*CancelWatch)(MojoHandle watcher_handle, uintptr_t context);
- MojoResult (*ArmWatcher)(MojoHandle watcher_handle,
- uint32_t* num_ready_contexts,
- uintptr_t* ready_contexts,
- MojoResult* ready_results,
- MojoHandleSignalsState* ready_signals_states);
+ MojoResult (*CreateTrap)(MojoTrapEventHandler handler,
+ const struct MojoCreateTrapOptions* options,
+ MojoHandle* trap_handle);
+ MojoResult (*AddTrigger)(MojoHandle trap_handle,
+ MojoHandle handle,
+ MojoHandleSignals signals,
+ MojoTriggerCondition condition,
+ uintptr_t context,
+ const struct MojoAddTriggerOptions* options);
+ MojoResult (*RemoveTrigger)(MojoHandle trap_handle,
+ uintptr_t context,
+ const struct MojoRemoveTriggerOptions* options);
+ MojoResult (*ArmTrap)(MojoHandle trap_handle,
+ const struct MojoArmTrapOptions* options,
+ uint32_t* num_ready_triggers,
+ uintptr_t* ready_triggers,
+ MojoResult* ready_results,
+ MojoHandleSignalsState* ready_signals_states);
MojoResult (*FuseMessagePipes)(MojoHandle handle0, MojoHandle handle1);
MojoResult (*CreateMessage)(const struct MojoCreateMessageOptions* options,
MojoMessageHandle* message);
diff --git a/mojo/public/c/system/trap.h b/mojo/public/c/system/trap.h
new file mode 100644
index 0000000000..7c65af31fa
--- /dev/null
+++ b/mojo/public/c/system/trap.h
@@ -0,0 +1,320 @@
+// Copyright 2017 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#ifndef MOJO_PUBLIC_C_SYSTEM_TRAP_H_
+#define MOJO_PUBLIC_C_SYSTEM_TRAP_H_
+
+#include <stdint.h>
+
+#include "mojo/public/c/system/macros.h"
+#include "mojo/public/c/system/system_export.h"
+#include "mojo/public/c/system/types.h"
+
+// Flags passed to trap event handlers within |MojoTrapEvent|.
+typedef uint32_t MojoTrapEventFlags;
+
+#ifdef __cplusplus
+const MojoTrapEventFlags MOJO_TRAP_EVENT_FLAG_NONE = 0;
+const MojoTrapEventFlags MOJO_TRAP_EVENT_FLAG_WITHIN_API_CALL = 1 << 0;
+#else
+#define MOJO_TRAP_EVENT_FLAG_NONE ((MojoTrapEventFlags)0)
+#define MOJO_TRAP_EVENT_FLAG_WITHIN_API_CALL ((MojoTrapEventFlags)1 << 0)
+#endif
+
+// Structure passed to trap event handlers when invoked by a tripped trap.
+struct MOJO_ALIGNAS(8) MojoTrapEvent {
+ // The size of this structure, used for versioning.
+ uint32_t struct_size;
+
+ // May take on some combination of the following values:
+ //
+ // |MOJO_TRAP_EVENT_FLAG_NONE|: No flags.
+ //
+ // |MOJO_TRAP_EVENT_FLAG_WITHIN_API_CALL|: The trap was tripped within the
+ // extent of a user call to some Mojo API. This means that the event
+ // handler itself is re-entering user code. May happen, for example, if
+ // user code writes to an intra-process pipe and the receiving end trips
+ // a trap as a result. In that case the event handler executes within
+ // the extent of the |MojoWriteMessage()| call.
+ MojoTrapEventFlags flags;
+
+ // The context for the trigger which tripped the trap.
+ uintptr_t trigger_context;
+
+ // A result code indicating the cause of the event. May take on any of the
+ // following values:
+ //
+ // |MOJO_RESULT_OK|: The trigger's conditions were met.
+ // |MOJO_RESULT_FAILED_PRECONDITION|: The trigger's observed handle has
+ // changed state in such a way that the trigger's conditions can never
+ // be met again.
+ // |MOJO_RESULT_CANCELLED|: The trigger has been removed and will never
+ // cause another event to fire. This is always the last event fired by
+ // a trigger and it will fire when: the trigger is explicitly removed
+ // with |MojoRemoteTrigger()|, the trigger's owning trap handle is
+ // closed, or the handle observed by the trigger is closed.
+ //
+ // Unlike the other result types above |MOJO_RESULT_CANCELLED| can
+ // fire even when the trap is disarmed.
+ MojoResult result;
+
+ // The last known signalling state of the trigger's observed handle at the
+ // time the trap was tripped.
+ struct MojoHandleSignalsState signals_state;
+};
+
+// Value given to |MojoAddTrigger| to configure what condition should cause it
+// to trip its trap. May be one of the following values:
+//
+// |MOJO_TRIGGER_CONDITION_SIGNALS_UNSATISFIED| - A trigger added with this
+// condition will trip its trap when any of its observed signals
+// transition from being satisfied to being unsatisfied.
+// |MOJO_TRIGGER_CONDITION_SIGNALS_SATISFIED| - A triger added with this
+// condition will trip its trap when any of its observed signals
+// transition from being unsatisfied to being satisfied, or when none of
+// the observed signals can ever be satisfied again.
+typedef uint32_t MojoTriggerCondition;
+
+#ifdef __cplusplus
+const MojoTriggerCondition MOJO_TRIGGER_CONDITION_SIGNALS_UNSATISFIED = 0;
+const MojoTriggerCondition MOJO_TRIGGER_CONDITION_SIGNALS_SATISFIED = 1;
+#else
+#define MOJO_TRIGGER_CONDITION_SIGNALS_UNSATISFIED ((MojoTriggerCondition)0)
+#define MOJO_TRIGGER_CONDITION_SIGNALS_SATISFIED ((MojoTriggerCondition)1)
+#endif
+
+// Flags passed to |MojoCreateTrap()| via |MojoCreateTrapOptions|.
+typedef uint32_t MojoCreateTrapFlags;
+
+#ifdef __cplusplus
+const MojoCreateTrapFlags MOJO_CREATE_TRAP_FLAG_NONE = 0;
+#else
+#define MOJO_CREATE_TRAP_FLAG_NONE ((MojoCreateTrapFlags)0)
+#endif
+
+// Options passed to |MojoCreateTrap()|.
+struct MOJO_ALIGNAS(8) MojoCreateTrapOptions {
+ // The size of this structure, used for versioning.
+ uint32_t struct_size;
+
+ // Flags. Currently unused.
+ MojoCreateTrapFlags flags;
+};
+
+// Flags passed to |MojoAddTrigger()| via |MojoAddTriggerOptions|.
+typedef uint32_t MojoAddTriggerFlags;
+
+#ifdef __cplusplus
+const MojoAddTriggerFlags MOJO_ADD_TRIGGER_FLAG_NONE = 0;
+#else
+#define MOJO_ADD_TRIGGER_FLAG_NONE ((MojoAddTriggerFlags)0)
+#endif
+
+// Options passed to |MojoAddTrigger()|.
+struct MOJO_ALIGNAS(8) MojoAddTriggerOptions {
+ // The size of this structure, used for versioning.
+ uint32_t struct_size;
+
+ // Flags. Currently unused.
+ MojoAddTriggerFlags flags;
+};
+
+// Flags passed to |MojoRemoveTrigger()| via |MojoRemoveTriggerOptions|.
+typedef uint32_t MojoRemoveTriggerFlags;
+
+#ifdef __cplusplus
+const MojoRemoveTriggerFlags MOJO_REMOVE_TRIGGER_FLAG_NONE = 0;
+#else
+#define MOJO_REMOVE_TRIGGER_FLAG_NONE ((MojoRemoveTriggerFlags)0)
+#endif
+
+// Options passed to |MojoRemoveTrigger()|.
+struct MOJO_ALIGNAS(8) MojoRemoveTriggerOptions {
+ // The size of this structure, used for versioning.
+ uint32_t struct_size;
+
+ // Flags. Currently unused.
+ MojoRemoveTriggerFlags flags;
+};
+
+// Flags passed to |MojoArmTrap()| via |MojoArmTrapOptions|.
+typedef uint32_t MojoArmTrapFlags;
+
+#ifdef __cplusplus
+const MojoArmTrapFlags MOJO_ARM_TRAP_FLAG_NONE = 0;
+#else
+#define MOJO_ARM_TRAP_FLAG_NONE ((MojoArmTrapFlags)0)
+#endif
+
+// Options passed to |MojoArmTrap()|.
+struct MOJO_ALIGNAS(8) MojoArmTrapOptions {
+ // The size of this structure, used for versioning.
+ uint32_t struct_size;
+
+ // Flags. Currently unused.
+ MojoArmTrapFlags flags;
+};
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+// A user-provided callback to handle trap events. Passed to |MojoCreateTrap()|.
+typedef void (*MojoTrapEventHandler)(const struct MojoTrapEvent* event);
+
+// Creates a new trap which can be used to detect signal changes on a handle.
+// Traps execute arbitrary user code when tripped.
+//
+// Traps can trip only while armed**, and new traps are created in a disarmed
+// state. Traps may be armed using |MojoArmTrap()|.
+//
+// Arming a trap is only possible when the trap has one or more triggers
+// attached to it. Triggers can be added or removed using |MojoAddTrigger()| and
+// |MojoRemoveTrigger()|.
+//
+// If a trap is tripped by any of its triggers, it is disarmed immediately and
+// the traps |MojoTrapEventHandler| is invoked once for every relevant trigger.
+//
+// |options| may be null.
+//
+// ** An unarmed trap will still fire an event when a trigger is removed. This
+// event will always convey the result |MOJO_RESULT_CANCELLED|.
+//
+// Parameters:
+// |handler|: The |MojoTrapEventHandler| to invoke any time this trap is
+// tripped. Note that this may be called from any arbitrary thread.
+// |trap_handle|: The address at which to store the MojoHandle corresponding
+// to the new trap if successfully created.
+//
+// Returns:
+// |MOJO_RESULT_OK| if the trap has been successfully created.
+// |MOJO_RESULT_RESOURCE_EXHAUSTED| if a handle could not be allocated for
+// this trap.
+MOJO_SYSTEM_EXPORT MojoResult
+MojoCreateTrap(MojoTrapEventHandler handler,
+ const struct MojoCreateTrapOptions* options,
+ MojoHandle* trap_handle);
+
+// Adds a trigger to a trap. This configures the trap to invoke its event
+// handler if the specified conditions are met (or can no longer be met) while
+// the trap is armed.
+//
+// Note that event handler invocations for a given trigger are mutually
+// exclusive in execution: the handler will never be entered for a trigger while
+// another thread is executing it for the same trigger. Similarly, event
+// handlers are never re-entered. If an event handler changes the state of the
+// system such that another event would fire, that event is deferred until the
+// first handler returns.
+//
+// Parameters:
+// |trap_handle|: The trap to which this trigger is to be added.
+// |handle|: The handle whose signals this trigger will observe. Must be a
+// message pipe or data pipe handle.
+// |signals|: The specific signal(s) this trigger will observe on |handle|.
+// |condition|: The signaling condition this trigger will observe. i.e.
+// whether to trip the trap when |signals| become satisfied or when they
+// become unsatisfied.
+// |context|: An arbitrary context value to be passed to the trap's event
+// handler when this trigger was responsible for tripping the trap. See
+// the |trigger_context| field in |MojoTrapEvent|. This value must be
+// unique among all triggers on the trap.
+//
+// |options| may be null.
+//
+// Returns:
+// |MOJO_RESULT_OK| if the handle is now being observed by the trigger.
+// |MOJO_RESULT_INVALID_ARGUMENT| if |trap_handle| is not a trap handle,
+// |handle| is not a valid message pipe or data pipe handle, or |signals|
+// or |condition| are an invalid value.
+// |MOJO_RESULT_ALREADY_EXISTS| if the trap already has a trigger associated
+// with |context| or |handle|.
+MOJO_SYSTEM_EXPORT MojoResult
+MojoAddTrigger(MojoHandle trap_handle,
+ MojoHandle handle,
+ MojoHandleSignals signals,
+ MojoTriggerCondition condition,
+ uintptr_t context,
+ const struct MojoAddTriggerOptions* options);
+
+// Removes a trigger from a trap.
+//
+// This ensures that the trigger is removed as soon as possible. Removal may
+// block an arbitrarily long time if the trap is already executing its handler.
+//
+// When removal is complete, the trap's handler is invoked one final time for
+// time for |context|, with the result |MOJO_RESULT_CANCELLED|.
+//
+// The same behavior can be elicted by either closing the watched handle
+// associated with this trigger, or by closing |trap_handle| itself.
+//
+// Parameters:
+// |trap_handle|: The handle of the trap from which to remove a trigger.
+// |context|: The context of the trigger to be removed.
+//
+// Returns:
+// |MOJO_RESULT_OK| if the trigger has been removed.
+// |MOJO_RESULT_INVALID_ARGUMENT| if |trap_handle| is not a trap handle.
+// |MOJO_RESULT_NOT_FOUND| if there is no trigger registered on this trap for
+// the given value of |context|.
+MOJO_SYSTEM_EXPORT MojoResult
+MojoRemoveTrigger(MojoHandle trap_handle,
+ uintptr_t context,
+ const struct MojoRemoveTriggerOptions* options);
+
+// Arms a trap, allowing it to invoke its event handler the next time any of its
+// triggers' conditions are met.
+//
+// Parameters:
+// |trap_handle|: The handle of the trap to be armed.
+// |num_ready_triggers|: An address pointing to the number of elements
+// available for storage in the following output buffer parameters.
+// Optional and only used when |MOJO_RESULT_FAILED_PRECONDITION| is
+// returned. See below.
+// |ready_triggers|: An output buffer for contexts of triggers that would have
+// tripped the trap immediately if it were armed. Optional and used only
+// when |MOJO_RESULT_FAILED_PRECONDITION| is returned. See below.
+// |ready_results|: An output buffer for |MojoResult| values corresponding to
+// each trigger in |ready_triggers|. Optional and only used when
+// |MOJO_RESULT_FAILED_PRECONDITION| is returned. See below.
+// |ready_signals_states|: An output buffer for |MojoHandleSignalsState|
+// structures corresponding to the handle observed by each respective
+// trigger in |ready_triggers|. Optional and only used when
+// |MOJO_RESULT_FAILED_PRECONDITION| is returned. See below.
+//
+// Returns:
+// |MOJO_RESULT_OK| if the trap has been successfully armed. All arguments
+// other than |trap_handle| are ignored in this case.
+// |MOJO_RESULT_NOT_FOUND| if the trap does not have any triggers. All
+// arguments other than |trap_handle| are ignored.
+// |MOJO_RESULT_INVALID_ARGUMENT| if |trap_handle| is not a valid trap handle,
+// or if |num_ready_triggers| is non-null and any of the output buffer
+// paramters is null.
+// |MOJO_RESULT_FAILED_PRECONDITION| if one or more triggers would have
+// tripped the trap immediately upon arming. If |num_handles| is non-null,
+// this assumes there is enough space for |*num_handles| entries in each
+// of the subsequent output buffer parameters.
+//
+// At most |*num_handles| entries are populated in the output buffers,
+// with each entry corresponding to one of the triggers which would have
+// tripped the trap. The actual number of entries populated is written to
+// |*num_handles| before returning.
+//
+// If there are more ready triggers than available provided storage, the
+// subset presented to thecaller is arbitrary. The runtime makes an effort
+// to circulate triggers returned by consecutive failed |MojoArmTrap()|
+// calls so that callers may avoid handle starvation when observing a
+// large number of active handles with a single trap.
+MOJO_SYSTEM_EXPORT MojoResult
+MojoArmTrap(MojoHandle trap_handle,
+ const struct MojoArmTrapOptions* options,
+ uint32_t* num_ready_triggers,
+ uintptr_t* ready_triggers,
+ MojoResult* ready_results,
+ struct MojoHandleSignalsState* ready_signals_states);
+
+#ifdef __cplusplus
+} // extern "C"
+#endif
+
+#endif // MOJO_PUBLIC_C_SYSTEM_TRAP_H_
diff --git a/mojo/public/c/system/types.h b/mojo/public/c/system/types.h
index 84e35b74ac..220f90f1c2 100644
--- a/mojo/public/c/system/types.h
+++ b/mojo/public/c/system/types.h
@@ -77,7 +77,7 @@ const MojoHandle MOJO_HANDLE_INVALID = 0;
// the resource being invalidated.
// |MOJO_RESULT_SHOULD_WAIT| - The request cannot currently be completed
// (e.g., if the data requested is not yet available). The caller should
-// wait for it to be feasible using a watcher.
+// wait for it to be feasible using a trap.
//
// The codes from |MOJO_RESULT_OK| to |MOJO_RESULT_DATA_LOSS| come from
// Google3's canonical error codes.
@@ -191,49 +191,6 @@ struct MOJO_ALIGNAS(4) MojoHandleSignalsState {
MOJO_STATIC_ASSERT(sizeof(MojoHandleSignalsState) == 8,
"MojoHandleSignalsState has wrong size");
-// |MojoWatcherNotificationFlags|: Passed to a callback invoked by a watcher
-// when some observed signals are raised or a watched handle is closed. May take
-// on any combination of the following values:
-//
-// |MOJO_WATCHER_NOTIFICATION_FLAG_FROM_SYSTEM| - The callback is being
-// invoked as a result of a system-level event rather than a direct API
-// call from user code. This may be used as an indication that user code
-// is safe to call without fear of reentry.
-
-typedef uint32_t MojoWatcherNotificationFlags;
-
-#ifdef __cplusplus
-const MojoWatcherNotificationFlags MOJO_WATCHER_NOTIFICATION_FLAG_NONE = 0;
-const MojoWatcherNotificationFlags MOJO_WATCHER_NOTIFICATION_FLAG_FROM_SYSTEM =
- 1 << 0;
-#else
-#define MOJO_WATCHER_NOTIFICATION_FLAG_NONE ((MojoWatcherNotificationFlags)0)
-#define MOJO_WATCHER_NOTIFICATION_FLAG_FROM_SYSTEM \
- ((MojoWatcherNotificationFlags)1 << 0);
-#endif
-
-// |MojoWatchCondition|: Given to |MojoWatch()| to indicate whether the
-// watched signals should trigger a notification when becoming satisfied or
-// becoming not-satisfied.
-//
-// |MOJO_WATCH_CONDITION_NOT_SATISFIED| - A watch added with this setting will
-// trigger a notification when any of the watched signals transition from
-// being not-satisfied to being satisfied.
-// |MOJO_WATCH_CONDITION_SATISFIED| - A watch added with this setting will
-// trigger a notification when any of the watched signals transition from
-// being satisfied to being not-satisfied, or when none of the watched
-// signals can ever be satisfied again.
-
-typedef uint32_t MojoWatchCondition;
-
-#ifdef __cplusplus
-const MojoWatchCondition MOJO_WATCH_CONDITION_NOT_SATISFIED = 0;
-const MojoWatchCondition MOJO_WATCH_CONDITION_SATISFIED = 1;
-#else
-#define MOJO_WATCH_CONDITION_NOT_SATISFIED ((MojoWatchCondition)0)
-#define MOJO_WATCH_CONDITION_SATISFIED ((MojoWatchCondition)1)
-#endif
-
// |MojoPropertyType|: Property types that can be passed to |MojoGetProperty()|
// to retrieve system properties. May take the following values:
// |MOJO_PROPERTY_TYPE_SYNC_CALL_ALLOWED| - Whether making synchronous calls
@@ -248,4 +205,9 @@ const MojoPropertyType MOJO_PROPERTY_TYPE_SYNC_CALL_ALLOWED = 0;
#define MOJO_PROPERTY_TYPE_SYNC_CALL_ALLOWED ((MojoPropertyType)0)
#endif
+// TODO(https://crbug.com/819046): Remove these aliases.
+#define MOJO_WATCH_CONDITION_SATISFIED MOJO_TRIGGER_CONDITION_SIGNALS_SATISFIED
+#define MOJO_WATCH_CONDITION_NOT_SATISFIED \
+ MOJO_TRIGGER_CONDITION_SIGNALS_UNSATISFIED
+
#endif // MOJO_PUBLIC_C_SYSTEM_TYPES_H_
diff --git a/mojo/public/c/system/watcher.h b/mojo/public/c/system/watcher.h
deleted file mode 100644
index 10b9168810..0000000000
--- a/mojo/public/c/system/watcher.h
+++ /dev/null
@@ -1,186 +0,0 @@
-// Copyright 2017 The Chromium Authors. All rights reserved.
-// Use of this source code is governed by a BSD-style license that can be
-// found in the LICENSE file.
-
-#ifndef MOJO_PUBLIC_C_SYSTEM_WATCHER_H_
-#define MOJO_PUBLIC_C_SYSTEM_WATCHER_H_
-
-#include <stdint.h>
-
-#include "mojo/public/c/system/system_export.h"
-#include "mojo/public/c/system/types.h"
-
-#ifdef __cplusplus
-extern "C" {
-#endif
-
-// A callback used to notify watchers about events on their watched handles.
-//
-// See documentation for |MojoWatcherNotificationFlags| for details regarding
-// the possible values of |flags|.
-//
-// See documentation for |MojoWatch()| for details regarding the other arguments
-// this callback receives when called.
-typedef void (*MojoWatcherCallback)(uintptr_t context,
- MojoResult result,
- struct MojoHandleSignalsState signals_state,
- MojoWatcherNotificationFlags flags);
-
-// Creates a new watcher.
-//
-// Watchers are used to trigger arbitrary code execution when one or more
-// handles change state to meet certain conditions.
-//
-// A newly registered watcher is initially disarmed and may be armed using
-// |MojoArmWatcher()|. A watcher is also always disarmed immediately before any
-// invocation of one or more notification callbacks in response to a single
-// handle's state changing in some relevant way.
-//
-// Parameters:
-// |callback|: The |MojoWatcherCallback| to invoke any time the watcher is
-// notified of an event. See |MojoWatch()| for details regarding arguments
-// passed to the callback. Note that this may be called from any arbitrary
-// thread.
-// |watcher_handle|: The address at which to store the MojoHandle
-// corresponding to the new watcher if successfully created.
-//
-// Returns:
-// |MOJO_RESULT_OK| if the watcher has been successfully created.
-// |MOJO_RESULT_RESOURCE_EXHAUSTED| if a handle could not be allocated for
-// this watcher.
-MOJO_SYSTEM_EXPORT MojoResult MojoCreateWatcher(MojoWatcherCallback callback,
- MojoHandle* watcher_handle);
-
-// Adds a watch to a watcher. This allows the watcher to fire notifications
-// regarding state changes on the handle corresponding to the arguments given.
-//
-// Note that notifications for a given watch context are guaranteed to be
-// mutually exclusive in execution: the callback will never be entered for a
-// given context while another invocation of the callback is still executing for
-// the same context. As a result it is generally a good idea to ensure that
-// callbacks do as little work as necessary in order to process the
-// notification.
-//
-// Parameters:
-// |watcher_handle|: The watcher to which |handle| is to be added.
-// |handle|: The handle to add to the watcher.
-// |signals|: The signals to watch for on |handle|.
-// |level|: The level to watch for on |signals|.
-// |context|: An arbitrary context value given to any invocation of the
-// watcher's callback when invoked as a result of some state change
-// relevant to this combination of |handle| and |signals|. Must be
-// unique within any given watcher.
-//
-// Callback parameters (see |MojoWatcherNotificationCallback| above):
-// When the watcher invokes its callback as a result of some notification
-// relevant to this watch operation, |context| receives the value given here
-// and |signals_state| receives the last known signals state of this handle.
-//
-// |result| is one of the following:
-// |MOJO_RESULT_OK| if at least one of the watched signals is satisfied. The
-// watcher must be armed for this notification to fire.
-// |MOJO_RESULT_FAILED_PRECONDITION| if all of the watched signals are
-// permanently unsatisfiable. The watcher must be armed for this
-// notification to fire.
-// |MOJO_RESULT_CANCELLED| if the watch has been cancelled. The may occur if
-// the watcher has been closed, the watched handle has been closed, or
-// the watch for |context| has been explicitly cancelled. This is always
-// the last result received for any given context, and it is guaranteed
-// to be received exactly once per watch, regardless of how the watch
-// was cancelled.
-//
-// Returns:
-// |MOJO_RESULT_OK| if the handle is now being watched by the watcher.
-// |MOJO_RESULT_INVALID_ARGUMENT| if |watcher_handle| is not a watcher handle,
-// |handle| is not a valid message pipe or data pipe handle.
-// |MOJO_RESULT_ALREADY_EXISTS| if the watcher already has a watch registered
-// for the given value of |context| or for the given |handle|.
-MOJO_SYSTEM_EXPORT MojoResult MojoWatch(MojoHandle watcher_handle,
- MojoHandle handle,
- MojoHandleSignals signals,
- MojoWatchCondition condition,
- uintptr_t context);
-
-// Removes a watch from a watcher.
-//
-// This ensures that the watch is cancelled as soon as possible. Cancellation
-// may be deferred (or may even block) an aritrarily long time if the watch is
-// already dispatching one or more notifications.
-//
-// When cancellation is complete, the watcher's callback is invoked one final
-// time for |context|, with the result |MOJO_RESULT_CANCELLED|.
-//
-// The same behavior can be elicted by either closing the watched handle
-// associated with this context, or by closing |watcher_handle| itself. In the
-// lastter case, all registered contexts on the watcher are implicitly cancelled
-// in a similar fashion.
-//
-// Parameters:
-// |watcher_handle|: The handle of the watcher from which to remove a watch.
-// |context|: The context of the watch to be removed.
-//
-// Returns:
-// |MOJO_RESULT_OK| if the watch has been cancelled.
-// |MOJO_RESULT_INVALID_ARGUMENT| if |watcher_handle| is not a watcher handle.
-// |MOJO_RESULT_NOT_FOUND| if there is no watch registered on this watcher for
-// the given value of |context|.
-MOJO_SYSTEM_EXPORT MojoResult MojoCancelWatch(MojoHandle watcher_handle,
- uintptr_t context);
-
-// Arms a watcher, enabling a single future event on one of the watched handles
-// to trigger a single notification for each relevant watch context associated
-// with that handle.
-//
-// Parameters:
-// |watcher_handle|: The handle of the watcher.
-// |num_ready_contexts|: An address pointing to the number of elements
-// available for storage in the remaining output buffers. Optional and
-// only used on failure. See |MOJO_RESULT_FAILED_PRECONDITION| below for
-// more details.
-// |ready_contexts|: An output buffer for contexts corresponding to the
-// watches which would have notified if the watcher were armed. Optional
-// and only uesd on failure. See |MOJO_RESULT_FAILED_PRECONDITION| below
-// for more details.
-// |ready_results|: An output buffer for MojoResult values corresponding to
-// each context in |ready_contexts|. Optional and only used on failure.
-// See |MOJO_RESULT_FAILED_PRECONDITION| below for more details.
-// |ready_signals_states|: An output buffer for |MojoHandleSignalsState|
-// structures corresponding to each context in |ready_contexts|. Optional
-// and only used on failure. See |MOJO_RESULT_FAILED_PRECONDITION| below
-// for more details.
-//
-// Returns:
-// |MOJO_RESULT_OK| if the watcher has been successfully armed. All arguments
-// other than |watcher_handle| are ignored in this case.
-// |MOJO_RESULT_NOT_FOUND| if the watcher does not have any registered watch
-// contexts. All arguments other than |watcher_handle| are ignored in this
-// case.
-// |MOJO_RESULT_INVALID_ARGUMENT| if |watcher_handle| is not a valid watcher
-// handle, or if |num_ready_contexts| is non-null but any of the output
-// buffer paramters is null.
-// |MOJO_RESULT_FAILED_PRECONDITION| if one or more watches would have
-// notified immediately upon arming the watcher. If |num_handles| is
-// non-null, this assumes there is enough space for |*num_handles| entries
-// in each of the subsequent output buffer arguments.
-//
-// At most that many entries are placed in the output buffers,
-// corresponding to the watches which would have signalled if the watcher
-// had been armed successfully. The actual number of entries placed in the
-// output buffers is written to |*num_ready_contexts| before returning.
-//
-// If more than (input) |*num_ready_contexts| watch contexts were ready to
-// notify, the subset presented in output buffers is arbitrary, but the
-// implementation makes a best effort to circulate the outputs across
-// consecutive calls so that callers may reliably avoid handle starvation.
-MOJO_SYSTEM_EXPORT MojoResult
-MojoArmWatcher(MojoHandle watcher_handle,
- uint32_t* num_ready_contexts,
- uintptr_t* ready_contexts,
- MojoResult* ready_results,
- struct MojoHandleSignalsState* ready_signals_states);
-
-#ifdef __cplusplus
-} // extern "C"
-#endif
-
-#endif // MOJO_PUBLIC_C_SYSTEM_WATCHER_H_