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

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

Issue 2075353002: Plumb the handle signals state out of Waiter::Wait(). (Closed) Base URL: https://github.com/domokit/mojo.git@work795_wait_set_4.3-x-work794_wait_set_4.2
Patch Set: Created 4 years, 6 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
OLDNEW
1 // Copyright 2013 The Chromium Authors. All rights reserved. 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 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #ifndef MOJO_EDK_SYSTEM_WAITER_H_ 5 #ifndef MOJO_EDK_SYSTEM_WAITER_H_
6 #define MOJO_EDK_SYSTEM_WAITER_H_ 6 #define MOJO_EDK_SYSTEM_WAITER_H_
7 7
8 #include <stdint.h> 8 #include <stdint.h>
9 9
10 #include "mojo/edk/system/awakable.h" 10 #include "mojo/edk/system/awakable.h"
(...skipping 16 matching lines...) Expand all
27 Waiter(); 27 Waiter();
28 ~Waiter() override; 28 ~Waiter() override;
29 29
30 // A |Waiter| can be used multiple times; |Init()| should be called before 30 // A |Waiter| can be used multiple times; |Init()| should be called before
31 // each time it's used. 31 // each time it's used.
32 void Init() MOJO_NOT_THREAD_SAFE; 32 void Init() MOJO_NOT_THREAD_SAFE;
33 33
34 // Waits until a suitable |Awake()| is called. (|context| may be null, in 34 // Waits until a suitable |Awake()| is called. (|context| may be null, in
35 // which case, obviously no context is ever returned.) 35 // which case, obviously no context is ever returned.)
36 // Returns: 36 // Returns:
37 // - The result given to the first call to |Awake()| (possibly before this 37 // - |MOJO_RESULT_OK| if |Awake()| was called with |AwakeReason::SATISFIED|;
38 // call to |Wait()|); in this case, |*context| is set to the value passed 38 // - |MOJO_RESULT_CANCELLED| if |Awake()| was called with
39 // to that call to |Awake()|. 39 // |AwakeReason::CANCELLED|;
40 // - |MOJO_RESULT_DEADLINE_EXCEEDED| if the deadline was exceeded; in this 40 // - |MOJO_RESULT_FAILED_PRECONDITION| if |Awake()| was called with
41 // case |*context| is not modified. 41 // |AwakeReason::UNSATISFIABLE|; or
42 // - |MOJO_RESULT_DEADLINE_EXCEEDED| if the deadline was exceeded.
42 // 43 //
43 // Usually, the context passed to |Awake()| will be the value passed to 44 // In all the cases except |MOJO_RESULT_DEADLINE_EXCEEDED|, the context and
44 // |Dispatcher::AddAwakable()|, which is usually the index to the array of 45 // signals state passed to |Awake()| be made available via |*context| and
45 // handles passed to |MojoWaitMany()| (or 0 for |MojoWait()|). 46 // |*signals_state|, respectively (unless the respective pointer is null).
46 // 47 MojoResult Wait(MojoDeadline deadline,
47 // Typical |Awake()| results are: 48 uint64_t* context,
48 // - |MOJO_RESULT_OK| if one of the flags passed to 49 HandleSignalsState* signals_state);
49 // |MojoWait()|/|MojoWaitMany()| (hence |Dispatcher::AddAwakable()|) was
50 // satisfied;
51 // - |MOJO_RESULT_CANCELLED| if a handle (on which
52 // |MojoWait()|/|MojoWaitMany()| was called) was closed (hence the
53 // dispatcher closed); and
54 // - |MOJO_RESULT_FAILED_PRECONDITION| if one of the set of flags passed to
55 // |MojoWait()|/|MojoWaitMany()| cannot or can no longer be satisfied by
56 // the corresponding handle (e.g., if the other end of a message or data
57 // pipe is closed).
58 MojoResult Wait(MojoDeadline deadline, uint64_t* context);
59 50
60 // |Awakable| implementation: 51 // |Awakable| implementation:
61 bool Awake(uint64_t context, 52 bool Awake(uint64_t context,
62 AwakeReason reason, 53 AwakeReason reason,
63 const HandleSignalsState& signals_state) override; 54 const HandleSignalsState& signals_state) override;
64 55
65 private: 56 private:
66 util::CondVar cv_; // Associated to |mutex_|. 57 util::CondVar cv_; // Associated to |mutex_|.
67 util::Mutex mutex_; 58 util::Mutex mutex_;
68 #ifndef NDEBUG 59 #ifndef NDEBUG
69 bool initialized_ MOJO_GUARDED_BY(mutex_); 60 bool initialized_ MOJO_GUARDED_BY(mutex_);
70 #endif 61 #endif
71 bool awoken_ MOJO_GUARDED_BY(mutex_); 62 bool awoken_ MOJO_GUARDED_BY(mutex_);
72 MojoResult awake_result_ MOJO_GUARDED_BY(mutex_); 63 AwakeReason awake_reason_ MOJO_GUARDED_BY(mutex_);
64 HandleSignalsState signals_state_ MOJO_GUARDED_BY(mutex_);
73 uint64_t awake_context_ MOJO_GUARDED_BY(mutex_); 65 uint64_t awake_context_ MOJO_GUARDED_BY(mutex_);
74 66
75 MOJO_DISALLOW_COPY_AND_ASSIGN(Waiter); 67 MOJO_DISALLOW_COPY_AND_ASSIGN(Waiter);
76 }; 68 };
77 69
78 } // namespace system 70 } // namespace system
79 } // namespace mojo 71 } // namespace mojo
80 72
81 #endif // MOJO_EDK_SYSTEM_WAITER_H_ 73 #endif // MOJO_EDK_SYSTEM_WAITER_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698