| OLD | NEW |
| 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_EDK_SYSTEM_HANDLE_TABLE_H_ | 5 #ifndef MOJO_EDK_SYSTEM_HANDLE_TABLE_H_ |
| 6 #define MOJO_EDK_SYSTEM_HANDLE_TABLE_H_ | 6 #define MOJO_EDK_SYSTEM_HANDLE_TABLE_H_ |
| 7 | 7 |
| 8 #include <unordered_map> | 8 #include <unordered_map> |
| 9 #include <utility> | 9 #include <utility> |
| 10 #include <vector> | 10 #include <vector> |
| 11 | 11 |
| 12 #include "base/memory/ref_counted.h" | 12 #include "base/memory/ref_counted.h" |
| 13 #include "mojo/edk/system/system_impl_export.h" | |
| 14 #include "mojo/public/c/system/types.h" | 13 #include "mojo/public/c/system/types.h" |
| 15 #include "mojo/public/cpp/system/macros.h" | 14 #include "mojo/public/cpp/system/macros.h" |
| 16 | 15 |
| 17 namespace mojo { | 16 namespace mojo { |
| 18 namespace system { | 17 namespace system { |
| 19 | 18 |
| 20 class Core; | 19 class Core; |
| 21 class Dispatcher; | 20 class Dispatcher; |
| 22 class DispatcherTransport; | 21 class DispatcherTransport; |
| 23 | 22 |
| 24 using DispatcherVector = std::vector<scoped_refptr<Dispatcher>>; | 23 using DispatcherVector = std::vector<scoped_refptr<Dispatcher>>; |
| 25 | 24 |
| 26 // Test-only function (defined/used in embedder/test_embedder.cc). Declared here | 25 // Test-only function (defined/used in embedder/test_embedder.cc). Declared here |
| 27 // so it can be friended. | 26 // so it can be friended. |
| 28 namespace internal { | 27 namespace internal { |
| 29 bool ShutdownCheckNoLeaks(Core*); | 28 bool ShutdownCheckNoLeaks(Core*); |
| 30 } | 29 } |
| 31 | 30 |
| 32 // This class provides the (global) handle table (owned by |Core|), which maps | 31 // This class provides the (global) handle table (owned by |Core|), which maps |
| 33 // (valid) |MojoHandle|s to |Dispatcher|s. This is abstracted so that, e.g., | 32 // (valid) |MojoHandle|s to |Dispatcher|s. This is abstracted so that, e.g., |
| 34 // caching may be added. | 33 // caching may be added. |
| 35 // | 34 // |
| 36 // This class is NOT thread-safe; locking is left to |Core| (since it may need | 35 // This class is NOT thread-safe; locking is left to |Core| (since it may need |
| 37 // to make several changes -- "atomically" or in rapid successsion, in which | 36 // to make several changes -- "atomically" or in rapid successsion, in which |
| 38 // case the extra locking/unlocking would be unnecessary overhead). | 37 // case the extra locking/unlocking would be unnecessary overhead). |
| 39 | 38 |
| 40 class MOJO_SYSTEM_IMPL_EXPORT HandleTable { | 39 class HandleTable { |
| 41 public: | 40 public: |
| 42 HandleTable(); | 41 HandleTable(); |
| 43 ~HandleTable(); | 42 ~HandleTable(); |
| 44 | 43 |
| 45 // Gets the dispatcher for a given handle (which should not be | 44 // Gets the dispatcher for a given handle (which should not be |
| 46 // |MOJO_HANDLE_INVALID|). Returns null if there's no dispatcher for the given | 45 // |MOJO_HANDLE_INVALID|). Returns null if there's no dispatcher for the given |
| 47 // handle. | 46 // handle. |
| 48 // WARNING: For efficiency, this returns a dumb pointer. If you're going to | 47 // WARNING: For efficiency, this returns a dumb pointer. If you're going to |
| 49 // use the result outside |Core|'s lock, you MUST take a reference (e.g., by | 48 // use the result outside |Core|'s lock, you MUST take a reference (e.g., by |
| 50 // storing the result inside a |scoped_refptr|). | 49 // storing the result inside a |scoped_refptr|). |
| (...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 135 HandleToEntryMap handle_to_entry_map_; | 134 HandleToEntryMap handle_to_entry_map_; |
| 136 MojoHandle next_handle_; // Invariant: never |MOJO_HANDLE_INVALID|. | 135 MojoHandle next_handle_; // Invariant: never |MOJO_HANDLE_INVALID|. |
| 137 | 136 |
| 138 MOJO_DISALLOW_COPY_AND_ASSIGN(HandleTable); | 137 MOJO_DISALLOW_COPY_AND_ASSIGN(HandleTable); |
| 139 }; | 138 }; |
| 140 | 139 |
| 141 } // namespace system | 140 } // namespace system |
| 142 } // namespace mojo | 141 } // namespace mojo |
| 143 | 142 |
| 144 #endif // MOJO_EDK_SYSTEM_HANDLE_TABLE_H_ | 143 #endif // MOJO_EDK_SYSTEM_HANDLE_TABLE_H_ |
| OLD | NEW |