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

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

Issue 66963005: Mojo: Implement local passing of MessagePipes. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: rebased Created 7 years, 1 month 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
« no previous file with comments | « mojo/system/core_test_base.cc ('k') | mojo/system/dispatcher.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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_SYSTEM_DISPATCHER_H_ 5 #ifndef MOJO_SYSTEM_DISPATCHER_H_
6 #define MOJO_SYSTEM_DISPATCHER_H_ 6 #define MOJO_SYSTEM_DISPATCHER_H_
7 7
8 #include <vector> 8 #include <vector>
9 9
10 #include "base/basictypes.h" 10 #include "base/basictypes.h"
(...skipping 24 matching lines...) Expand all
35 // prevents the various |...ImplNoLock()|s from releasing the lock as soon as 35 // prevents the various |...ImplNoLock()|s from releasing the lock as soon as
36 // possible. If this becomes an issue, we can rethink this. 36 // possible. If this becomes an issue, we can rethink this.
37 MojoResult Close(); 37 MojoResult Close();
38 // |dispatchers| may be non-null if and only if there are handles to be 38 // |dispatchers| may be non-null if and only if there are handles to be
39 // written, in which case this will be called with all the dispatchers' locks 39 // written, in which case this will be called with all the dispatchers' locks
40 // held. On success, all the dispatchers must have been moved to a closed 40 // held. On success, all the dispatchers must have been moved to a closed
41 // state; on failure, they should remain in their original state. 41 // state; on failure, they should remain in their original state.
42 MojoResult WriteMessage(const void* bytes, uint32_t num_bytes, 42 MojoResult WriteMessage(const void* bytes, uint32_t num_bytes,
43 const std::vector<Dispatcher*>* dispatchers, 43 const std::vector<Dispatcher*>* dispatchers,
44 MojoWriteMessageFlags flags); 44 MojoWriteMessageFlags flags);
45 // |dispatchers| must be non-null but empty, if |max_num_dispatchers| is 45 // |dispatchers| must be non-null but empty, if |num_dispatchers| is non-null
46 // nonzero. On success, it will be set to the dispatchers to be received (and 46 // and nonzero. On success, it will be set to the dispatchers to be received
47 // assigned handles) as part of the message. 47 // (and assigned handles) as part of the message.
48 MojoResult ReadMessage( 48 MojoResult ReadMessage(
49 void* bytes, uint32_t* num_bytes, 49 void* bytes, uint32_t* num_bytes,
50 uint32_t max_num_dispatchers,
51 std::vector<scoped_refptr<Dispatcher> >* dispatchers, 50 std::vector<scoped_refptr<Dispatcher> >* dispatchers,
51 uint32_t* num_dispatchers,
52 MojoReadMessageFlags flags); 52 MojoReadMessageFlags flags);
53 53
54 // Adds a waiter to this dispatcher. The waiter will be woken up when this 54 // Adds a waiter to this dispatcher. The waiter will be woken up when this
55 // object changes state to satisfy |flags| with result |wake_result| (which 55 // object changes state to satisfy |flags| with result |wake_result| (which
56 // must be >= 0, i.e., a success status). It will also be woken up when it 56 // must be >= 0, i.e., a success status). It will also be woken up when it
57 // becomes impossible for the object to ever satisfy |flags| with a suitable 57 // becomes impossible for the object to ever satisfy |flags| with a suitable
58 // error status. 58 // error status.
59 // 59 //
60 // Returns: 60 // Returns:
61 // - |MOJO_RESULT_OK| if the waiter was added; 61 // - |MOJO_RESULT_OK| if the waiter was added;
62 // - |MOJO_RESULT_ALREADY_EXISTS| if |flags| is already satisfied; 62 // - |MOJO_RESULT_ALREADY_EXISTS| if |flags| is already satisfied;
63 // - |MOJO_RESULT_INVALID_ARGUMENT| if the dispatcher has been closed; and 63 // - |MOJO_RESULT_INVALID_ARGUMENT| if the dispatcher has been closed; and
64 // - |MOJO_RESULT_FAILED_PRECONDITION| if it is not (or no longer) possible 64 // - |MOJO_RESULT_FAILED_PRECONDITION| if it is not (or no longer) possible
65 // that |flags| will ever be satisfied. 65 // that |flags| will ever be satisfied.
66 MojoResult AddWaiter(Waiter* waiter, 66 MojoResult AddWaiter(Waiter* waiter,
67 MojoWaitFlags flags, 67 MojoWaitFlags flags,
68 MojoResult wake_result); 68 MojoResult wake_result);
69 void RemoveWaiter(Waiter* waiter); 69 void RemoveWaiter(Waiter* waiter);
70 70
71 // Creates an equivalent dispatcher -- representing the same resource as this
72 // dispatcher -- and close (i.e., disable) this dispatcher. I.e., this
73 // dispatcher will look as though it was closed, but the resource it
74 // represents will be assigned to the new dispatcher. This must be called
75 // under the dispatcher's lock.
76 scoped_refptr<Dispatcher> CreateEquivalentDispatcherAndCloseNoLock();
77
71 protected: 78 protected:
72 Dispatcher(); 79 Dispatcher();
73 80
74 friend class base::RefCountedThreadSafe<Dispatcher>; 81 friend class base::RefCountedThreadSafe<Dispatcher>;
75 virtual ~Dispatcher(); 82 virtual ~Dispatcher();
76 83
77 // These are to be overridden by subclasses (if necessary). They are called 84 // These are to be overridden by subclasses (if necessary). They are called
78 // exactly once -- first |CancelAllWaitersNoLock()|, then |CloseImplNoLock()|, 85 // exactly once -- first |CancelAllWaitersNoLock()|, then |CloseImplNoLock()|,
79 // when the dispatcher is being closed. They are called under |lock_|. 86 // when the dispatcher is being closed. They are called under |lock_|.
80 virtual void CancelAllWaitersNoLock(); 87 virtual void CancelAllWaitersNoLock();
81 virtual MojoResult CloseImplNoLock(); 88 virtual MojoResult CloseImplNoLock();
82 89
83 // These are to be overridden by subclasses (if necessary). They are never 90 // These are to be overridden by subclasses (if necessary). They are never
84 // called after the dispatcher has been closed. They are called under |lock_|. 91 // called after the dispatcher has been closed. They are called under |lock_|.
85 // See the descriptions of the methods without the "ImplNoLock" for more 92 // See the descriptions of the methods without the "ImplNoLock" for more
86 // information. 93 // information.
87 virtual MojoResult WriteMessageImplNoLock( 94 virtual MojoResult WriteMessageImplNoLock(
88 const void* bytes, uint32_t num_bytes, 95 const void* bytes, uint32_t num_bytes,
89 const std::vector<Dispatcher*>* dispatchers, 96 const std::vector<Dispatcher*>* dispatchers,
90 MojoWriteMessageFlags flags); 97 MojoWriteMessageFlags flags);
91 virtual MojoResult ReadMessageImplNoLock( 98 virtual MojoResult ReadMessageImplNoLock(
92 void* bytes, uint32_t* num_bytes, 99 void* bytes, uint32_t* num_bytes,
93 uint32_t max_num_dispatchers,
94 std::vector<scoped_refptr<Dispatcher> >* dispatchers, 100 std::vector<scoped_refptr<Dispatcher> >* dispatchers,
101 uint32_t* num_dispatchers,
95 MojoReadMessageFlags flags); 102 MojoReadMessageFlags flags);
96 virtual MojoResult AddWaiterImplNoLock(Waiter* waiter, 103 virtual MojoResult AddWaiterImplNoLock(Waiter* waiter,
97 MojoWaitFlags flags, 104 MojoWaitFlags flags,
98 MojoResult wake_result); 105 MojoResult wake_result);
99 virtual void RemoveWaiterImplNoLock(Waiter* waiter); 106 virtual void RemoveWaiterImplNoLock(Waiter* waiter);
100 107
108 // This must be implemented by subclasses, since only they can instantiate a
109 // new dispatcher of the same class. See
110 // |CreateEquivalentDispatcherAndCloseNoLock()| for more details.
111 virtual scoped_refptr<Dispatcher>
112 CreateEquivalentDispatcherAndCloseImplNoLock() = 0;
113
101 // Available to subclasses. (Note: Returns a non-const reference, just like 114 // Available to subclasses. (Note: Returns a non-const reference, just like
102 // |base::AutoLock|'s constructor takes a non-const reference. 115 // |base::AutoLock|'s constructor takes a non-const reference.)
103 base::Lock& lock() const { return lock_; } 116 base::Lock& lock() const { return lock_; }
104 117
118 bool is_closed_no_lock() const { return is_closed_; }
119
105 private: 120 private:
106 // For |WriteMessage()|, |CoreImpl| needs access to |lock()|. 121 // For |WriteMessage()|, |CoreImpl| needs access to |lock()| and
122 // |is_closed_no_lock()|.
107 friend class CoreImpl; 123 friend class CoreImpl;
108 124
109 // This protects the following members as well as any state added by 125 // This protects the following members as well as any state added by
110 // subclasses. 126 // subclasses.
111 mutable base::Lock lock_; 127 mutable base::Lock lock_;
112 bool is_closed_; 128 bool is_closed_;
113 129
114 DISALLOW_COPY_AND_ASSIGN(Dispatcher); 130 DISALLOW_COPY_AND_ASSIGN(Dispatcher);
115 }; 131 };
116 132
117 } // namespace system 133 } // namespace system
118 } // namespace mojo 134 } // namespace mojo
119 135
120 #endif // MOJO_SYSTEM_DISPATCHER_H_ 136 #endif // MOJO_SYSTEM_DISPATCHER_H_
OLDNEW
« no previous file with comments | « mojo/system/core_test_base.cc ('k') | mojo/system/dispatcher.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698