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

Side by Side Diff: mojo/system/waiter.h

Issue 23621056: Initial in-process implementation of some Mojo primitives. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: C++ wrappers Created 7 years, 2 months 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 | Annotate | Revision Log
OLDNEW
(Empty)
1 // Copyright 2013 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 #ifndef MOJO_SYSTEM_WAITER_H_
6 #define MOJO_SYSTEM_WAITER_H_
7
8 #include "base/basictypes.h"
9 #include "base/synchronization/condition_variable.h"
10 #include "base/synchronization/lock.h"
11 #include "mojo/public/system/core.h"
12
13 namespace mojo {
14 namespace system {
15
16 // IMPORTANT (all-caps gets your attention, right?): |Waiter| methods are called
17 // under other locks, in particular, |Dispatcher::lock_|s, so |Waiter| methods
18 // must never call out to other objects (in particular, |Dispatcher|s). This
19 // class is thread-safe.
20 class Waiter {
21 public:
22 Waiter();
23 ~Waiter();
24
25 // A |Waiter| can be used multiple times; |Init()| should be called before
26 // each time it's used.
27 void Init();
28
29 // Waits until a suitable |Awake()| is called.
30 // Returns:
31 // - The |wake_result| passed to |Dispatcher::AddWaiter()| if it was woken up
32 // by that dispatcher for the reason specified by |flags| (in the call to
33 // |AddWaiter()|).
34 // - |MOJO_RESULT_CANCELLED| if a handle (on which |MojoWait()| was called)
35 // was closed; and
36 // - |MOJO_RESULT_FAILED_PRECONDITION| if the reasons for being awoken given
37 // by |flags| cannot (or can no longer) be satisfied (e.g., if the other
38 // end of a pipe is closed).
39 MojoResult Wait(MojoDeadline deadline);
40
41 // Wake the waiter up with the given result (or no-op if it's been woken up
42 // already).
43 void Awake(MojoResult wait_result);
44
45 private:
46 base::ConditionVariable cv_; // Associated to |lock_|.
47 base::Lock lock_; // Protects the following members.
48 bool awoken_;
49 MojoResult wait_result_;
50
51 DISALLOW_COPY_AND_ASSIGN(Waiter);
52 };
53
54 } // namespace system
55 } // namespace mojo
56
57 #endif // MOJO_SYSTEM_WAITER_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698