From 0c7bff02710f8ad7915e215f723b6abad0079221 Mon Sep 17 00:00:00 2001 From: Stephan Bergmann Date: Wed, 23 Nov 2011 15:45:43 +0100 Subject: Changed sal/log.h -> sal/log.hxx, drop _S from C++ streaming log macros. A compile time check ensures the common case of streaming just a plain C-style string literal still produces reasonably compact call-site code. The format-string variants are still available in sal/detail/log.h, but only to be used in obsolete osl/diagnose.h etc., and going to be removed again eventually. --- sal/inc/osl/diagnose.h | 17 ++- sal/inc/osl/diagnose.hxx | 2 +- sal/inc/rtl/string.hxx | 2 +- sal/inc/rtl/ustring.hxx | 2 +- sal/inc/sal/detail/log.h | 111 ++++++++++++++ sal/inc/sal/log.h | 300 ------------------------------------- sal/inc/sal/log.hxx | 263 +++++++++++++++++++++++++++++++++ sal/osl/all/log.cxx | 3 +- sal/osl/all/logformat.hxx | 2 +- sal/osl/all/trace.cxx | 3 +- sal/osl/unx/conditn.c | 347 ------------------------------------------- sal/osl/unx/conditn.cxx | 360 +++++++++++++++++++++++++++++++++++++++++++++ sal/prj/d.lst | 3 + sal/rtl/source/logfile.cxx | 6 +- 14 files changed, 757 insertions(+), 664 deletions(-) create mode 100644 sal/inc/sal/detail/log.h delete mode 100644 sal/inc/sal/log.h create mode 100644 sal/inc/sal/log.hxx delete mode 100644 sal/osl/unx/conditn.c create mode 100644 sal/osl/unx/conditn.cxx (limited to 'sal') diff --git a/sal/inc/osl/diagnose.h b/sal/inc/osl/diagnose.h index 0e1fc443e67e..12357aa9bd61 100644 --- a/sal/inc/osl/diagnose.h +++ b/sal/inc/osl/diagnose.h @@ -32,7 +32,7 @@ #include "sal/config.h" -#include +#include #include /** provides simple diagnostic support @@ -42,7 +42,7 @@ if an assertion fails, and is controlled by the standard NDEBUG macro). Logging of warnings (e.g., about malformed input) and traces (e.g., about steps taken while executing some protocol) should use the facilities - provided by sal/log.h. + provided by (C++ only) sal/log.hxx. Because the assertion macros (OSL_ASSERT, OSL_ENSURE, OSL_FAIL, OSL_PRECOND, and OSL_POSTCOND) have been used for true assertions as well as for logged @@ -139,19 +139,20 @@ pfunc_osl_printDetailedDebugMessage SAL_CALL osl_setDetailedDebugMessageFunc( pf /* the macro OSL_LOG_PREFIX is intended to be an office internal macro for now - it is deprecated and superseded by SAL_WHERE + it is deprecated and superseded by (C++ only) SAL_WHERE */ -#define OSL_LOG_PREFIX SAL_WHERE +#define OSL_LOG_PREFIX SAL_DETAIL_WHERE #define OSL_DEBUG_ONLY(s) _OSL_DEBUG_ONLY(s) #define OSL_TRACE(...) \ - SAL_INFO_IF(OSL_DEBUG_LEVEL > 0, "legacy.osl", __VA_ARGS__) + SAL_DETAIL_INFO_IF_FORMAT(OSL_DEBUG_LEVEL > 0, "legacy.osl", __VA_ARGS__) #if OSL_DEBUG_LEVEL > 0 -#define OSL_ASSERT(c) SAL_WARN_IF(!(c), "legacy.osl", "OSL_ASSERT") -#define OSL_ENSURE(c, m) SAL_WARN_IF(!(c), "legacy.osl", "%s", m) -#define OSL_FAIL(m) SAL_WARN_IF(sal_True, "legacy.osl", "%s", m) +#define OSL_ASSERT(c) \ + SAL_DETAIL_WARN_IF_FORMAT(!(c), "legacy.osl", "OSL_ASSERT") +#define OSL_ENSURE(c, m) SAL_DETAIL_WARN_IF_FORMAT(!(c), "legacy.osl", "%s", m) +#define OSL_FAIL(m) SAL_DETAIL_WARN_IF_FORMAT(sal_True, "legacy.osl", "%s", m) #else #define OSL_ASSERT(c) ((void) 0) #define OSL_ENSURE(c, m) ((void) 0) diff --git a/sal/inc/osl/diagnose.hxx b/sal/inc/osl/diagnose.hxx index 42e4b8dd7f2f..45a6fdd3cf7c 100644 --- a/sal/inc/osl/diagnose.hxx +++ b/sal/inc/osl/diagnose.hxx @@ -39,7 +39,7 @@ #include "osl/mutex.hxx" #include "rtl/allocator.hxx" #include "rtl/instance.hxx" -#include "sal/log.h" +#include "sal/log.hxx" #include "sal/types.h" namespace osl { diff --git a/sal/inc/rtl/string.hxx b/sal/inc/rtl/string.hxx index 007129a7dc0f..0db8341a8930 100644 --- a/sal/inc/rtl/string.hxx +++ b/sal/inc/rtl/string.hxx @@ -37,7 +37,7 @@ #include #include #include -#include "sal/log.h" +#include "sal/log.hxx" #if !defined EXCEPTIONS_OFF #include diff --git a/sal/inc/rtl/ustring.hxx b/sal/inc/rtl/ustring.hxx index ef13dd1da387..868f6dd043cd 100644 --- a/sal/inc/rtl/ustring.hxx +++ b/sal/inc/rtl/ustring.hxx @@ -37,7 +37,7 @@ #include #include #include -#include "sal/log.h" +#include "sal/log.hxx" #if defined EXCEPTIONS_OFF #include diff --git a/sal/inc/sal/detail/log.h b/sal/inc/sal/detail/log.h new file mode 100644 index 000000000000..bc51b89b6b14 --- /dev/null +++ b/sal/inc/sal/detail/log.h @@ -0,0 +1,111 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * Version: MPL 1.1 / GPLv3+ / LGPLv3+ + * + * The contents of this file are subject to the Mozilla Public License Version + * 1.1 (the "License"); you may not use this file except in compliance with + * the License or as specified alternatively below. You may obtain a copy of + * the License at http://www.mozilla.org/MPL/ + * + * Software distributed under the License is distributed on an "AS IS" basis, + * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License + * for the specific language governing rights and limitations under the + * License. + * + * Major Contributor(s): + * [ Copyright (C) 2011 Stephan Bergmann, Red Hat (initial + * developer) ] + * + * All Rights Reserved. + * + * For minor contributions see the git repository. + * + * Alternatively, the contents of this file may be used under the terms of + * either the GNU General Public License Version 3 or later (the "GPLv3+"), or + * the GNU Lesser General Public License Version 3 or later (the "LGPLv3+"), + * in which case the provisions of the GPLv3+ or the LGPLv3+ are applicable + * instead of those above. + */ + +#ifndef INCLUDED_SAL_DETAIL_LOG_H +#define INCLUDED_SAL_DETAIL_LOG_H + +#include "sal/config.h" + +#include "sal/types.h" + +/** @internal */ + +/* This header makes available replacements working in both C and C++ for the + obsolete osl/diagnose.h functionality that in turn is used from both C and + C++ code and the obsolete tools/debug.hxx and + canvas/inc/canvas/verbosetrace.hxx functionality that uses printf-style + formatting. Once that obsolete functionality is removed, this header can be + removed, too. + + This header uses variadic macros in both C (where they are officially only + supported since C99) and C++ (where they are officially only supported since + C++11). It appears that all relevant compilers (esp. GCC 4.0 and MS VS 2008 + Express) already support them in their C and C++ dialects. See also + . + + Avoid the use of other sal code in this header as much as possible, so that + this code can be called from other sal code without causing endless + recursion. +*/ + +#if defined __cplusplus +extern "C" { +#endif + +enum sal_detail_LogLevel { + SAL_DETAIL_LOG_LEVEL_INFO, SAL_DETAIL_LOG_LEVEL_WARN, + SAL_DETAIL_MAKE_FIXED_SIZE = SAL_MAX_ENUM +}; + +void SAL_CALL sal_detail_logFormat( + enum sal_detail_LogLevel level, char const * area, char const * where, + char const * format, ...) +/* TODO: enabling this will produce a huge amount of -Werror=format errors: */ +#if defined GCC && 0 + __attribute__((format(printf, 4, 5))) +#endif + ; + +#if defined __cplusplus +} +#endif + +#define SAL_DETAIL_LOG_FORMAT(condition, level, area, where, ...) \ + do { \ + if (condition) { \ + sal_detail_logFormat((level), (area), (where), __VA_ARGS__); \ + } \ + } while (sal_False) + +#if defined SAL_LOG_INFO +#define SAL_DETAIL_ENABLE_LOG_INFO sal_True +#else +#define SAL_DETAIL_ENABLE_LOG_INFO sal_False +#endif +#if defined SAL_LOG_WARN +#define SAL_DETAIL_ENABLE_LOG_WARN sal_True +#else +#define SAL_DETAIL_ENABLE_LOG_WARN sal_False +#endif + +#define SAL_DETAIL_WHERE __FILE__ ":" SAL_STRINGIFY(__LINE__) ": " + +#define SAL_DETAIL_INFO_IF_FORMAT(condition, area, ...) \ + SAL_DETAIL_LOG_FORMAT( \ + SAL_DETAIL_ENABLE_LOG_INFO && (condition), SAL_DETAIL_LOG_LEVEL_INFO, \ + area, SAL_DETAIL_WHERE, __VA_ARGS__) + +#define SAL_DETAIL_WARN_IF_FORMAT(condition, area, ...) \ + SAL_DETAIL_LOG_FORMAT( \ + SAL_DETAIL_ENABLE_LOG_WARN && (condition), SAL_DETAIL_LOG_LEVEL_WARN, \ + area, SAL_DETAIL_WHERE, __VA_ARGS__) + +#endif + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/sal/inc/sal/log.h b/sal/inc/sal/log.h deleted file mode 100644 index d63ed6b32752..000000000000 --- a/sal/inc/sal/log.h +++ /dev/null @@ -1,300 +0,0 @@ -/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ -/* - * Version: MPL 1.1 / GPLv3+ / LGPLv3+ - * - * The contents of this file are subject to the Mozilla Public License Version - * 1.1 (the "License"); you may not use this file except in compliance with - * the License or as specified alternatively below. You may obtain a copy of - * the License at http://www.mozilla.org/MPL/ - * - * Software distributed under the License is distributed on an "AS IS" basis, - * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License - * for the specific language governing rights and limitations under the - * License. - * - * Major Contributor(s): - * [ Copyright (C) 2011 Stephan Bergmann, Red Hat (initial - * developer) ] - * - * All Rights Reserved. - * - * For minor contributions see the git repository. - * - * Alternatively, the contents of this file may be used under the terms of - * either the GNU General Public License Version 3 or later (the "GPLv3+"), or - * the GNU Lesser General Public License Version 3 or later (the "LGPLv3+"), - * in which case the provisions of the GPLv3+ or the LGPLv3+ are applicable - * instead of those above. - */ - -#ifndef INCLUDED_SAL_LOG_H -#define INCLUDED_SAL_LOG_H - -#include "sal/config.h" - -#if defined __cplusplus -#include -#include -#endif - -#include "sal/types.h" - -/* This header uses variadic macros in both C (where they are officially only - supported since C99) and C++ (where they are officially only supported since - C++11). It appears that all relevant compilers (esp. GCC 4.0 and MS VS 2008 - Express) already support them in their C and C++ dialects. See also - . - - Avoid the use of other sal code in this header as much as possible, so that - this code can be called from other sal code without causing endless - recursion. -*/ - -#if defined __cplusplus -extern "C" { -#endif - -/** @internal */ -enum sal_detail_LogLevel { - SAL_DETAIL_LOG_LEVEL_INFO, SAL_DETAIL_LOG_LEVEL_WARN, - SAL_DETAIL_MAKE_FIXED_SIZE = SAL_MAX_ENUM -}; - -/** @internal */ -void SAL_CALL sal_detail_log( - enum sal_detail_LogLevel level, char const * area, char const * where, - char const * message); - -/** @internal */ -void SAL_CALL sal_detail_logFormat( - enum sal_detail_LogLevel level, char const * area, char const * where, - char const * format, ...) -/* TODO: enabling this will produce a huge amount of -Werror=format errors: */ -#if defined GCC && 0 - __attribute__((format(printf, 4, 5))) -#endif - ; - -#if defined __cplusplus -} -#endif - -/** @internal */ -#define SAL_DETAIL_LOG_FORMAT(condition, level, area, where, ...) \ - do { \ - if (condition) { \ - sal_detail_logFormat((level), (area), (where), __VA_ARGS__); \ - } \ - } while (sal_False) - -#if defined __cplusplus - -namespace sal { namespace detail { - -/// @internal -inline void SAL_CALL log( - sal_detail_LogLevel level, char const * area, char const * where, - std::ostringstream const & stream) -{ - // An alternative would be to have sal_detail_log take a std::ostringstream - // pointer (via a C void pointer); the advantage would be smaller client - // code (the ".str().c_str()" part would move into the implementation of - // sal_detail_log) and potential for proper support of embedded null - // characters within the message, but the disadvantage would be dependence - // on the C++ ABI; as a compromise, the ".str().c_str()" part has been moved - // to this inline function so that it is potentially only emitted once per - // dynamic library: - sal_detail_log(level, area, where, stream.str().c_str()); -} - -} } - -/// @internal -#define SAL_DETAIL_LOG_STREAM(condition, level, area, where, stream) \ - do { \ - if (condition) { \ - ::std::ostringstream sal_detail_stream; \ - sal_detail_stream << stream; \ - ::sal::detail::log((level), (area), (where), sal_detail_stream); \ - } \ - } while (false) - -#endif - -/** @internal */ -#if defined SAL_LOG_INFO -#define SAL_DETAIL_ENABLE_LOG_INFO sal_True -#else -#define SAL_DETAIL_ENABLE_LOG_INFO sal_False -#endif -#if defined SAL_LOG_WARN -#define SAL_DETAIL_ENABLE_LOG_WARN sal_True -#else -#define SAL_DETAIL_ENABLE_LOG_WARN sal_False -#endif - -/** A simple macro to create a "file and line number" string. - - Potentially not only useful within the log framework (where it is used - automatically), but also when creating exception messages. - - @since LibreOffice 3.5 -*/ -#define SAL_WHERE __FILE__ ":" SAL_STRINGIFY(__LINE__) ": " - -#if defined __cplusplus - -/** A facility for generating temporary string messages by piping items into a - C++ std::ostringstream. - - This can be useful for example in a call to SAL_INFO_S when depending on - some boolean condition data of incompatible types shall be streamed into the - message, as in: - - SAL_INFO_S( - "foo", "object: " << (hasName ? obj->name : SAL_STREAM(obj))); - - @since LibreOffice 3.5 -*/ -#define SAL_STREAM(stream) \ - (dynamic_cast< ::std::ostringstream & >(::std::ostringstream() << stream). \ - str()) - -#endif - -/** Basic logging functionality. - - SAL_INFO(char const * area, char const * format, ...), - SAL_INFO_IF(bool condition, char const * area, char const * format, ...), - SAL_WARN(char const * area, char const * format, ...), and - SAL_WARN_IF(bool condition, char const * area, char const * format, ...) - produce an info resp. warning log entry with a printf-style message. The - given format argument and any following arguments must be so that that - sequence of arguments would be appropriate for a call to printf. - - SAL_INFO_S(char const * area, expr), - SAL_INFO_IF_S(bool condition, char const * area, expr), - SAL_WARN_S(char const * area, expr), and - SAL_WARN_IF_S(bool condition, char const * area, expr) produce an info resp. - warning log entry with a message produced by piping items into a C++ - std::ostringstream (and are only available in C++). The given expr must be - so that the full expression "stream << expr" is valid, where stream is a - variable of type std::ostringstream. - - SAL_INFO_S("foo", "string " << s << " of length " << n) - - would be an example of such a call; if the given s is of type rtl::OUString, - - #include "rtl/oustringostreaminserter.hxx" - - would make sure that an appropriate operator << is available. - - In either case, the composed message should be in UTF-8 and it should - contain no vertical formatting characters and no null characters - - For the _IF variants, log output is only generated if the given condition is - true (in addition to the other conditions that have to be met). - - For all these macros, the given area argument must be non-null and must - match the regular expression - - ::= (".")* - - with - - ::= [0-9a-z]+ - - Whether these macros generate any log output is controlled in a two-stage - process. - - First, at compile time the macros SAL_LOG_INFO and SAL_LOG_WARN, - respectively, control whether the INFO and WARN macros, respectively, - expand to actual code (in case the macro is defined, to any value) or to - no-ops (in case the macro is not defined). - - Second, at runtime the environment variable SAL_LOG further limits which - macro calls actually generate log output. The environment variable SAL_LOG - must either be unset or must match the regular expression - - ::= * - - with - - ::= (".")? - ::= "+"|"-" - ::= "INFO"|"WARN" - - If the environment variable is unset, "+WARN" is used instead (which results - in all warnings being output but no infos). If the given value does not - match the regular expression, "+INFO+WARN" is used instead (which in turn - results in everything being output). - - A given macro call's level (INFO or WARN) and area is matched against the - given switches as follows: Only those switches for which the level matches - the given level and for which the area is a prefix (including both empty and - full prefixes) of the given area are considered. Log output is generated if - and only if among the longest such switches (if any), there is at least one - that has a sense of "+". (That is, if both +INFO.foo and -INFO.foo are - present, +INFO.foo wins.) - - For example, if SAL_LOG is "+INFO-INFO.foo+INFO.foo.bar", then calls like - SAL_INFO("foo.bar", ...), SAL_INFO("foo.bar.baz", ...), or - SAL_INFO("other", ...) generate output, while calls like - SAL_INFO("foo", ...) or SAL_INFO("foo.barzzz", ...) do not. - - The generated log output consists of the given level ("info" or "warn"), the - given area, the process ID, the thread ID, the source file, and the source - line number, each followed by a colon, followed by a space, the given - message, and a newline. The precise format of the log output is subject to - change. The log output is printed to stderr without further text encoding - conversion. - - @since LibreOffice 3.5 -*/ - -#define SAL_INFO(area, ...) \ - SAL_DETAIL_LOG_FORMAT( \ - SAL_DETAIL_ENABLE_LOG_INFO, SAL_DETAIL_LOG_LEVEL_INFO, area, \ - SAL_WHERE, __VA_ARGS__) - -#define SAL_INFO_IF(condition, area, ...) \ - SAL_DETAIL_LOG_FORMAT( \ - SAL_DETAIL_ENABLE_LOG_INFO && (condition), SAL_DETAIL_LOG_LEVEL_INFO, \ - area, SAL_WHERE, __VA_ARGS__) - -#define SAL_WARN(area, ...) \ - SAL_DETAIL_LOG_FORMAT( \ - SAL_DETAIL_ENABLE_LOG_WARN, SAL_DETAIL_LOG_LEVEL_WARN, area, \ - SAL_WHERE, __VA_ARGS__) - -#define SAL_WARN_IF(condition, area, ...) \ - SAL_DETAIL_LOG_FORMAT( \ - SAL_DETAIL_ENABLE_LOG_WARN && (condition), SAL_DETAIL_LOG_LEVEL_WARN, \ - area, SAL_WHERE, __VA_ARGS__) - -#if defined __cplusplus - -#define SAL_INFO_S(area, stream) \ - SAL_DETAIL_LOG_STREAM( \ - SAL_DETAIL_ENABLE_LOG_INFO, ::SAL_DETAIL_LOG_LEVEL_INFO, area, \ - SAL_WHERE, stream) - -#define SAL_INFO_IF_S(condition, area, stream) \ - SAL_DETAIL_LOG_STREAM( \ - SAL_DETAIL_ENABLE_LOG_INFO && (condition), \ - ::SAL_DETAIL_LOG_LEVEL_INFO, area, SAL_WHERE, stream) - -#define SAL_WARN_S(area, stream) \ - SAL_DETAIL_LOG_STREAM( \ - SAL_DETAIL_ENABLE_LOG_WARN, ::SAL_DETAIL_LOG_LEVEL_WARN, area, \ - SAL_WHERE, stream) - -#define SAL_WARN_IF_S(condition, area, stream) \ - SAL_DETAIL_LOG_STREAM( \ - SAL_DETAIL_ENABLE_LOG_WARN && (condition), \ - ::SAL_DETAIL_LOG_LEVEL_WARN, area, SAL_WHERE, stream) -#endif - -#endif - -/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/sal/inc/sal/log.hxx b/sal/inc/sal/log.hxx new file mode 100644 index 000000000000..be71d021d560 --- /dev/null +++ b/sal/inc/sal/log.hxx @@ -0,0 +1,263 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * Version: MPL 1.1 / GPLv3+ / LGPLv3+ + * + * The contents of this file are subject to the Mozilla Public License Version + * 1.1 (the "License"); you may not use this file except in compliance with + * the License or as specified alternatively below. You may obtain a copy of + * the License at http://www.mozilla.org/MPL/ + * + * Software distributed under the License is distributed on an "AS IS" basis, + * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License + * for the specific language governing rights and limitations under the + * License. + * + * Major Contributor(s): + * [ Copyright (C) 2011 Stephan Bergmann, Red Hat (initial + * developer) ] + * + * All Rights Reserved. + * + * For minor contributions see the git repository. + * + * Alternatively, the contents of this file may be used under the terms of + * either the GNU General Public License Version 3 or later (the "GPLv3+"), or + * the GNU Lesser General Public License Version 3 or later (the "LGPLv3+"), + * in which case the provisions of the GPLv3+ or the LGPLv3+ are applicable + * instead of those above. + */ + +#ifndef INCLUDED_SAL_LOG_HXX +#define INCLUDED_SAL_LOG_HXX + +#include "sal/config.h" + +#include +#include +#include + +#include "sal/detail/log.h" +#include "sal/types.h" + +// Avoid the use of other sal code in this header as much as possible, so that +// this code can be called from other sal code without causing endless +// recursion. + +/// @internal +extern "C" void SAL_CALL sal_detail_log( + enum sal_detail_LogLevel level, char const * area, char const * where, + char const * message); + +/// @internal +namespace sal { namespace detail { + +inline void SAL_CALL log( + sal_detail_LogLevel level, char const * area, char const * where, + std::ostringstream const & stream) +{ + // An alternative would be to have sal_detail_log take a std::ostringstream + // pointer (via a C void pointer); the advantage would be smaller client + // code (the ".str().c_str()" part would move into the implementation of + // sal_detail_log) and potential for proper support of embedded null + // characters within the message, but the disadvantage would be dependence + // on the C++ ABI; as a compromise, the ".str().c_str()" part has been moved + // to this inline function so that it is potentially only emitted once per + // dynamic library: + sal_detail_log(level, area, where, stream.str().c_str()); +} + +// Special handling of the common case where the message consists of just a +// string literal, to produce smaller call-site code: + +struct StreamStart {}; + +struct StreamString { + StreamString(char const * s): string(s) {} + + char const * string; + + typedef char Result; +}; + +struct StreamIgnore { + typedef struct { char a[2]; } Result; +}; + +inline StreamString operator <<(StreamStart const &, char const * s) { + return StreamString(s); +} + +template< typename T > inline StreamIgnore operator <<( + StreamStart const &, T const &) +{ + std::abort(); +} + +template< typename T > inline StreamIgnore operator <<( + StreamString const &, T const &) +{ + std::abort(); +} + +template< typename T > inline StreamIgnore operator <<( + StreamIgnore const &, T const &) +{ + std::abort(); +} + +template< typename T > typename T::Result getResult(T const &); + +inline char const * unwrapStream(StreamString const & s) { return s.string; } + +inline char const * unwrapStream(StreamIgnore const &) { std::abort(); } + +} } + +/// @internal +#define SAL_DETAIL_LOG_STREAM(condition, level, area, where, stream) \ + do { \ + if (condition) { \ + if (sizeof getResult(::sal::detail::StreamStart() << stream) == 1) \ + { \ + ::sal_detail_log( \ + (level), (area), (where), \ + ::sal::detail::unwrapStream( \ + ::sal::detail::StreamStart() << stream)); \ + } else { \ + ::std::ostringstream sal_detail_stream; \ + sal_detail_stream << stream; \ + ::sal::detail::log( \ + (level), (area), (where), sal_detail_stream); \ + } \ + } \ + } while (false) + +/** A simple macro to create a "file and line number" string. + + Potentially not only useful within the log framework (where it is used + automatically), but also when creating exception messages. + + @since LibreOffice 3.5 +*/ +#define SAL_WHERE SAL_DETAIL_WHERE + +/** A facility for generating temporary string messages by piping items into a + C++ std::ostringstream. + + This can be useful for example in a call to SAL_INFO when depending on some + boolean condition data of incompatible types shall be streamed into the + message, as in: + + SAL_INFO("foo", "object: " << (hasName ? obj->name : SAL_STREAM(obj))); + + @since LibreOffice 3.5 +*/ +#define SAL_STREAM(stream) \ + (dynamic_cast< ::std::ostringstream & >(::std::ostringstream() << stream). \ + str()) + +/** Basic logging functionality. + + SAL_INFO(char const * area, expr), + SAL_INFO_IF(bool condition, char const * area, expr), + SAL_WARN(char const * area, expr), and + SAL_WARN_IF(bool condition, char const * area, expr) produce an info resp. + warning log entry with a message produced by piping items into a C++ + std::ostringstream. The given expr must be so that the full expression + "stream << expr" is valid, where stream is a variable of type + std::ostringstream. + + SAL_INFO("foo", "string " << s << " of length " << n) + + would be an example of such a call; if the given s is of type rtl::OUString, + + #include "rtl/oustringostreaminserter.hxx" + + would make sure that an appropriate operator << is available. + + In either case, the composed message should be in UTF-8 and it should + contain no vertical formatting characters and no null characters + + For the _IF variants, log output is only generated if the given condition is + true (in addition to the other conditions that have to be met). + + For all these macros, the given area argument must be non-null and must + match the regular expression + + ::= (".")* + + with + + ::= [0-9a-z]+ + + Whether these macros generate any log output is controlled in a two-stage + process. + + First, at compile time the macros SAL_LOG_INFO and SAL_LOG_WARN, + respectively, control whether the INFO and WARN macros, respectively, + expand to actual code (in case the macro is defined, to any value) or to + no-ops (in case the macro is not defined). + + Second, at runtime the environment variable SAL_LOG further limits which + macro calls actually generate log output. The environment variable SAL_LOG + must either be unset or must match the regular expression + + ::= * + + with + + ::= (".")? + ::= "+"|"-" + ::= "INFO"|"WARN" + + If the environment variable is unset, "+WARN" is used instead (which results + in all warnings being output but no infos). If the given value does not + match the regular expression, "+INFO+WARN" is used instead (which in turn + results in everything being output). + + A given macro call's level (INFO or WARN) and area is matched against the + given switches as follows: Only those switches for which the level matches + the given level and for which the area is a prefix (including both empty and + full prefixes) of the given area are considered. Log output is generated if + and only if among the longest such switches (if any), there is at least one + that has a sense of "+". (That is, if both +INFO.foo and -INFO.foo are + present, +INFO.foo wins.) + + For example, if SAL_LOG is "+INFO-INFO.foo+INFO.foo.bar", then calls like + SAL_INFO("foo.bar", ...), SAL_INFO("foo.bar.baz", ...), or + SAL_INFO("other", ...) generate output, while calls like + SAL_INFO("foo", ...) or SAL_INFO("foo.barzzz", ...) do not. + + The generated log output consists of the given level ("info" or "warn"), the + given area, the process ID, the thread ID, the source file, and the source + line number, each followed by a colon, followed by a space, the given + message, and a newline. The precise format of the log output is subject to + change. The log output is printed to stderr without further text encoding + conversion. + + @since LibreOffice 3.5 +*/ + +#define SAL_INFO(area, stream) \ + SAL_DETAIL_LOG_STREAM( \ + SAL_DETAIL_ENABLE_LOG_INFO, ::SAL_DETAIL_LOG_LEVEL_INFO, area, \ + SAL_WHERE, stream) + +#define SAL_INFO_IF(condition, area, stream) \ + SAL_DETAIL_LOG_STREAM( \ + SAL_DETAIL_ENABLE_LOG_INFO && (condition), \ + ::SAL_DETAIL_LOG_LEVEL_INFO, area, SAL_WHERE, stream) + +#define SAL_WARN(area, stream) \ + SAL_DETAIL_LOG_STREAM( \ + SAL_DETAIL_ENABLE_LOG_WARN, ::SAL_DETAIL_LOG_LEVEL_WARN, area, \ + SAL_WHERE, stream) + +#define SAL_WARN_IF(condition, area, stream) \ + SAL_DETAIL_LOG_STREAM( \ + SAL_DETAIL_ENABLE_LOG_WARN && (condition), \ + ::SAL_DETAIL_LOG_LEVEL_WARN, area, SAL_WHERE, stream) + +#endif + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/sal/osl/all/log.cxx b/sal/osl/all/log.cxx index be45cf629b81..a43964436842 100644 --- a/sal/osl/all/log.cxx +++ b/sal/osl/all/log.cxx @@ -42,7 +42,8 @@ #include "osl/thread.hxx" #include "rtl/string.h" -#include "sal/log.h" +#include "sal/detail/log.h" +#include "sal/log.hxx" #include "sal/types.h" #include "logformat.hxx" diff --git a/sal/osl/all/logformat.hxx b/sal/osl/all/logformat.hxx index f4589a7b9f94..bb6ea4cc6bdd 100644 --- a/sal/osl/all/logformat.hxx +++ b/sal/osl/all/logformat.hxx @@ -34,7 +34,7 @@ #include -#include "sal/log.h" +#include "sal/detail/log.h" namespace osl { namespace detail { diff --git a/sal/osl/all/trace.cxx b/sal/osl/all/trace.cxx index 835704779452..8fccb44b68d0 100644 --- a/sal/osl/all/trace.cxx +++ b/sal/osl/all/trace.cxx @@ -33,7 +33,8 @@ #include #include "osl/diagnose.h" -#include "sal/log.h" +#include "sal/detail/log.h" +#include "sal/log.hxx" #include "logformat.hxx" diff --git a/sal/osl/unx/conditn.c b/sal/osl/unx/conditn.c deleted file mode 100644 index d7ab7131938c..000000000000 --- a/sal/osl/unx/conditn.c +++ /dev/null @@ -1,347 +0,0 @@ -/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ -/************************************************************************* - * - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * Copyright 2000, 2010 Oracle and/or its affiliates. - * - * OpenOffice.org - a multi-platform office productivity suite - * - * This file is part of OpenOffice.org. - * - * OpenOffice.org is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License version 3 - * only, as published by the Free Software Foundation. - * - * OpenOffice.org is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Lesser General Public License version 3 for more details - * (a copy is included in the LICENSE file that accompanied this code). - * - * You should have received a copy of the GNU Lesser General Public License - * version 3 along with OpenOffice.org. If not, see - * - * for a copy of the LGPLv3 License. - * - ************************************************************************/ - -#include "sal/config.h" - -#include - -#include "system.h" -#include -#include - -#include -#include - - -typedef struct _oslConditionImpl -{ - pthread_cond_t m_Condition; - pthread_mutex_t m_Lock; - sal_Bool m_State; -} oslConditionImpl; - - -/*****************************************************************************/ -/* osl_createCondition */ -/*****************************************************************************/ -oslCondition SAL_CALL osl_createCondition() -{ - oslConditionImpl* pCond; - int nRet=0; - - pCond = (oslConditionImpl*) malloc(sizeof(oslConditionImpl)); - - if ( pCond == 0 ) - { - SAL_WARN("sal", "std::bad_alloc in C"); - return 0; - } - - pCond->m_State = sal_False; - - /* init condition variable with default attr. (PTHREAD_PROCESS_PRIVAT) */ - nRet = pthread_cond_init(&pCond->m_Condition, PTHREAD_CONDATTR_DEFAULT); - if ( nRet != 0 ) - { - SAL_WARN( - "sal", "pthread_cond_init failed, errno %d, \"%s\"", nRet, - strerror(nRet)); - - free(pCond); - return 0; - } - - nRet = pthread_mutex_init(&pCond->m_Lock, PTHREAD_MUTEXATTR_DEFAULT); - if ( nRet != 0 ) - { - SAL_WARN( - "sal", "pthread_mutex_init failed, errno %d, \"%s\"", nRet, - strerror(nRet)); - - nRet = pthread_cond_destroy(&pCond->m_Condition); - SAL_WARN_IF( - nRet != 0, "sal", "pthread_cond_destroy failed, errno %d, \"%s\"", - nRet, strerror(nRet)); - - free(pCond); - pCond = 0; - } - - return (oslCondition)pCond; -} - -/*****************************************************************************/ -/* osl_destroyCondition */ -/*****************************************************************************/ -void SAL_CALL osl_destroyCondition(oslCondition Condition) -{ - oslConditionImpl* pCond; - int nRet = 0; - - if ( Condition ) - { - pCond = (oslConditionImpl*)Condition; - - nRet = pthread_cond_destroy(&pCond->m_Condition); - SAL_WARN_IF( - nRet != 0, "sal", "pthread_cond_destroy failed, errno %d, \"%s\"", - nRet, strerror(nRet)); - nRet = pthread_mutex_destroy(&pCond->m_Lock); - SAL_WARN_IF( - nRet != 0, "sal", "pthread_mutex_destroy failed, errno %d, \"%s\"", - nRet, strerror(nRet)); - - free(Condition); - } - - return; -} - -/*****************************************************************************/ -/* osl_setCondition */ -/*****************************************************************************/ -sal_Bool SAL_CALL osl_setCondition(oslCondition Condition) -{ - oslConditionImpl* pCond; - int nRet=0; - - assert(Condition); - pCond = (oslConditionImpl*)Condition; - - if ( pCond == 0 ) - { - return sal_False; - } - - nRet = pthread_mutex_lock(&pCond->m_Lock); - if ( nRet != 0 ) - { - SAL_WARN( - "sal", "pthread_mutex_lock failed, errno %d, \"%s\"", nRet, - strerror(nRet)); - return sal_False; - } - - pCond->m_State = sal_True; - nRet = pthread_cond_broadcast(&pCond->m_Condition); - if ( nRet != 0 ) - { - SAL_WARN( - "sal", "pthread_cond_broadcast failed, errno %d, \"%s\"", nRet, - strerror(nRet)); - return sal_False; - } - - nRet = pthread_mutex_unlock(&pCond->m_Lock); - if ( nRet != 0 ) - { - SAL_WARN( - "sal", "pthread_mutex_unlock failed, errno %d, \"%s\"", nRet, - strerror(nRet)); - return sal_False; - } - - return sal_True; - -} - -/*****************************************************************************/ -/* osl_resetCondition */ -/*****************************************************************************/ -sal_Bool SAL_CALL osl_resetCondition(oslCondition Condition) -{ - oslConditionImpl* pCond; - int nRet=0; - - assert(Condition); - - pCond = (oslConditionImpl*)Condition; - - if ( pCond == 0 ) - { - return sal_False; - } - - nRet = pthread_mutex_lock(&pCond->m_Lock); - if ( nRet != 0 ) - { - SAL_WARN( - "sal", "pthread_mutex_lock failed, errno %d, \"%s\"", nRet, - strerror(nRet)); - return sal_False; - } - - pCond->m_State = sal_False; - - nRet = pthread_mutex_unlock(&pCond->m_Lock); - if ( nRet != 0 ) - { - SAL_WARN( - "sal", "pthread_mutex_unlock failed, errno %d, \"%s\"", nRet, - strerror(nRet)); - return sal_False; - } - - return sal_True; -} - -/*****************************************************************************/ -/* osl_waitCondition */ -/*****************************************************************************/ -oslConditionResult SAL_CALL osl_waitCondition(oslCondition Condition, const TimeValue* pTimeout) -{ - oslConditionImpl* pCond; - int nRet=0; - oslConditionResult Result = osl_cond_result_ok; - - assert(Condition); - pCond = (oslConditionImpl*)Condition; - - if ( pCond == 0 ) - { - return osl_cond_result_error; - } - - nRet = pthread_mutex_lock(&pCond->m_Lock); - if ( nRet != 0 ) - { - SAL_WARN( - "sal", "pthread_mutex_lock failed, errno %d, \"%s\"", nRet, - strerror(nRet)); - return osl_cond_result_error; - } - - if ( pTimeout ) - { - if ( ! pCond->m_State ) - { - int ret; - struct timeval tp; - struct timespec to; - - gettimeofday(&tp, NULL); - - SET_TIMESPEC( to, tp.tv_sec + pTimeout->Seconds, - tp.tv_usec * 1000 + pTimeout->Nanosec ); - - /* spurious wake up prevention */ - do - { - ret = pthread_cond_timedwait(&pCond->m_Condition, &pCond->m_Lock, &to); - if ( ret != 0 ) - { - if ( ret == ETIME || ret == ETIMEDOUT ) - { - Result = osl_cond_result_timeout; - nRet = pthread_mutex_unlock(&pCond->m_Lock); - SAL_WARN_IF( - nRet != 0, "sal", - "pthread_mutex_unlock failed, errno %d, \"%s\"", - nRet, strerror(nRet)); - - return Result; - } - else if ( ret != EINTR ) - { - Result = osl_cond_result_error; - nRet = pthread_mutex_unlock(&pCond->m_Lock); - SAL_WARN_IF( - nRet != 0, "sal", - "pthread_mutex_unlock failed, errno %d, \"%s\"", - nRet, strerror(nRet)); - return Result; - } - } - } - while ( !pCond->m_State ); - } - } - else - { - while ( !pCond->m_State ) - { - nRet = pthread_cond_wait(&pCond->m_Condition, &pCond->m_Lock); - if ( nRet != 0 ) - { - SAL_WARN( - "sal", "pthread_cond_wait failed, errno %d, \"%s\"", nRet, - strerror(nRet)); - Result = osl_cond_result_error; - nRet = pthread_mutex_unlock(&pCond->m_Lock); - SAL_WARN_IF( - nRet != 0, "sal", - "pthread_mutex_unlock failed, errno %d, \"%s\"", nRet, - strerror(nRet)); - - return Result; - } - } - } - - nRet = pthread_mutex_unlock(&pCond->m_Lock); - SAL_WARN_IF( - nRet != 0, "sal", "pthread_mutex_unlock failed, errno %d, \"%s\"", nRet, - strerror(nRet)); - - return Result; -} - -/*****************************************************************************/ -/* osl_checkCondition */ -/*****************************************************************************/ -sal_Bool SAL_CALL osl_checkCondition(oslCondition Condition) -{ - sal_Bool State; - oslConditionImpl* pCond; - int nRet=0; - - assert(Condition); - pCond = (oslConditionImpl*)Condition; - - if ( pCond == 0 ) - { - return sal_False; - } - - nRet = pthread_mutex_lock(&pCond->m_Lock); - SAL_WARN_IF( - nRet != 0, "sal", "pthread_mutex_lock failed, errno %d, \"%s\"", nRet, - strerror(nRet)); - - State = pCond->m_State; - - nRet = pthread_mutex_unlock(&pCond->m_Lock); - SAL_WARN_IF( - nRet != 0, "sal", "pthread_mutex_unlock failed, errno %d, \"%s\"", nRet, - strerror(nRet)); - - return State; -} - - -/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/sal/osl/unx/conditn.cxx b/sal/osl/unx/conditn.cxx new file mode 100644 index 000000000000..c6417bfb2f7a --- /dev/null +++ b/sal/osl/unx/conditn.cxx @@ -0,0 +1,360 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * + * for a copy of the LGPLv3 License. + * + ************************************************************************/ + +#include "sal/config.h" + +#include + +#include "system.h" +#include +#include + +#include +#include + + +typedef struct _oslConditionImpl +{ + pthread_cond_t m_Condition; + pthread_mutex_t m_Lock; + sal_Bool m_State; +} oslConditionImpl; + + +/*****************************************************************************/ +/* osl_createCondition */ +/*****************************************************************************/ +oslCondition SAL_CALL osl_createCondition() +{ + oslConditionImpl* pCond; + int nRet=0; + + pCond = (oslConditionImpl*) malloc(sizeof(oslConditionImpl)); + + if ( pCond == 0 ) + { + SAL_WARN("sal", "std::bad_alloc in C"); + return 0; + } + + pCond->m_State = sal_False; + + /* init condition variable with default attr. (PTHREAD_PROCESS_PRIVAT) */ + nRet = pthread_cond_init(&pCond->m_Condition, PTHREAD_CONDATTR_DEFAULT); + if ( nRet != 0 ) + { + SAL_WARN( + "sal", + "pthread_cond_init failed, errno " << nRet << ", \"" + << strerror(nRet) << '"'); + + free(pCond); + return 0; + } + + nRet = pthread_mutex_init(&pCond->m_Lock, PTHREAD_MUTEXATTR_DEFAULT); + if ( nRet != 0 ) + { + SAL_WARN( + "sal", + "pthread_mutex_init failed, errno " << nRet << ", \"" + << strerror(nRet) << '"'); + + nRet = pthread_cond_destroy(&pCond->m_Condition); + SAL_WARN_IF( + nRet != 0, "sal", + "pthread_cond_destroy failed, errno " << nRet << ", \"" + << strerror(nRet) << '"'); + + free(pCond); + pCond = 0; + } + + return (oslCondition)pCond; +} + +/*****************************************************************************/ +/* osl_destroyCondition */ +/*****************************************************************************/ +void SAL_CALL osl_destroyCondition(oslCondition Condition) +{ + oslConditionImpl* pCond; + int nRet = 0; + + if ( Condition ) + { + pCond = (oslConditionImpl*)Condition; + + nRet = pthread_cond_destroy(&pCond->m_Condition); + SAL_WARN_IF( + nRet != 0, "sal", + "pthread_cond_destroy failed, errno " << nRet << ", \"" + << strerror(nRet) << '"'); + nRet = pthread_mutex_destroy(&pCond->m_Lock); + SAL_WARN_IF( + nRet != 0, "sal", + "pthread_mutex_destroy failed, errno " << nRet << ", \"" + << strerror(nRet) << '"'); + + free(Condition); + } + + return; +} + +/*****************************************************************************/ +/* osl_setCondition */ +/*****************************************************************************/ +sal_Bool SAL_CALL osl_setCondition(oslCondition Condition) +{ + oslConditionImpl* pCond; + int nRet=0; + + assert(Condition); + pCond = (oslConditionImpl*)Condition; + + if ( pCond == 0 ) + { + return sal_False; + } + + nRet = pthread_mutex_lock(&pCond->m_Lock); + if ( nRet != 0 ) + { + SAL_WARN( + "sal", + "pthread_mutex_lock failed, errno " << nRet << ", \"" + << strerror(nRet) << '"'); + return sal_False; + } + + pCond->m_State = sal_True; + nRet = pthread_cond_broadcast(&pCond->m_Condition); + if ( nRet != 0 ) + { + SAL_WARN( + "sal", + "pthread_cond_broadcast failed, errno " << nRet << ", \"" + << strerror(nRet) << '"'); + return sal_False; + } + + nRet = pthread_mutex_unlock(&pCond->m_Lock); + if ( nRet != 0 ) + { + SAL_WARN( + "sal", + "pthread_mutex_unlock failed, errno " << nRet << ", \"" + << strerror(nRet) << '"'); + return sal_False; + } + + return sal_True; + +} + +/*****************************************************************************/ +/* osl_resetCondition */ +/*****************************************************************************/ +sal_Bool SAL_CALL osl_resetCondition(oslCondition Condition) +{ + oslConditionImpl* pCond; + int nRet=0; + + assert(Condition); + + pCond = (oslConditionImpl*)Condition; + + if ( pCond == 0 ) + { + return sal_False; + } + + nRet = pthread_mutex_lock(&pCond->m_Lock); + if ( nRet != 0 ) + { + SAL_WARN( + "sal", + "pthread_mutex_lock failed, errno " << nRet << ", \"" + << strerror(nRet) << '"'); + return sal_False; + } + + pCond->m_State = sal_False; + + nRet = pthread_mutex_unlock(&pCond->m_Lock); + if ( nRet != 0 ) + { + SAL_WARN( + "sal", "pthread_mutex_unlock failed, errno " << nRet <<", \"" + << strerror(nRet) << '"'); + return sal_False; + } + + return sal_True; +} + +/*****************************************************************************/ +/* osl_waitCondition */ +/*****************************************************************************/ +oslConditionResult SAL_CALL osl_waitCondition(oslCondition Condition, const TimeValue* pTimeout) +{ + oslConditionImpl* pCond; + int nRet=0; + oslConditionResult Result = osl_cond_result_ok; + + assert(Condition); + pCond = (oslConditionImpl*)Condition; + + if ( pCond == 0 ) + { + return osl_cond_result_error; + } + + nRet = pthread_mutex_lock(&pCond->m_Lock); + if ( nRet != 0 ) + { + SAL_WARN( + "sal", "pthread_mutex_lock failed, errno " << nRet <<", \"" + << strerror(nRet) << '"'); + return osl_cond_result_error; + } + + if ( pTimeout ) + { + if ( ! pCond->m_State ) + { + int ret; + struct timeval tp; + struct timespec to; + + gettimeofday(&tp, NULL); + + SET_TIMESPEC( to, tp.tv_sec + pTimeout->Seconds, + tp.tv_usec * 1000 + pTimeout->Nanosec ); + + /* spurious wake up prevention */ + do + { + ret = pthread_cond_timedwait(&pCond->m_Condition, &pCond->m_Lock, &to); + if ( ret != 0 ) + { + if ( ret == ETIME || ret == ETIMEDOUT ) + { + Result = osl_cond_result_timeout; + nRet = pthread_mutex_unlock(&pCond->m_Lock); + SAL_WARN_IF( + nRet != 0, "sal", + "pthread_mutex_unlock failed, errno " << nRet + << ", \"" << strerror(nRet) << '"'); + + return Result; + } + else if ( ret != EINTR ) + { + Result = osl_cond_result_error; + nRet = pthread_mutex_unlock(&pCond->m_Lock); + SAL_WARN_IF( + nRet != 0, "sal", + "pthread_mutex_unlock failed, errno " << nRet + << ", \"" << strerror(nRet) << '"'); + return Result; + } + } + } + while ( !pCond->m_State ); + } + } + else + { + while ( !pCond->m_State ) + { + nRet = pthread_cond_wait(&pCond->m_Condition, &pCond->m_Lock); + if ( nRet != 0 ) + { + SAL_WARN( + "sal", + "pthread_cond_wait failed, errno " << nRet << ", \"" + << strerror(nRet) << '"'); + Result = osl_cond_result_error; + nRet = pthread_mutex_unlock(&pCond->m_Lock); + SAL_WARN_IF( + nRet != 0, "sal", + "pthread_mutex_unlock failed, errno " << nRet << ", \"" + << strerror(nRet) << '"'); + + return Result; + } + } + } + + nRet = pthread_mutex_unlock(&pCond->m_Lock); + SAL_WARN_IF( + nRet != 0, "sal", + "pthread_mutex_unlock failed, errno " << nRet << ", \"" + << strerror(nRet) << '"'); + + return Result; +} + +/*****************************************************************************/ +/* osl_checkCondition */ +/*****************************************************************************/ +sal_Bool SAL_CALL osl_checkCondition(oslCondition Condition) +{ + sal_Bool State; + oslConditionImpl* pCond; + int nRet=0; + + assert(Condition); + pCond = (oslConditionImpl*)Condition; + + if ( pCond == 0 ) + { + return sal_False; + } + + nRet = pthread_mutex_lock(&pCond->m_Lock); + SAL_WARN_IF( + nRet != 0, "sal", + "pthread_mutex_lock failed, errno " << nRet << ", \"" << strerror(nRet) + << '"'); + + State = pCond->m_State; + + nRet = pthread_mutex_unlock(&pCond->m_Lock); + SAL_WARN_IF( + nRet != 0, "sal", + "pthread_mutex_unlock failed, errno " << nRet << ", \"" + << strerror(nRet) << '"'); + + return State; +} + + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/sal/prj/d.lst b/sal/prj/d.lst index 5023c576b334..c7f93ed06309 100644 --- a/sal/prj/d.lst +++ b/sal/prj/d.lst @@ -1,6 +1,7 @@ mkdir: %_DEST%\bin\cppunit mkdir: %_DEST%\inc\cppunittester mkdir: %_DEST%\inc\sal +mkdir: %_DEST%\inc\sal\detail mkdir: %_DEST%\inc\osl mkdir: %_DEST%\inc\rtl mkdir: %_DEST%\inc\systools @@ -9,7 +10,9 @@ mkdir: %_DEST%\inc\systools\win32 ..\inc\cppunittester\protectorfactory.hxx %_DEST%\inc\protectorfactory.hxx ..\%__SRC%\inc\rtlbootstrap.mk %_DEST%\inc\rtlbootstrap.mk ..\inc\sal\*.h %_DEST%\inc\sal\*.h +..\inc\sal\log.hxx %_DEST%\inc\sal\log.hxx ..\inc\sal\precppunit.hxx %_DEST%\inc\sal\precppunit.hxx +..\inc\sal\detail\log.h %_DEST%\inc\sal\detail\log.h ..\%__SRC%\inc\sal\typesizes.h %_DEST%\inc\sal\typesizes.h ..\inc\osl\*.h %_DEST%\inc\osl\*.h ..\inc\osl\*.hxx %_DEST%\inc\osl\*.hxx diff --git a/sal/rtl/source/logfile.cxx b/sal/rtl/source/logfile.cxx index c5858c1747b8..a9bf40b5a0ee 100644 --- a/sal/rtl/source/logfile.cxx +++ b/sal/rtl/source/logfile.cxx @@ -44,7 +44,7 @@ #include #include #include -#include +#include #include "osl/thread.h" #include @@ -109,7 +109,7 @@ OUString getFileUrl( const OUString &name ) if ( osl_getFileURLFromSystemPath( name.pData, &aRet.pData ) != osl_File_E_None ) { - SAL_WARN_S( + SAL_WARN( "sal", "osl_getFileURLFromSystemPath failed for \"" << name << '"'); } @@ -185,7 +185,7 @@ void init() { } else { - SAL_WARN_S( + SAL_WARN( "sal", "Couldn't open logfile " << o << '(' << e << ')'); } -- cgit