Only in logging/boost-root: bin diff -urb -x Makefile logging.orig/boost-root/boost/log/detail/ts.hpp logging/boost-root/boost/log/detail/ts.hpp --- logging.orig/boost-root/boost/log/detail/ts.hpp 2004-06-30 20:50:02.000000000 -0400 +++ logging/boost-root/boost/log/detail/ts.hpp 2004-10-22 15:39:51.000000000 -0400 @@ -22,7 +22,7 @@ # pragma once #endif -#include +#include #include #include #include @@ -30,92 +30,18 @@ #include +#include +#include // Thread-safety issues namespace boost { namespace log { namespace detail { -class mutex { - mutex & operator = ( const mutex & Not_Implemented); - mutex( const mutex & From); -public: - mutex() { - InitializeCriticalSection( GetCriticalSectionPtr() ); - } - void Lock() { - EnterCriticalSection( GetCriticalSectionPtr()); - } - void Unlock() { - LeaveCriticalSection( GetCriticalSectionPtr()); - } -private: - LPCRITICAL_SECTION GetCriticalSectionPtr() const { return &m_cs; } - mutable CRITICAL_SECTION m_cs; -}; - -class scoped_lock { - scoped_lock operator=( scoped_lock & Not_Implemented); - scoped_lock( const scoped_lock & Not_Implemented); -public: - scoped_lock( mutex & cs) : m_cs( cs) { m_cs.Lock(); } - ~scoped_lock() { m_cs.Unlock(); } -private: - mutex & m_cs; -}; - - - -/* - Global unsigned integer. Its purpose is to be used as a "Change ID", - and to be incremented every time a ***change*** happens. - - However, there will be *no* unneeded thread locks. - - Each thread will have a local ID. It will compare it with this global_uint. - If they match, there was no change (cached content is ok). - Otherwise, some change occured and cached content needs to be updated. - - Remarks - - This is an interesting caching mechanism. Changes won't propagate instantly, - but they will propage. As soon as at least a bit from m_val or m_rev_val - gets changed, we'll know a changed ***happened sometime before***. - That's all we need to know. -*/ -struct global_uint { - global_uint() : m_val(0), m_rev_val(~0) {} - - void increment() { - scoped_lock lock(m_cs); - ++m_val; - m_rev_val = ~m_val; - } - - unsigned int get() const { - unsigned int val = m_val, rev_val = m_rev_val; - if ( ~val == rev_val) - return val; - else { - // someone has incremented it - scoped_lock lock(m_cs); - val = m_val; - rev_val = m_rev_val; - // this should always be preserved - assert( ~val == rev_val); - return val; - } - } - -private: - // value and its bitwise-reversed value - unsigned int m_val, m_rev_val; - mutable mutex m_cs; -}; +typedef boost::mutex mutex; +typedef boost::mutex::scoped_lock scoped_lock; +typedef boost::detail::atomic_count global_uint; // every time a change happens, this gets incremented -global_uint & change_id(); - - - +global_uint& change_id(); typedef std::vector modifiers_array; typedef std::vector log_funcs_array; @@ -196,7 +122,7 @@ // this log information is valid only if m_change_id == change_id().get(); // (ignored for get_main_loglib_info) - unsigned int m_change_id; + long m_change_id; }; Only in logging/boost-root/boost/log/detail: ts.hpp~ diff -urb -x Makefile logging.orig/boost-root/boost/log/functions.hpp logging/boost-root/boost/log/functions.hpp --- logging.orig/boost-root/boost/log/functions.hpp 2004-06-30 20:50:02.000000000 -0400 +++ logging/boost-root/boost/log/functions.hpp 2004-10-22 15:51:08.000000000 -0400 @@ -129,28 +129,24 @@ void append_enter(const string &, string & msg); -// prefixes the message with the time. You pass the format string at construction. +// prefixes the message with the time. You pass the format string at +// construction. // -// The format can contain escape sequences: -// $dd - day, 2 digits -// $MM - month, 2 digits -// $yy - year, 2 digits -// $yyyy - year, 4 digits -// $hh - hour, 2 digits -// $mm - minute, 2 digits -// $ss - second, 2 digits +// The format will be expanded using std::strftime. // -// Example: 'Today is $dd/$MM/$yyyy' +// Example: 'Today is %c' struct prepend_time { - prepend_time(const string & format); + prepend_time(const string & format, bool localtime = true); void operator()(const string &, string & msg); private: // the indexes of each escape sequence within the format string - int m_day, m_month, m_yy, m_yyyy, m_hour, m_min, m_sec; string m_format; + bool m_localtime; char_t m_buffer[256]; + time_t m_t; + tm m_tm; }; Only in logging/boost-root/boost/log: functions.hpp~ Only in logging/boost-root/libs/log/examples/basic_usage: basic_test Only in logging/boost-root/libs/log/examples/basic_usage: define.o diff -urb -x Makefile logging.orig/boost-root/libs/log/examples/basic_usage/init.cpp logging/boost-root/libs/log/examples/basic_usage/init.cpp --- logging.orig/boost-root/libs/log/examples/basic_usage/init.cpp 2004-06-30 20:50:04.000000000 -0400 +++ logging/boost-root/libs/log/examples/basic_usage/init.cpp 2004-10-22 16:17:31.000000000 -0400 @@ -10,7 +10,7 @@ void init_logs() { using namespace boost::log; // all logs prefix the message by time - add_modifier_func("*", prepend_time("$hh:$mm:$ss "), DEFAULT_INDEX + 1 ); + add_modifier_func("*", prepend_time("%Y-%m-%d %H:%M:%S "), DEFAULT_INDEX + 1 ); // all log' messages are prefixed by the log name ("app", or "DEBUG" or "Inf") add_modifier_func("*", &prepend_prefix); @@ -18,6 +18,8 @@ add_log_func("*", write_to_cout); // app messages are also written to file 'out.txt' add_log_func("app", write_to_file("out.txt") ); +#ifdef BOOST_LOG_WIN32 // dbg messages are also written to Output Debug Window add_log_func("DEBUG", write_to_dbg_wnd ); +#endif } Only in logging/boost-root/libs/log/examples/basic_usage: init.o Only in logging/boost-root/libs/log/examples/basic_usage: out.txt Only in logging/boost-root/libs/log/examples/basic_usage: use.o Only in logging/boost-root/libs/log/examples: libboost_log.a Only in logging/boost-root/libs/log/src: Makefile~ diff -urb -x Makefile logging.orig/boost-root/libs/log/src/functions.cpp logging/boost-root/libs/log/src/functions.cpp --- logging.orig/boost-root/libs/log/src/functions.cpp 2004-06-30 20:50:04.000000000 -0400 +++ logging/boost-root/libs/log/src/functions.cpp 2004-10-25 08:29:34.000000000 -0400 @@ -27,10 +27,8 @@ #include #include -#ifndef BOOST_LOG_WIN32 #include #include -#endif namespace boost { namespace log { @@ -46,7 +44,10 @@ void write_to_file::write(const string& msg) { - std::ios::openmode open_type = std::ios::out | (overwrite_file ? 0 : std::ios::app); + std::ios::openmode open_type = std::ios::out; + + if (overwrite_file) + open_type |= std::ios::app; std::basic_ofstream out( file_name.c_str(), open_type); out << msg; @@ -97,15 +98,8 @@ detail::scoped_lock lock( m_info->cs); if ( m_info->h_log != 0) return; // already created -#ifdef BOOST_LOG_WIN32 - DWORD ignore; - m_info->h_log = ::CreateThread( 0, 0, &win32_log_thread, m_info.get(), 0, &ignore); - if ( m_info->h_log != 0) - SetThreadPriority( m_info->h_log, THREAD_PRIORITY_ABOVE_NORMAL); -#else using namespace boost; m_info->h_log = new thread( bind( ts_write::log_thread,m_info.get()) ); -#endif } // make sure the thread gets created and gets a chance to access the info do_sleep(100); @@ -138,29 +132,22 @@ if ( !m_info.unique() ) return; // we'll terminate the thread only when we're the only thread left - // note: even if we're the only object left, we still need to use locks - // there could be another thread: the log_thread; so we still need to be thread-safe + // note: even if we're the only object left, we still need to use + // locks there could be another thread: the log_thread; so we + // still need to be thread-safe int sleep_ms; - HANDLE h; { detail::scoped_lock lock( m_info->cs); if ( m_info->h_log == 0) return; /* this thread was not even started... */ sleep_ms = m_info->sleep_ms; - h = m_info->h_log; m_info->terminated = true; } - // FIXME in the future, when thread library settles down, I could use conditions - - // wait for the other thread to realize this... - do_sleep( sleep_ms + 10); + // FIXME in the future, when thread library settles down, I could + // use conditions -#ifdef BOOST_LOG_WIN32 - DWORD exit_code = 0; - ::GetExitCodeThread(h, &exit_code); - if ( exit_code == STILL_ACTIVE) - ::TerminateThread( h, 0); -#endif + // wait for other thread to exit + m_info->h_log->join (); } @@ -203,94 +190,35 @@ // ... Windows only #if defined(BOOST_LOG_WIN32) void prepend_thread_id(const string &, string & msg) { - std::ostringstream out; out << "[Thread " << ::GetCurrentThreadId() << "] "; - msg = out.str() + msg; - } - + std::ostringstream out; + out << "[Thread " +#if defined (BOOST_HAS_WINTHREADS) + << ::GetCurrentThreadId() +#elif defined (BOOST_HAS_PTHREADS) + << pthread_self () +#elif defined (BOOST_HAS_MPTASKS) + << MPCurrentTaskID() #endif + << "] "; - - - -namespace { - struct index_info { - index_info(int src_idx, int *format_idx, int size = 2) : src_idx(src_idx), format_idx(format_idx), size(size) {} - int src_idx; - int * format_idx; - int size; - }; - bool by_index(const index_info & first, const index_info & second) { - return first.src_idx < second.src_idx; + msg = out.str() + msg; } -} -prepend_time::prepend_time(const string & format) : m_day(-1), m_month(-1), m_yy(-1), m_yyyy(-1), m_hour(-1), m_min(-1), m_sec(-1) { - // format too big - assert( format.size() < 256); - - typedef string::size_type uint; - uint day_idx = format.find("$dd"); - uint month_idx = format.find("$MM"); - uint yy_idx = format.find("$yy"); - uint yyyy_idx = format.find("$yyyy"); - uint hour_idx = format.find("$hh"); - uint min_idx = format.find("$mm"); - uint sec_idx = format.find("$ss"); - - typedef std::vector array; - array indexes; - if ( day_idx != string::npos) - indexes.push_back( index_info(day_idx, &m_day) ); - if ( month_idx != string::npos) - indexes.push_back( index_info(month_idx, &m_month) ); - - if ( yy_idx != string::npos || yyyy_idx != string::npos) - if ( yyyy_idx != string::npos) - indexes.push_back( index_info(yyyy_idx, &m_yyyy, 4) ); - else - indexes.push_back( index_info(yy_idx, &m_yy) ); - - if ( hour_idx != string::npos) - indexes.push_back( index_info(hour_idx, &m_hour ) ); - if ( min_idx != string::npos) - indexes.push_back( index_info(min_idx, &m_min) ); - if ( sec_idx != string::npos) - indexes.push_back( index_info(sec_idx, &m_sec) ); - std::sort( indexes.begin(), indexes.end(), by_index); - - // create the format string, that we can actually pass to sprintf - int prev_idx = 0; - int idx = 0; - for ( array::iterator begin = indexes.begin(), end = indexes.end(); begin != end; ++begin) { - m_format += format.substr( prev_idx, begin->src_idx - prev_idx); - *begin->format_idx = idx; - m_format += (begin->size == 4) ? "%04d" : "%02d"; - prev_idx = begin->src_idx + begin->size + 1; - ++idx; - } +#endif - m_format += format.substr(prev_idx); -} -void prepend_time::operator()(const string &, string & msg) { - time_t t = time(0); - tm details = *localtime( &t); - - int vals[8]; - vals[m_day + 1] = details.tm_mday; - vals[m_month + 1] = details.tm_mon; - vals[m_yy + 1] = details.tm_year; - vals[m_yyyy + 1] = details.tm_year + 1900; - vals[m_hour + 1] = details.tm_hour; - vals[m_min + 1] = details.tm_min; - vals[m_sec + 1] = details.tm_sec; +prepend_time::prepend_time (const string & format, bool localtime) + : m_format (format), m_localtime (localtime) +{} + +void prepend_time::operator() (const string&, string& msg) { + m_t = time (0); + m_tm = m_localtime ? *localtime( &m_t) : *gmtime( &m_t); - // ignore value at index 0 - it's there so that I don't have to test for an index being -1 - sprintf( m_buffer, m_format.c_str(), vals[1], vals[2], vals[3], vals[4], vals[5], vals[6], vals[7] ); + if (0 != strftime (m_buffer, sizeof (m_buffer), m_format.c_str (), &m_tm)) msg = m_buffer + msg; } }} - Only in logging/boost-root/libs/log/src: functions.cpp~ Only in logging/boost-root/libs/log/src: functions.o Only in logging/boost-root/libs/log/src: libboost_log.a diff -urb -x Makefile logging.orig/boost-root/libs/log/src/log.cpp logging/boost-root/libs/log/src/log.cpp --- logging.orig/boost-root/libs/log/src/log.cpp 2004-06-30 20:50:04.000000000 -0400 +++ logging/boost-root/libs/log/src/log.cpp 2004-10-22 16:02:57.000000000 -0400 @@ -93,7 +93,7 @@ maininfo->m_raw_loggers[str][idx].push_back(f); maininfo->re_compute_log_funcs(); } // something changed - change_id().increment(); + ++change_id(); } // adds a function that modifies messages (like, adds a prefix and/or suffix) @@ -103,7 +103,7 @@ maininfo->m_raw_modifiers[str][idx].push_back(f); maininfo->re_compute_modifiers(); } // something changed - change_id().increment(); + ++change_id(); } @@ -131,13 +131,13 @@ void enable_logs(const string & logs_spec) { detail::enable_logs_impl(logs_spec, true); // something changed - change_id().increment(); + ++change_id(); } void disable_logs(const string & logs_spec) { detail::enable_logs_impl(logs_spec, false); // something changed - change_id().increment(); + ++change_id(); } Only in logging/boost-root/libs/log/src: log.cpp~ Only in logging/boost-root/libs/log/src: log.o diff -urb -x Makefile logging.orig/boost-root/libs/log/src/ts.cpp logging/boost-root/libs/log/src/ts.cpp --- logging.orig/boost-root/libs/log/src/ts.cpp 2004-06-30 20:50:04.000000000 -0400 +++ logging/boost-root/libs/log/src/ts.cpp 2004-10-22 16:13:14.000000000 -0400 @@ -26,13 +26,14 @@ // every time a change happens, this gets incremented global_uint & change_id() { - static global_uint g; + static global_uint g (0); return g; } int get_next_unique_id() { - static int id = 0; - return id++; + static boost::detail::atomic_count id (0); + ++id; + return id; } void register_prefix(unsigned int id, const string & prefix) { @@ -48,14 +49,6 @@ } -// our library TLS slot -// -// FIXME - how do I do this using Pthreads? -inline DWORD tls_slot() { - static DWORD slot = TlsAlloc(); - return slot; -} - struct clear_unwritten { template void operator() ( pair & info) const { if ( !info.second.prefix.empty() ) @@ -63,15 +56,15 @@ } }; +boost::thread_specific_ptr thread_loglib_ptr; + // returns the log information for the CURRENT thread loglib_info & thread_loglib() { - loglib_info * tss = reinterpret_cast( TlsGetValue( tls_slot()) ); - if ( tss == 0) { - tss = new loglib_info; - TlsSetValue( tls_slot(), tss); - } + loglib_info *tss = thread_loglib_ptr.get (); + if ( tss == 0) + thread_loglib_ptr.reset (tss = new loglib_info ()); - unsigned int global_id = change_id().get(); + long global_id = change_id(); if ( tss->m_change_id != global_id) { loglib_info * maininfo; { get_main_log get(maininfo); Only in logging/boost-root/libs/log/src: ts.cpp~ Only in logging/boost-root/libs/log/src: ts.o Only in logging: logging-boost-threads.diff Only in logging: logging-boost-threads.diff2