OLD | NEW |
1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 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/public/cpp/application/run_application.h" | 5 #include "mojo/public/cpp/application/run_application.h" |
6 | 6 |
7 #include <assert.h> | 7 #include <assert.h> |
8 #include <pthread.h> | 8 #include <pthread.h> |
9 | 9 |
10 #include "mojo/public/cpp/application/application_impl_base.h" | 10 #include "mojo/public/cpp/application/application_impl_base.h" |
11 #include "mojo/public/cpp/system/macros.h" | 11 #include "mojo/public/cpp/system/macros.h" |
12 #include "mojo/public/cpp/system/message_pipe.h" | 12 #include "mojo/public/cpp/system/message_pipe.h" |
13 #include "mojo/public/cpp/utility/run_loop.h" | 13 #include "mojo/public/cpp/utility/run_loop.h" |
14 #include "mojo/public/interfaces/application/application.mojom.h" | 14 #include "mojo/public/interfaces/application/application.mojom.h" |
15 | 15 |
16 namespace mojo { | 16 namespace mojo { |
17 | 17 |
18 namespace { | 18 namespace { |
19 | 19 |
20 // We store a pointer to a |ResultHolder|, which just stores a |MojoResult|, in | 20 // We store a pointer to a |ResultHolder|, which just stores a |MojoResult|, in |
21 // TLS so that |TerminateApplication()| can provide the result that | 21 // TLS so that |TerminateApplication()| can provide the result that |
22 // |RunApplication()| will return. (The |ResultHolder| is just on | 22 // |RunApplication()| will return. (The |ResultHolder| is just on |
23 // |RunApplication()|'s stack.) | 23 // |RunApplication()|'s stack.) |
24 struct ResultHolder { | 24 struct ResultHolder { |
25 #ifndef NDEBUG | 25 #ifndef NDEBUG |
26 bool is_set = false; | 26 bool is_set = false; |
27 #endif | 27 #endif |
28 MojoResult result = MOJO_RESULT_UNKNOWN; | 28 // TODO(vtl): The default result should probably be |MOJO_RESULT_UNKNOWN|, but |
| 29 // |ApplicationRunner| always returned |MOJO_RESULT_OK|. |
| 30 MojoResult result = MOJO_RESULT_OK; |
29 }; | 31 }; |
30 | 32 |
31 pthread_key_t g_current_result_holder_key; | 33 pthread_key_t g_current_result_holder_key; |
32 | 34 |
33 // Ensures that we have a TLS slot to store the current result in. | 35 // Ensures that we have a TLS slot to store the current result in. |
34 void InitializeCurrentResultHolderIfNecessary() { | 36 void InitializeCurrentResultHolderIfNecessary() { |
35 static pthread_once_t current_result_holder_key_once = PTHREAD_ONCE_INIT; | 37 static pthread_once_t current_result_holder_key_once = PTHREAD_ONCE_INIT; |
36 int error = pthread_once(¤t_result_holder_key_once, []() { | 38 int error = pthread_once(¤t_result_holder_key_once, []() { |
37 int error = pthread_key_create(&g_current_result_holder_key, nullptr); | 39 int error = pthread_key_create(&g_current_result_holder_key, nullptr); |
38 MOJO_ALLOW_UNUSED_LOCAL(error); | 40 MOJO_ALLOW_UNUSED_LOCAL(error); |
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
97 ResultHolder* result_holder = GetCurrentResultHolder(); | 99 ResultHolder* result_holder = GetCurrentResultHolder(); |
98 assert(result_holder); | 100 assert(result_holder); |
99 assert(!result_holder->is_set); | 101 assert(!result_holder->is_set); |
100 result_holder->result = result; | 102 result_holder->result = result; |
101 #ifndef NDEBUG | 103 #ifndef NDEBUG |
102 result_holder->is_set = true; | 104 result_holder->is_set = true; |
103 #endif | 105 #endif |
104 } | 106 } |
105 | 107 |
106 } // namespace mojo | 108 } // namespace mojo |
OLD | NEW |