OLD | NEW |
1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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 #include "mojo/edk/embedder/embedder_internal.h" | 5 #include "mojo/edk/embedder/embedder_internal.h" |
6 #include "mojo/edk/system/core.h" | 6 #include "mojo/edk/system/core.h" |
7 #include "mojo/edk/system/dispatcher.h" | 7 #include "mojo/edk/system/dispatcher.h" |
| 8 #include "mojo/edk/system/ref_ptr.h" |
8 #include "mojo/public/c/system/buffer.h" | 9 #include "mojo/public/c/system/buffer.h" |
9 #include "mojo/public/c/system/data_pipe.h" | 10 #include "mojo/public/c/system/data_pipe.h" |
10 #include "mojo/public/c/system/functions.h" | 11 #include "mojo/public/c/system/functions.h" |
11 #include "mojo/public/c/system/message_pipe.h" | 12 #include "mojo/public/c/system/message_pipe.h" |
12 #include "mojo/public/platform/native/system_impl_private.h" | 13 #include "mojo/public/platform/native/system_impl_private.h" |
13 | 14 |
14 using mojo::embedder::internal::g_core; | 15 using mojo::embedder::internal::g_core; |
15 using mojo::system::Core; | 16 using mojo::system::Core; |
16 using mojo::system::Dispatcher; | 17 using mojo::system::Dispatcher; |
17 using mojo::system::MakeUserPointer; | 18 using mojo::system::MakeUserPointer; |
| 19 using mojo::system::RefPtr; |
18 | 20 |
19 // Definitions of the system functions, but with an explicit parameter for the | 21 // Definitions of the system functions, but with an explicit parameter for the |
20 // core object rather than using the default singleton. Also includes functions | 22 // core object rather than using the default singleton. Also includes functions |
21 // for manipulating core objects. | 23 // for manipulating core objects. |
22 extern "C" { | 24 extern "C" { |
23 | 25 |
24 MojoSystemImpl MojoSystemImplGetDefaultImpl() { | 26 MojoSystemImpl MojoSystemImplGetDefaultImpl() { |
25 return static_cast<MojoSystemImpl>(g_core); | 27 return static_cast<MojoSystemImpl>(g_core); |
26 } | 28 } |
27 | 29 |
(...skipping 13 matching lines...) Expand all Loading... |
41 if (handle == MOJO_HANDLE_INVALID) | 43 if (handle == MOJO_HANDLE_INVALID) |
42 return MOJO_RESULT_INVALID_ARGUMENT; | 44 return MOJO_RESULT_INVALID_ARGUMENT; |
43 | 45 |
44 Core* to_core = static_cast<Core*>(to_system); | 46 Core* to_core = static_cast<Core*>(to_system); |
45 if (to_core == nullptr) | 47 if (to_core == nullptr) |
46 return MOJO_RESULT_INVALID_ARGUMENT; | 48 return MOJO_RESULT_INVALID_ARGUMENT; |
47 | 49 |
48 if (result_handle == nullptr) | 50 if (result_handle == nullptr) |
49 return MOJO_RESULT_INVALID_ARGUMENT; | 51 return MOJO_RESULT_INVALID_ARGUMENT; |
50 | 52 |
51 scoped_refptr<Dispatcher> d; | 53 RefPtr<Dispatcher> d; |
52 MojoResult result = from_core->GetAndRemoveDispatcher(handle, &d); | 54 MojoResult result = from_core->GetAndRemoveDispatcher(handle, &d); |
53 if (result != MOJO_RESULT_OK) | 55 if (result != MOJO_RESULT_OK) |
54 return result; | 56 return result; |
55 | 57 |
56 MojoHandle created_handle = to_core->AddDispatcher(d); | 58 MojoHandle created_handle = to_core->AddDispatcher(d.get()); |
57 if (created_handle == MOJO_HANDLE_INVALID) { | 59 if (created_handle == MOJO_HANDLE_INVALID) { |
58 // The handle has been lost, unfortunately. There's no guarentee we can put | 60 // The handle has been lost, unfortunately. There's no guarentee we can put |
59 // it back where it came from, or get the original ID back. Holding locks | 61 // it back where it came from, or get the original ID back. Holding locks |
60 // for multiple cores risks deadlock, so that isn't a solution. This case | 62 // for multiple cores risks deadlock, so that isn't a solution. This case |
61 // should not happen for reasonable uses of this API, however. | 63 // should not happen for reasonable uses of this API, however. |
62 LOG(ERROR) << "Could not transfer handle"; | 64 LOG(ERROR) << "Could not transfer handle"; |
63 d->Close(); | 65 d->Close(); |
64 return MOJO_RESULT_RESOURCE_EXHAUSTED; | 66 return MOJO_RESULT_RESOURCE_EXHAUSTED; |
65 } | 67 } |
66 | 68 |
(...skipping 184 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
251 MakeUserPointer(buffer), flags); | 253 MakeUserPointer(buffer), flags); |
252 } | 254 } |
253 | 255 |
254 MojoResult MojoSystemImplUnmapBuffer(MojoSystemImpl system, void* buffer) { | 256 MojoResult MojoSystemImplUnmapBuffer(MojoSystemImpl system, void* buffer) { |
255 mojo::system::Core* core = static_cast<mojo::system::Core*>(system); | 257 mojo::system::Core* core = static_cast<mojo::system::Core*>(system); |
256 DCHECK(core); | 258 DCHECK(core); |
257 return core->UnmapBuffer(MakeUserPointer(buffer)); | 259 return core->UnmapBuffer(MakeUserPointer(buffer)); |
258 } | 260 } |
259 | 261 |
260 } // extern "C" | 262 } // extern "C" |
OLD | NEW |