Commit 8dc910a0 authored by Ricardo Cosme's avatar Ricardo Cosme
Browse files

Merge branch 'bbuild' into 02

parents 0b78022a 1e71e044
# -*- coding: iso-8859-1-unix -*-
import common ;
import os ;
import option ;
path-constant here : . ;
path-constant root : $(here)/.. ;
project logger
: requirements
<tag>@tag
<target-os>windows:<pch>off
<target-os>windows,<link>shared:<runtime-link>shared
<target-os>windows,<link>static:<runtime-link>static
<target-os>windows:<debug-store>database
<target-os>windows:<define>_SCL_SECURE_NO_WARNINGS
<define>BOOST_ALL_NO_LIB=1
<debug-symbols>on
<link>shared:<define>LOGGER_SHARED
<define>LOGGER_SOURCE
: usage-requirements
<link>shared:<define>LOGGER_SHARED
;
rule tag ( name : type ? : property-set )
{
if $(type) in STATIC_LIB SHARED_LIB IMPORT_LIB EXE
{
local result ;
local debug ;
local static ;
if <link>static in [ $(property-set).raw ]
{
static = -s ;
}
if <variant>debug in [ $(property-set).raw ]
{
debug = -d ;
}
if <threading>multi in [ $(property-set).raw ]
{
result = [ common.format-name <base>
-mt $(static) $(debug) : $(name) : $(type) : $(property-set) ] ;
}
else
{
result = [ common.format-name <base>
$(static) $(debug) : $(name) : $(type) : $(property-set) ] ;
}
return $(result) ;
}
}
lib logger
: $(root)/src/logger.cpp
/boost//headers
: <include>$(root)/include
<threading>single:<define>LOGGER_DISABLE_THREADS
<threading>multi:<source>/boost//thread
:
: <include>$(root)/include
<threading>single:<define>LOGGER_DISABLE_THREADS
;
install stage : logger ;
# -*- coding: iso-8859-1-unix -*-
import os ;
import path ;
path-constant here : . ;
local boost-root-path = [ os.environ BOOST_ROOT_PATH ] ;
if ! $(boost-root-path)
{
boost-root-path = "$(here)/../boost" ;
}
use-project boost : $(boost-root-path) ;
......@@ -11,7 +11,6 @@
#include <memory>
#include <cstdarg>
#include <list>
#include <map>
#ifndef LOGGER_DISABLE_THREADS
#include <boost/thread.hpp>
......@@ -108,7 +107,7 @@ protected:
class logger
{
#ifndef LOGGER_DISABLE_THREADS
mutable boost::mutex mutex;
boost::mutex mutex;
#endif
/**
......@@ -116,7 +115,7 @@ class logger
*/
level level_;
#ifndef LOGGER_DISABLE_THREADS
std::map<boost::thread::id, std::list<scope_info> > scope_stack;
boost::thread_specific_ptr<std::list<scope_info> > scope_stack;
#else
std::auto_ptr<std::list<scope_info> > scope_stack;
#endif
......
......@@ -10,7 +10,6 @@
#include <log/formatter/add_breakline.h>
#include <boost/utility.hpp>
#include <boost/typeof/typeof.hpp>
#include <functional>
#include <numeric>
......@@ -46,13 +45,6 @@ logger::logger(level l)
scope_token logger::create_scope(const char* label)
{
#ifndef LOGGER_DISABLE_THREADS
boost::lock_guard<boost::mutex> lock(mutex);
std::list<scope_info> &stack(scope_stack[boost::this_thread::get_id()]);
if (stack.size() == 0) stack.push_back(scope_info(""));
stack.push_back(scope_info(label));
scope_token token (boost::prior(stack.end()));
#else
if(!scope_stack.get())
{
scope_stack.reset(new std::list<scope_info>);
......@@ -61,7 +53,6 @@ scope_token logger::create_scope(const char* label)
scope_stack->push_back(scope_info(label));
scope_token token (boost::prior(scope_stack->end()));
#endif
return token;
}
......@@ -84,31 +75,16 @@ struct scope_logical_and
void logger::remove_scope(scope_token const& token)
{
token.scope_iterator->deleted = true;
std::list<scope_info> *stack;
#ifndef LOGGER_DISABLE_THREADS
boost::lock_guard<boost::mutex> lock(mutex);
stack = &scope_stack[boost::this_thread::get_id()];
#else
stack = scope_stack.get();
#endif
if(std::accumulate(token.scope_iterator, stack->end()
if(std::accumulate(token.scope_iterator, scope_stack->end()
, true, scope_logical_and()))
{
stack->erase(token.scope_iterator, stack->end());
scope_stack->erase(token.scope_iterator, scope_stack->end());
}
}
std::size_t logger::identation_level(scope_token const& token) const
{
std::list<scope_info>::const_iterator it;
#ifndef LOGGER_DISABLE_THREADS
BOOST_AUTO(stack, scope_stack.find(boost::this_thread::get_id()));
it = stack->second.begin();
#else
it = scope_stack->begin();
#endif
std::list<scope_info>::const_iterator last(token.scope_iterator);
return std::distance(it, last);
return std::distance(scope_stack->begin(), token.scope_iterator);
}
namespace {
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment