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 embedder { | |
19 void Init(); // So it can be friended. | |
20 } | |
21 | |
17 namespace system { | 22 namespace system { |
18 | 23 |
19 class CoreImpl; | 24 class CoreImpl; |
20 class Dispatcher; | 25 class Dispatcher; |
21 | 26 |
22 namespace test { | 27 namespace test { |
23 class CoreTestBase; | 28 class CoreTestBase; |
24 } | 29 } |
25 | 30 |
26 // |CoreImpl| is a singleton object that implements the Mojo system calls. With | 31 // |CoreImpl| is a singleton object that implements the Mojo system calls. All |
27 // the (obvious) exception of |Init()|, which must be called first (and the call | 32 // public methods are thread-safe. |
28 // completed) before making any other calls, all the public methods are | |
29 // thread-safe. | |
30 class MOJO_SYSTEM_IMPL_EXPORT CoreImpl : public Core { | 33 class MOJO_SYSTEM_IMPL_EXPORT CoreImpl : public Core { |
31 public: | 34 public: |
32 static void Init(); | 35 static void Init(); |
33 | 36 |
34 // |CorePrivate| implementation: | 37 // |CorePrivate| implementation: |
35 virtual MojoTimeTicks GetTimeTicksNow() OVERRIDE; | 38 virtual MojoTimeTicks GetTimeTicksNow() OVERRIDE; |
36 virtual MojoResult Close(MojoHandle handle) OVERRIDE; | 39 virtual MojoResult Close(MojoHandle handle) OVERRIDE; |
37 virtual MojoResult Wait(MojoHandle handle, | 40 virtual MojoResult Wait(MojoHandle handle, |
38 MojoWaitFlags flags, | 41 MojoWaitFlags flags, |
39 MojoDeadline deadline) OVERRIDE; | 42 MojoDeadline deadline) OVERRIDE; |
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
75 uint32_t* num_bytes, | 78 uint32_t* num_bytes, |
76 MojoReadDataFlags flags) OVERRIDE; | 79 MojoReadDataFlags flags) OVERRIDE; |
77 virtual MojoResult BeginReadData(MojoHandle data_pipe_consumer_handle, | 80 virtual MojoResult BeginReadData(MojoHandle data_pipe_consumer_handle, |
78 const void** buffer, | 81 const void** buffer, |
79 uint32_t* buffer_num_bytes, | 82 uint32_t* buffer_num_bytes, |
80 MojoReadDataFlags flags) OVERRIDE; | 83 MojoReadDataFlags flags) OVERRIDE; |
81 virtual MojoResult EndReadData(MojoHandle data_pipe_consumer_handle, | 84 virtual MojoResult EndReadData(MojoHandle data_pipe_consumer_handle, |
82 uint32_t num_bytes_read) OVERRIDE; | 85 uint32_t num_bytes_read) OVERRIDE; |
83 | 86 |
84 private: | 87 private: |
88 friend void ::mojo::embedder::Init(); | |
darin (slow to review)
2014/01/10 22:48:54
it doesn't work to just say "embedder::Init()" her
viettrungluu
2014/01/11 00:30:38
Done.
| |
85 friend class test::CoreTestBase; | 89 friend class test::CoreTestBase; |
86 | 90 |
87 // The |busy| member is used only to deal with functions (in particular | 91 // The |busy| member is used only to deal with functions (in particular |
88 // |WriteMessage()|) that want to hold on to a dispatcher and later remove it | 92 // |WriteMessage()|) that want to hold on to a dispatcher and later remove it |
89 // from the handle table, without holding on to the handle table lock. | 93 // from the handle table, without holding on to the handle table lock. |
90 // | 94 // |
91 // For example, if |WriteMessage()| is called with a handle to be sent, (under | 95 // For example, if |WriteMessage()| is called with a handle to be sent, (under |
92 // the handle table lock) it must first check that that handle is not busy (if | 96 // the handle table lock) it must first check that that handle is not busy (if |
93 // it is busy, then it fails with |MOJO_RESULT_BUSY|) and then marks it as | 97 // it is busy, then it fails with |MOJO_RESULT_BUSY|) and then marks it as |
94 // busy. To avoid deadlock, it should also try to acquire the locks for all | 98 // busy. To avoid deadlock, it should also try to acquire the locks for all |
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
145 base::Lock handle_table_lock_; // Protects the immediately-following members. | 149 base::Lock handle_table_lock_; // Protects the immediately-following members. |
146 HandleTableMap handle_table_; | 150 HandleTableMap handle_table_; |
147 MojoHandle next_handle_; // Invariant: never |MOJO_HANDLE_INVALID|. | 151 MojoHandle next_handle_; // Invariant: never |MOJO_HANDLE_INVALID|. |
148 | 152 |
149 // --------------------------------------------------------------------------- | 153 // --------------------------------------------------------------------------- |
150 | 154 |
151 DISALLOW_COPY_AND_ASSIGN(CoreImpl); | 155 DISALLOW_COPY_AND_ASSIGN(CoreImpl); |
152 }; | 156 }; |
153 | 157 |
154 } // namespace system | 158 } // namespace system |
159 | |
155 } // namespace mojo | 160 } // namespace mojo |
156 | 161 |
157 #endif // MOJO_SYSTEM_CORE_IMPL_H_ | 162 #endif // MOJO_SYSTEM_CORE_IMPL_H_ |
OLD | NEW |