diff options
author | viettrungluu@chromium.org <viettrungluu@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2013-09-28 00:30:04 +0000 |
---|---|---|
committer | viettrungluu@chromium.org <viettrungluu@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2013-09-28 00:30:04 +0000 |
commit | 3d58663b00b219889b298b233e0c0e0f80596ed7 (patch) | |
tree | 9a4bdf0e0f48f1af7a083924c2711af9cc7310d1 /mojo/system/waiter.h | |
parent | 82ce871c06a72ffb38f3ddcac1090a2ceed266fb (diff) | |
download | chromium_src-3d58663b00b219889b298b233e0c0e0f80596ed7.zip chromium_src-3d58663b00b219889b298b233e0c0e0f80596ed7.tar.gz chromium_src-3d58663b00b219889b298b233e0c0e0f80596ed7.tar.bz2 |
Initial in-process implementation of some Mojo primitives.
This has an initial in-process implementation of the most basic Mojo primitives:
- MojoClose()
- MojoWait()
- MojoWaitMany()
- MojoCreateMessagePipe()
- MojoWriteMessage()
- MojoReadMessage()
R=darin@chromium.org
Committed: https://src.chromium.org/viewvc/chrome?view=rev&revision=225801
Review URL: https://codereview.chromium.org/23621056
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@225821 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'mojo/system/waiter.h')
-rw-r--r-- | mojo/system/waiter.h | 57 |
1 files changed, 57 insertions, 0 deletions
diff --git a/mojo/system/waiter.h b/mojo/system/waiter.h new file mode 100644 index 0000000..bdd33fc --- /dev/null +++ b/mojo/system/waiter.h @@ -0,0 +1,57 @@ +// Copyright 2013 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_SYSTEM_WAITER_H_ +#define MOJO_SYSTEM_WAITER_H_ + +#include "base/basictypes.h" +#include "base/synchronization/condition_variable.h" +#include "base/synchronization/lock.h" +#include "mojo/public/system/core.h" + +namespace mojo { +namespace system { + +// IMPORTANT (all-caps gets your attention, right?): |Waiter| methods are called +// under other locks, in particular, |Dispatcher::lock_|s, so |Waiter| methods +// must never call out to other objects (in particular, |Dispatcher|s). This +// class is thread-safe. +class Waiter { + public: + Waiter(); + ~Waiter(); + + // A |Waiter| can be used multiple times; |Init()| should be called before + // each time it's used. + void Init(); + + // Waits until a suitable |Awake()| is called. + // Returns: + // - The |wake_result| passed to |Dispatcher::AddWaiter()| if it was woken up + // by that dispatcher for the reason specified by |flags| (in the call to + // |AddWaiter()|). + // - |MOJO_RESULT_CANCELLED| if a handle (on which |MojoWait()| was called) + // was closed; and + // - |MOJO_RESULT_FAILED_PRECONDITION| if the reasons for being awoken given + // by |flags| cannot (or can no longer) be satisfied (e.g., if the other + // end of a pipe is closed). + MojoResult Wait(MojoDeadline deadline); + + // Wake the waiter up with the given result (or no-op if it's been woken up + // already). + void Awake(MojoResult wait_result); + + private: + base::ConditionVariable cv_; // Associated to |lock_|. + base::Lock lock_; // Protects the following members. + bool awoken_; + MojoResult wait_result_; + + DISALLOW_COPY_AND_ASSIGN(Waiter); +}; + +} // namespace system +} // namespace mojo + +#endif // MOJO_SYSTEM_WAITER_H_ |