|
Boost-Commit : |
Subject: [Boost-commit] svn:boost r84919 - in trunk: boost/log/utility libs/log/src
From: andrey.semashev_at_[hidden]
Date: 2013-06-30 11:51:01
Author: andysem
Date: 2013-06-30 11:51:01 EDT (Sun, 30 Jun 2013)
New Revision: 84919
URL: http://svn.boost.org/trac/boost/changeset/84919
Log:
Minor optimizations.
Text files modified:
trunk/boost/log/utility/once_block.hpp | 31 +++++++++++++++----------------
trunk/libs/log/src/once_block.cpp | 28 +++++++++++++++++-----------
2 files changed, 32 insertions(+), 27 deletions(-)
Modified: trunk/boost/log/utility/once_block.hpp
==============================================================================
--- trunk/boost/log/utility/once_block.hpp Sun Jun 30 09:29:25 2013 (r84918)
+++ trunk/boost/log/utility/once_block.hpp 2013-06-30 11:51:01 EDT (Sun, 30 Jun 2013) (r84919)
@@ -76,30 +76,30 @@
once_block_flag& m_flag;
public:
- explicit once_block_sentry(once_block_flag& f) : m_flag(f)
+ explicit once_block_sentry(once_block_flag& f) BOOST_NOEXCEPT : m_flag(f)
{
}
- ~once_block_sentry()
+ ~once_block_sentry() BOOST_NOEXCEPT
{
if (m_flag.status != once_block_flag::initialized)
rollback();
}
- bool executed() const
+ bool executed() const BOOST_NOEXCEPT
{
return (m_flag.status == once_block_flag::initialized || enter_once_block());
}
- BOOST_LOG_API void commit();
+ BOOST_LOG_API void commit() BOOST_NOEXCEPT;
private:
- // Non-copyable, non-assignable
- once_block_sentry(once_block_sentry const&);
- once_block_sentry& operator= (once_block_sentry const&);
+ BOOST_LOG_API bool enter_once_block() const BOOST_NOEXCEPT;
+ BOOST_LOG_API void rollback() BOOST_NOEXCEPT;
- BOOST_LOG_API bool enter_once_block() const;
- BOOST_LOG_API void rollback();
+ // Non-copyable, non-assignable
+ BOOST_LOG_DELETED_FUNCTION(once_block_sentry(once_block_sentry const&))
+ BOOST_LOG_DELETED_FUNCTION(once_block_sentry& operator= (once_block_sentry const&))
};
} // namespace aux
@@ -129,24 +129,23 @@
once_block_flag& m_flag;
public:
- explicit once_block_sentry(once_block_flag& f) : m_flag(f)
+ explicit once_block_sentry(once_block_flag& f) BOOST_NOEXCEPT : m_flag(f)
{
}
- bool executed() const
+ bool executed() const BOOST_NOEXCEPT
{
return m_flag.status;
}
- void commit()
+ void commit() BOOST_NOEXCEPT
{
m_flag.status = true;
}
-private:
// Non-copyable, non-assignable
- once_block_sentry(once_block_sentry const&);
- once_block_sentry& operator= (once_block_sentry const&);
+ BOOST_LOG_DELETED_FUNCTION(once_block_sentry(once_block_sentry const&))
+ BOOST_LOG_DELETED_FUNCTION(once_block_sentry& operator= (once_block_sentry const&))
};
} // namespace aux
@@ -161,7 +160,7 @@
#define BOOST_LOG_ONCE_BLOCK_FLAG_INTERNAL(flag_var, sentry_var)\
for (boost::log::aux::once_block_sentry sentry_var((flag_var));\
- !sentry_var.executed(); sentry_var.commit())
+ BOOST_UNLIKELY(!sentry_var.executed()); sentry_var.commit())
// NOTE: flag_var deliberately doesn't have an initializer so that it is zero-initialized at the static initialization stage
#define BOOST_LOG_ONCE_BLOCK_INTERNAL(flag_var, sentry_var)\
Modified: trunk/libs/log/src/once_block.cpp
==============================================================================
--- trunk/libs/log/src/once_block.cpp Sun Jun 30 09:29:25 2013 (r84918)
+++ trunk/libs/log/src/once_block.cpp 2013-06-30 11:51:01 EDT (Sun, 30 Jun 2013) (r84919)
@@ -18,6 +18,7 @@
#include <boost/log/utility/once_block.hpp>
#ifndef BOOST_LOG_NO_THREADS
+#include <cstdlib>
#include <boost/assert.hpp>
#if defined(BOOST_THREAD_PLATFORM_WIN32)
@@ -42,7 +43,7 @@
} // namespace
-BOOST_LOG_API bool once_block_sentry::enter_once_block() const
+BOOST_LOG_API bool once_block_sentry::enter_once_block() const BOOST_NOEXCEPT
{
AcquireSRWLockExclusive(&g_OnceBlockMutex);
@@ -72,7 +73,7 @@
return true;
}
-BOOST_LOG_API void once_block_sentry::commit()
+BOOST_LOG_API void once_block_sentry::commit() BOOST_NOEXCEPT
{
AcquireSRWLockExclusive(&g_OnceBlockMutex);
@@ -83,7 +84,7 @@
WakeAllConditionVariable(&g_OnceBlockCond);
}
-BOOST_LOG_API void once_block_sentry::rollback()
+BOOST_LOG_API void once_block_sentry::rollback() BOOST_NOEXCEPT
{
AcquireSRWLockExclusive(&g_OnceBlockMutex);
@@ -328,10 +329,10 @@
delete impl;
}
- once_block_impl_base* get_once_block_impl()
+ once_block_impl_base* get_once_block_impl() BOOST_NOEXCEPT
{
once_block_impl_base* impl = g_pOnceBlockImpl;
- if (!impl)
+ if (!impl) try
{
once_block_impl_base* new_impl = create_once_block_impl();
impl = (once_block_impl_base*)
@@ -346,23 +347,28 @@
return new_impl;
}
}
+ catch (...)
+ {
+ BOOST_ASSERT_MSG(false, "Boost.Log: Failed to initialize the once block thread synchronization structures");
+ std::abort();
+ }
return impl;
}
} // namespace
-BOOST_LOG_API bool once_block_sentry::enter_once_block() const
+BOOST_LOG_API bool once_block_sentry::enter_once_block() const BOOST_NOEXCEPT
{
return get_once_block_impl()->enter_once_block(m_flag);
}
-BOOST_LOG_API void once_block_sentry::commit()
+BOOST_LOG_API void once_block_sentry::commit() BOOST_NOEXCEPT
{
get_once_block_impl()->commit(m_flag);
}
-BOOST_LOG_API void once_block_sentry::rollback()
+BOOST_LOG_API void once_block_sentry::rollback() BOOST_NOEXCEPT
{
get_once_block_impl()->rollback(m_flag);
}
@@ -395,7 +401,7 @@
} // namespace
-BOOST_LOG_API bool once_block_sentry::enter_once_block() const
+BOOST_LOG_API bool once_block_sentry::enter_once_block() const BOOST_NOEXCEPT
{
BOOST_VERIFY(!pthread_mutex_lock(&g_OnceBlockMutex));
@@ -424,7 +430,7 @@
return true;
}
-BOOST_LOG_API void once_block_sentry::commit()
+BOOST_LOG_API void once_block_sentry::commit() BOOST_NOEXCEPT
{
BOOST_VERIFY(!pthread_mutex_lock(&g_OnceBlockMutex));
@@ -435,7 +441,7 @@
BOOST_VERIFY(!pthread_cond_broadcast(&g_OnceBlockCond));
}
-BOOST_LOG_API void once_block_sentry::rollback()
+BOOST_LOG_API void once_block_sentry::rollback() BOOST_NOEXCEPT
{
BOOST_VERIFY(!pthread_mutex_lock(&g_OnceBlockMutex));
Boost-Commit list run by bdawes at acm.org, david.abrahams at rcn.com, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk