Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(682)

Side by Side Diff: mojo/public/cpp/environment/lib/environment.cc

Issue 1447273002: Mojo Log service and a thread-safe client library. (Closed) Base URL: https://github.com/domokit/mojo.git@master
Patch Set: Fix destructor race condition in log_client.cc; add some comments Created 5 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « mojo/public/cpp/environment/environment.h ('k') | mojo/public/cpp/environment/lib/logging.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 #include "mojo/public/cpp/environment/environment.h" 5 #include "mojo/public/cpp/environment/environment.h"
6 6
7 #include <assert.h> 7 #include <assert.h>
8 8
9 #include "mojo/public/c/environment/logger.h" 9 #include "mojo/public/c/environment/logger.h"
10 #include "mojo/public/cpp/environment/lib/default_async_waiter.h" 10 #include "mojo/public/cpp/environment/lib/default_async_waiter.h"
11 #include "mojo/public/cpp/environment/lib/default_logger.h" 11 #include "mojo/public/cpp/environment/lib/default_logger.h"
12 #include "mojo/public/cpp/utility/run_loop.h" 12 #include "mojo/public/cpp/utility/run_loop.h"
13 13
14 namespace mojo { 14 namespace mojo {
15 15
16 namespace { 16 namespace {
17 17
18 const MojoAsyncWaiter* g_default_async_waiter = nullptr; 18 const MojoAsyncWaiter* g_default_async_waiter = nullptr;
19 const MojoLogger* g_default_logger = nullptr; 19 const MojoLogger* g_default_logger = nullptr;
20 20
21 void Init(const MojoAsyncWaiter* default_async_waiter, 21 void Init(const MojoAsyncWaiter* default_async_waiter,
22 const MojoLogger* default_logger) { 22 const MojoLogger* default_logger) {
23 g_default_async_waiter = default_async_waiter 23 g_default_async_waiter = default_async_waiter
24 ? default_async_waiter 24 ? default_async_waiter
25 : &internal::kDefaultAsyncWaiter; 25 : &internal::kDefaultAsyncWaiter;
26
viettrungluu 2015/11/17 22:33:33 nit: Adding this blank line seems gratuitous.
26 g_default_logger = 27 g_default_logger =
27 default_logger ? default_logger : &internal::kDefaultLogger; 28 default_logger ? default_logger : &internal::kDefaultLogger;
28 29
29 RunLoop::SetUp(); 30 RunLoop::SetUp();
30 } 31 }
31 32
32 } // namespace 33 } // namespace
33 34
34 Environment::Environment() { 35 Environment::Environment() {
35 Init(nullptr, nullptr); 36 Init(nullptr, nullptr);
(...skipping 19 matching lines...) Expand all
55 return g_default_async_waiter; 56 return g_default_async_waiter;
56 } 57 }
57 58
58 // static 59 // static
59 const MojoLogger* Environment::GetDefaultLogger() { 60 const MojoLogger* Environment::GetDefaultLogger() {
60 assert(g_default_logger); // Fails if not "inside" |Environment|. 61 assert(g_default_logger); // Fails if not "inside" |Environment|.
61 return g_default_logger; 62 return g_default_logger;
62 } 63 }
63 64
64 // static 65 // static
66 void Environment::SetDefaultLogger(const MojoLogger* logger) {
67 assert(g_default_logger); // Fails if not "inside" |Environment|.
68 assert(logger);
viettrungluu 2015/11/17 22:33:33 Maybe setting it to null should mean using &intern
vardhan 2015/12/02 00:06:13 sounds right (Done.)
69 g_default_logger = logger;
70 }
71
72 // static
65 void Environment::InstantiateDefaultRunLoop() { 73 void Environment::InstantiateDefaultRunLoop() {
66 assert(!RunLoop::current()); 74 assert(!RunLoop::current());
67 // Not leaked: accessible from |RunLoop::current()|. 75 // Not leaked: accessible from |RunLoop::current()|.
68 RunLoop* run_loop = new RunLoop(); 76 RunLoop* run_loop = new RunLoop();
69 MOJO_ALLOW_UNUSED_LOCAL(run_loop); 77 MOJO_ALLOW_UNUSED_LOCAL(run_loop);
70 assert(run_loop == RunLoop::current()); 78 assert(run_loop == RunLoop::current());
71 } 79 }
72 80
73 // static 81 // static
74 void Environment::DestroyDefaultRunLoop() { 82 void Environment::DestroyDefaultRunLoop() {
75 assert(RunLoop::current()); 83 assert(RunLoop::current());
76 delete RunLoop::current(); 84 delete RunLoop::current();
77 assert(!RunLoop::current()); 85 assert(!RunLoop::current());
78 } 86 }
79 87
80 } // namespace mojo 88 } // namespace mojo
OLDNEW
« no previous file with comments | « mojo/public/cpp/environment/environment.h ('k') | mojo/public/cpp/environment/lib/logging.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698