OLD | NEW |
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_CORE_H_ | 5 #ifndef MOJO_SYSTEM_CORE_H_ |
6 #define MOJO_SYSTEM_CORE_H_ | 6 #define MOJO_SYSTEM_CORE_H_ |
7 | 7 |
8 #include "base/basictypes.h" | 8 #include "base/basictypes.h" |
9 #include "base/compiler_specific.h" | 9 #include "base/compiler_specific.h" |
10 #include "base/memory/ref_counted.h" | 10 #include "base/memory/ref_counted.h" |
(...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
86 MojoHandle* new_buffer_handle); | 86 MojoHandle* new_buffer_handle); |
87 MojoResult MapBuffer(MojoHandle buffer_handle, | 87 MojoResult MapBuffer(MojoHandle buffer_handle, |
88 uint64_t offset, | 88 uint64_t offset, |
89 uint64_t num_bytes, | 89 uint64_t num_bytes, |
90 void** buffer, | 90 void** buffer, |
91 MojoMapBufferFlags flags); | 91 MojoMapBufferFlags flags); |
92 MojoResult UnmapBuffer(void* buffer); | 92 MojoResult UnmapBuffer(void* buffer); |
93 | 93 |
94 private: | 94 private: |
95 friend bool internal::ShutdownCheckNoLeaks(Core*); | 95 friend bool internal::ShutdownCheckNoLeaks(Core*); |
96 // The |busy| member is used only to deal with functions (in particular | |
97 // |WriteMessage()|) that want to hold on to a dispatcher and later remove it | |
98 // from the handle table, without holding on to the handle table lock. | |
99 // | |
100 // For example, if |WriteMessage()| is called with a handle to be sent, (under | |
101 // the handle table lock) it must first check that that handle is not busy (if | |
102 // it is busy, then it fails with |MOJO_RESULT_BUSY|) and then marks it as | |
103 // busy. To avoid deadlock, it should also try to acquire the locks for all | |
104 // the dispatchers for the handles that it is sending (and fail with | |
105 // |MOJO_RESULT_BUSY| if the attempt fails). At this point, it can release the | |
106 // handle table lock. | |
107 // | |
108 // If |Close()| is simultaneously called on that handle, it too checks if the | |
109 // handle is marked busy. If it is, it fails (with |MOJO_RESULT_BUSY|). This | |
110 // prevents |WriteMessage()| from sending a handle that has been closed (or | |
111 // learning about this too late). | |
112 struct HandleTableEntry { | |
113 HandleTableEntry(); | |
114 explicit HandleTableEntry(const scoped_refptr<Dispatcher>& dispatcher); | |
115 ~HandleTableEntry(); | |
116 | |
117 scoped_refptr<Dispatcher> dispatcher; | |
118 bool busy; | |
119 }; | |
120 typedef base::hash_map<MojoHandle, HandleTableEntry> HandleTableMap; | |
121 | 96 |
122 // Looks up the dispatcher for the given handle. Returns null if the handle is | 97 // Looks up the dispatcher for the given handle. Returns null if the handle is |
123 // invalid. | 98 // invalid. |
124 scoped_refptr<Dispatcher> GetDispatcher(MojoHandle handle); | 99 scoped_refptr<Dispatcher> GetDispatcher(MojoHandle handle); |
125 | 100 |
126 // Internal implementation of |Wait()| and |WaitMany()|; doesn't do basic | 101 // Internal implementation of |Wait()| and |WaitMany()|; doesn't do basic |
127 // validation of arguments. | 102 // validation of arguments. |
128 MojoResult WaitManyInternal(const MojoHandle* handles, | 103 MojoResult WaitManyInternal(const MojoHandle* handles, |
129 const MojoWaitFlags* flags, | 104 const MojoWaitFlags* flags, |
130 uint32_t num_handles, | 105 uint32_t num_handles, |
(...skipping 11 matching lines...) Expand all Loading... |
142 | 117 |
143 // --------------------------------------------------------------------------- | 118 // --------------------------------------------------------------------------- |
144 | 119 |
145 DISALLOW_COPY_AND_ASSIGN(Core); | 120 DISALLOW_COPY_AND_ASSIGN(Core); |
146 }; | 121 }; |
147 | 122 |
148 } // namespace system | 123 } // namespace system |
149 } // namespace mojo | 124 } // namespace mojo |
150 | 125 |
151 #endif // MOJO_SYSTEM_CORE_H_ | 126 #endif // MOJO_SYSTEM_CORE_H_ |
OLD | NEW |