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_IMPL_H_ | 5 #ifndef MOJO_SYSTEM_CORE_IMPL_H_ |
6 #define MOJO_SYSTEM_CORE_IMPL_H_ | 6 #define MOJO_SYSTEM_CORE_IMPL_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/containers/hash_tables.h" | 10 #include "base/containers/hash_tables.h" |
11 #include "base/memory/ref_counted.h" | 11 #include "base/memory/ref_counted.h" |
12 #include "base/synchronization/lock.h" | 12 #include "base/synchronization/lock.h" |
13 #include "mojo/public/system/core_private.h" | 13 #include "mojo/public/system/core_private.h" |
14 #include "mojo/system/system_impl_export.h" | 14 #include "mojo/system/system_impl_export.h" |
15 | 15 |
16 namespace mojo { | 16 namespace mojo { |
17 | |
18 namespace system { | 17 namespace system { |
19 | 18 |
20 class CoreImpl; | 19 class CoreImpl; |
21 class Dispatcher; | 20 class Dispatcher; |
22 | 21 |
22 // Test-only function (defined/used in embedder/test_embedder.cc). Declared here | |
23 // so it can be friended. | |
24 namespace internal { | |
25 bool ShutdownCheckNoLeaks(CoreImpl*); | |
sky
2014/01/17 20:29:01
I believe the style guide says you should name the
| |
26 } | |
27 | |
23 // |CoreImpl| is a singleton object that implements the Mojo system calls. All | 28 // |CoreImpl| is a singleton object that implements the Mojo system calls. All |
24 // public methods are thread-safe. | 29 // public methods are thread-safe. |
25 class MOJO_SYSTEM_IMPL_EXPORT CoreImpl : public Core { | 30 class MOJO_SYSTEM_IMPL_EXPORT CoreImpl : public Core { |
26 public: | 31 public: |
27 // These methods are only to be used by via the embedder API. | 32 // These methods are only to be used by via the embedder API. |
28 CoreImpl(); | 33 CoreImpl(); |
29 virtual ~CoreImpl(); | 34 virtual ~CoreImpl(); |
30 MojoHandle AddDispatcher(const scoped_refptr<Dispatcher>& dispatcher); | 35 MojoHandle AddDispatcher(const scoped_refptr<Dispatcher>& dispatcher); |
31 | 36 |
32 // |CorePrivate| implementation: | 37 // |CorePrivate| implementation: |
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
73 uint32_t* num_bytes, | 78 uint32_t* num_bytes, |
74 MojoReadDataFlags flags) OVERRIDE; | 79 MojoReadDataFlags flags) OVERRIDE; |
75 virtual MojoResult BeginReadData(MojoHandle data_pipe_consumer_handle, | 80 virtual MojoResult BeginReadData(MojoHandle data_pipe_consumer_handle, |
76 const void** buffer, | 81 const void** buffer, |
77 uint32_t* buffer_num_bytes, | 82 uint32_t* buffer_num_bytes, |
78 MojoReadDataFlags flags) OVERRIDE; | 83 MojoReadDataFlags flags) OVERRIDE; |
79 virtual MojoResult EndReadData(MojoHandle data_pipe_consumer_handle, | 84 virtual MojoResult EndReadData(MojoHandle data_pipe_consumer_handle, |
80 uint32_t num_bytes_read) OVERRIDE; | 85 uint32_t num_bytes_read) OVERRIDE; |
81 | 86 |
82 private: | 87 private: |
88 friend bool internal::ShutdownCheckNoLeaks(CoreImpl*); | |
89 | |
83 // The |busy| member is used only to deal with functions (in particular | 90 // The |busy| member is used only to deal with functions (in particular |
84 // |WriteMessage()|) that want to hold on to a dispatcher and later remove it | 91 // |WriteMessage()|) that want to hold on to a dispatcher and later remove it |
85 // from the handle table, without holding on to the handle table lock. | 92 // from the handle table, without holding on to the handle table lock. |
86 // | 93 // |
87 // For example, if |WriteMessage()| is called with a handle to be sent, (under | 94 // For example, if |WriteMessage()| is called with a handle to be sent, (under |
88 // the handle table lock) it must first check that that handle is not busy (if | 95 // the handle table lock) it must first check that that handle is not busy (if |
89 // it is busy, then it fails with |MOJO_RESULT_BUSY|) and then marks it as | 96 // it is busy, then it fails with |MOJO_RESULT_BUSY|) and then marks it as |
90 // busy. To avoid deadlock, it should also try to acquire the locks for all | 97 // busy. To avoid deadlock, it should also try to acquire the locks for all |
91 // the dispatchers for the handles that it is sending (and fail with | 98 // the dispatchers for the handles that it is sending (and fail with |
92 // |MOJO_RESULT_BUSY| if the attempt fails). At this point, it can release the | 99 // |MOJO_RESULT_BUSY| if the attempt fails). At this point, it can release the |
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
138 base::Lock handle_table_lock_; // Protects the immediately-following members. | 145 base::Lock handle_table_lock_; // Protects the immediately-following members. |
139 HandleTableMap handle_table_; | 146 HandleTableMap handle_table_; |
140 MojoHandle next_handle_; // Invariant: never |MOJO_HANDLE_INVALID|. | 147 MojoHandle next_handle_; // Invariant: never |MOJO_HANDLE_INVALID|. |
141 | 148 |
142 // --------------------------------------------------------------------------- | 149 // --------------------------------------------------------------------------- |
143 | 150 |
144 DISALLOW_COPY_AND_ASSIGN(CoreImpl); | 151 DISALLOW_COPY_AND_ASSIGN(CoreImpl); |
145 }; | 152 }; |
146 | 153 |
147 } // namespace system | 154 } // namespace system |
148 | |
149 } // namespace mojo | 155 } // namespace mojo |
150 | 156 |
151 #endif // MOJO_SYSTEM_CORE_IMPL_H_ | 157 #endif // MOJO_SYSTEM_CORE_IMPL_H_ |
OLD | NEW |