Skip to content

Commit

Permalink
Static initializers: Remove <iostream> include from GPU logging system.
Browse files Browse the repository at this point in the history
GPU can't rely on base because of nacl so it has its own logger. The logger
includes <iostream> in the header, so most gles2 and command buffer files have
std::__ioinit static initializers. Create a common logging.cc which has a
simple method that just returns std::cerr so all the __ioinits collapse down to
one.

BUG=94794
TEST=compiles
R=apatrick
TBR=noelallen

Review URL: http://codereview.chromium.org/7821004

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@99229 0039d316-1c4b-4281-b951-d872f2087c98
  • Loading branch information
erg@google.com committed Sep 1, 2011
1 parent 8ef8d41 commit c279bff
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 10 deletions.
24 changes: 24 additions & 0 deletions gpu/command_buffer/common/logging.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
// Copyright (c) 2011 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#include "gpu/command_buffer/common/logging.h"

#include <iostream>

namespace gpu {

std::ostream& Logger::stream() {
return std::cerr;
}

Logger::~Logger() {
if (!condition_) {
std::cerr << std::endl;
std::cerr.flush();
if (level_ == FATAL)
assert(false);
}
}

} // namespace gpu
18 changes: 8 additions & 10 deletions gpu/command_buffer/common/logging.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

#include <assert.h>

#include <iostream>
#include <ostream>

// Windows defines an ERROR macro.
#ifdef ERROR
Expand Down Expand Up @@ -132,19 +132,17 @@ class Logger {
<< y_name << "(" << y << ")) failed. ";
}

~Logger() {
if (!condition_) {
std::cerr << std::endl;
std::cerr.flush();
if (level_ == FATAL)
assert(false);
}
}
// Retrieves the stream that we write to. This header cannot depend on
// <iostream> because that will add static initializers to all files that
// include this header.
std::ostream& stream();

~Logger();

template <typename T>
Logger& operator<<(const T& value) {
if (!condition_)
std::cerr << value;
stream() << value;
return *this;
}

Expand Down
1 change: 1 addition & 0 deletions gpu/gpu.gyp
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@
'command_buffer/common/gles2_cmd_utils.h',
'command_buffer/common/id_allocator.cc',
'command_buffer/common/id_allocator.h',
'command_buffer/common/logging.cc',
'command_buffer/common/logging.h',
'command_buffer/common/thread_local.h',
'command_buffer/common/types.h',
Expand Down
2 changes: 2 additions & 0 deletions ppapi/native_client/src/shared/ppapi_proxy/nacl.scons
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,8 @@ command_buffer_common_srcs = [
'command_buffer/common/cmd_buffer_common.cc',
'command_buffer/common/gles2_cmd_format.cc',
'command_buffer/common/gles2_cmd_utils.cc',
'command_buffer/common/logging.cc',
'command_buffer/common/logging.h',
]

command_buffer_client_srcs = [
Expand Down

0 comments on commit c279bff

Please sign in to comment.