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

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

Issue 231353002: Make mojo_system static and mojo_system_impl a component, never use both (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Cleanup Created 6 years, 8 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
1 // Copyright 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 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_HANDLE_TABLE_H_ 5 #ifndef MOJO_SYSTEM_HANDLE_TABLE_H_
6 #define MOJO_SYSTEM_HANDLE_TABLE_H_ 6 #define MOJO_SYSTEM_HANDLE_TABLE_H_
7 7
8 #include <utility> 8 #include <utility>
9 #include <vector> 9 #include <vector>
10 10
11 #include "base/containers/hash_tables.h" 11 #include "base/containers/hash_tables.h"
12 #include "base/macros.h" 12 #include "base/macros.h"
13 #include "base/memory/ref_counted.h" 13 #include "base/memory/ref_counted.h"
14 #include "mojo/public/c/system/core.h" 14 #include "mojo/public/c/system/core.h"
15 #include "mojo/system/system_impl_export.h" 15 #include "mojo/system/system_impl_export.h"
16 16
17 namespace mojo { 17 namespace mojo {
18 namespace system { 18 namespace system {
19 19
20 class CoreImpl; 20 class Core;
21 class Dispatcher; 21 class Dispatcher;
22 class DispatcherTransport; 22 class DispatcherTransport;
23 23
24 // Test-only function (defined/used in embedder/test_embedder.cc). Declared here 24 // Test-only function (defined/used in embedder/test_embedder.cc). Declared here
25 // so it can be friended. 25 // so it can be friended.
26 namespace internal { 26 namespace internal {
27 bool ShutdownCheckNoLeaks(CoreImpl*); 27 bool ShutdownCheckNoLeaks(Core*);
28 } 28 }
29 29
30 // This class provides the (global) handle table (owned by |CoreImpl|), which 30 // This class provides the (global) handle table (owned by |Core|), which
viettrungluu 2014/04/09 20:26:52 Nit: Please re-wrap this paragraph, and the next o
DaveMoore 2014/04/09 22:49:08 Done.
31 // maps (valid) |MojoHandle|s to |Dispatcher|s. This is abstracted so that, 31 // maps (valid) |MojoHandle|s to |Dispatcher|s. This is abstracted so that,
32 // e.g., caching may be added. 32 // e.g., caching may be added.
33 // 33 //
34 // This class is NOT thread-safe; locking is left to |CoreImpl| (since it may 34 // This class is NOT thread-safe; locking is left to |Core| (since it may
35 // need to make several changes -- "atomically" or in rapid successsion, in 35 // need to make several changes -- "atomically" or in rapid successsion, in
36 // which case the extra locking/unlocking would be unnecessary overhead). 36 // which case the extra locking/unlocking would be unnecessary overhead).
37 37
38 class MOJO_SYSTEM_IMPL_EXPORT HandleTable { 38 class MOJO_SYSTEM_IMPL_EXPORT HandleTable {
39 public: 39 public:
40 HandleTable(); 40 HandleTable();
41 ~HandleTable(); 41 ~HandleTable();
42 42
43 // Gets the dispatcher for a given handle (which should not be 43 // Gets the dispatcher for a given handle (which should not be
44 // |MOJO_HANDLE_INVALID|). Returns null if there's no dispatcher for the given 44 // |MOJO_HANDLE_INVALID|). Returns null if there's no dispatcher for the given
45 // handle. 45 // handle.
46 // WARNING: For efficiency, this returns a dumb pointer. If you're going to 46 // WARNING: For efficiency, this returns a dumb pointer. If you're going to
47 // use the result outside |CoreImpl|'s lock, you MUST take a reference (e.g., 47 // use the result outside |Core|'s lock, you MUST take a reference (e.g.,
viettrungluu 2014/04/09 20:26:52 "
DaveMoore 2014/04/09 22:49:08 Done.
48 // by storing the result inside a |scoped_refptr|). 48 // by storing the result inside a |scoped_refptr|).
49 Dispatcher* GetDispatcher(MojoHandle handle); 49 Dispatcher* GetDispatcher(MojoHandle handle);
50 50
51 // On success, gets the dispatcher for a given handle (which should not be 51 // On success, gets the dispatcher for a given handle (which should not be
52 // |MOJO_HANDLE_INVALID|) and removes it. (On failure, returns an appropriate 52 // |MOJO_HANDLE_INVALID|) and removes it. (On failure, returns an appropriate
53 // result (and leaves |dispatcher| alone), namely 53 // result (and leaves |dispatcher| alone), namely
54 // |MOJO_RESULT_INVALID_ARGUMENT| if there's no dispatcher for the given 54 // |MOJO_RESULT_INVALID_ARGUMENT| if there's no dispatcher for the given
55 // handle or |MOJO_RESULT_BUSY| if the handle is marked as busy.) 55 // handle or |MOJO_RESULT_BUSY| if the handle is marked as busy.)
56 MojoResult GetAndRemoveDispatcher(MojoHandle handle, 56 MojoResult GetAndRemoveDispatcher(MojoHandle handle,
57 scoped_refptr<Dispatcher>* dispatcher); 57 scoped_refptr<Dispatcher>* dispatcher);
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
91 // Remove the given handles, which must all be present and which should have 91 // Remove the given handles, which must all be present and which should have
92 // previously been marked busy by |MarkBusyAndStartTransport()|. 92 // previously been marked busy by |MarkBusyAndStartTransport()|.
93 void RemoveBusyHandles(const MojoHandle* handles, uint32_t num_handles); 93 void RemoveBusyHandles(const MojoHandle* handles, uint32_t num_handles);
94 94
95 // Restores the given handles, which must all be present and which should have 95 // Restores the given handles, which must all be present and which should have
96 // previously been marked busy by |MarkBusyAndStartTransport()|, to a non-busy 96 // previously been marked busy by |MarkBusyAndStartTransport()|, to a non-busy
97 // state. 97 // state.
98 void RestoreBusyHandles(const MojoHandle* handles, uint32_t num_handles); 98 void RestoreBusyHandles(const MojoHandle* handles, uint32_t num_handles);
99 99
100 private: 100 private:
101 friend bool internal::ShutdownCheckNoLeaks(CoreImpl*); 101 friend bool internal::ShutdownCheckNoLeaks(Core*);
102 102
103 struct Entry { 103 struct Entry {
104 Entry(); 104 Entry();
105 explicit Entry(const scoped_refptr<Dispatcher>& dispatcher); 105 explicit Entry(const scoped_refptr<Dispatcher>& dispatcher);
106 ~Entry(); 106 ~Entry();
107 107
108 scoped_refptr<Dispatcher> dispatcher; 108 scoped_refptr<Dispatcher> dispatcher;
109 bool busy; 109 bool busy;
110 }; 110 };
111 typedef base::hash_map<MojoHandle, Entry> HandleToEntryMap; 111 typedef base::hash_map<MojoHandle, Entry> HandleToEntryMap;
112 112
113 // Adds the given dispatcher to the handle table, not doing any size checks. 113 // Adds the given dispatcher to the handle table, not doing any size checks.
114 MojoHandle AddDispatcherNoSizeCheck( 114 MojoHandle AddDispatcherNoSizeCheck(
115 const scoped_refptr<Dispatcher>& dispatcher); 115 const scoped_refptr<Dispatcher>& dispatcher);
116 116
117 HandleToEntryMap handle_to_entry_map_; 117 HandleToEntryMap handle_to_entry_map_;
118 MojoHandle next_handle_; // Invariant: never |MOJO_HANDLE_INVALID|. 118 MojoHandle next_handle_; // Invariant: never |MOJO_HANDLE_INVALID|.
119 119
120 DISALLOW_COPY_AND_ASSIGN(HandleTable); 120 DISALLOW_COPY_AND_ASSIGN(HandleTable);
121 }; 121 };
122 122
123 } // namespace system 123 } // namespace system
124 } // namespace mojo 124 } // namespace mojo
125 125
126 #endif // MOJO_SYSTEM_HANDLE_TABLE_H_ 126 #endif // MOJO_SYSTEM_HANDLE_TABLE_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698