From 97562928a801e99eb79e79b5c55da49d1c1b28cf Mon Sep 17 00:00:00 2001 From: Michael Glassford Date: Fri, 25 Jun 2004 19:36:47 +0000 Subject: [PATCH] Cleanup: always #include first; eliminate tabs; etc. [SVN r23185] --- include/boost/thread/condition.hpp | 6 +- include/boost/thread/detail/force_cast.hpp | 2 + include/boost/thread/detail/named.hpp | 14 +- include/boost/thread/detail/singleton.hpp | 2 + include/boost/thread/detail/threadmon.hpp | 10 +- include/boost/thread/exceptions.hpp | 1 - include/boost/thread/mutex.hpp | 6 +- include/boost/thread/once.hpp | 4 - include/boost/thread/recursive_mutex.hpp | 6 +- include/boost/thread/shared_memory.hpp | 5 +- include/boost/thread/thread_pool.hpp | 5 - include/boost/thread/tss.hpp | 8 +- include/boost/thread/xtime.hpp | 8 +- src/condition.cpp | 2 + src/exceptions.cpp | 2 + src/mutex.cpp | 2 + src/named.cpp | 165 +++++++++++---------- src/once.cpp | 2 + src/recursive_mutex.cpp | 4 +- src/shared_memory.cpp | 94 ++++++------ src/thread_pool.cpp | 2 + src/threadmon.cpp | 2 +- src/tss.cpp | 6 + src/xtime.cpp | 2 + test/test_thread.cpp | 2 +- 25 files changed, 187 insertions(+), 175 deletions(-) diff --git a/include/boost/thread/condition.hpp b/include/boost/thread/condition.hpp index 2ce274a6..97a7526b 100644 --- a/include/boost/thread/condition.hpp +++ b/include/boost/thread/condition.hpp @@ -12,15 +12,11 @@ #ifndef BOOST_CONDITION_WEK070601_HPP #define BOOST_CONDITION_WEK070601_HPP -#include - -// insist on threading support being available: -#include +#include #include #include #include -#include #if defined(BOOST_HAS_PTHREADS) # include diff --git a/include/boost/thread/detail/force_cast.hpp b/include/boost/thread/detail/force_cast.hpp index 5632fb65..7f0b81a0 100644 --- a/include/boost/thread/detail/force_cast.hpp +++ b/include/boost/thread/detail/force_cast.hpp @@ -14,6 +14,8 @@ #ifndef BOOST_FORCE_CAST_MJM012402_HPP #define BOOST_FORCE_CAST_MJM012402_HPP +#include + namespace boost { namespace detail { namespace thread { diff --git a/include/boost/thread/detail/named.hpp b/include/boost/thread/detail/named.hpp index 6c6573fe..95f50e31 100644 --- a/include/boost/thread/detail/named.hpp +++ b/include/boost/thread/detail/named.hpp @@ -12,22 +12,24 @@ #ifndef BOOST_NAMED_WEK031703_HPP #define BOOST_NAMED_WEK031703_HPP +#include + namespace boost { namespace detail { class named_object { protected: - named_object(const char* name=0); - ~named_object(); + named_object(const char* name=0); + ~named_object(); public: - const char* name() const; - const char* effective_name() const; + const char* name() const; + const char* effective_name() const; protected: - char* m_name; - char* m_ename; + char* m_name; + char* m_ename; }; } // namespace detail diff --git a/include/boost/thread/detail/singleton.hpp b/include/boost/thread/detail/singleton.hpp index f4b589b4..27b72e63 100644 --- a/include/boost/thread/detail/singleton.hpp +++ b/include/boost/thread/detail/singleton.hpp @@ -14,6 +14,8 @@ #ifndef BOOST_SINGLETON_MJM012402_HPP #define BOOST_SINGLETON_MJM012402_HPP +#include + namespace boost { namespace detail { namespace thread { diff --git a/include/boost/thread/detail/threadmon.hpp b/include/boost/thread/detail/threadmon.hpp index 376481d6..46254615 100644 --- a/include/boost/thread/detail/threadmon.hpp +++ b/include/boost/thread/detail/threadmon.hpp @@ -9,17 +9,15 @@ // about the suitability of this software for any purpose. // It is provided "as is" without express or implied warranty. -#include - -// insist on threading support being available: -#include +#ifndef BOOST_THREADMON_WEK062504_HPP +#define BOOST_THREADMON_WEK062504_HPP #include #ifdef BOOST_HAS_WINTHREADS -#include - extern "C" BOOST_THREAD_DECL int on_thread_exit(void (__cdecl * func)(void)); #endif // BOOST_HAS_WINTHREADS + +#endif // BOOST_THREADMON_WEK062504_HPP diff --git a/include/boost/thread/exceptions.hpp b/include/boost/thread/exceptions.hpp index 78b629d5..2296ed30 100644 --- a/include/boost/thread/exceptions.hpp +++ b/include/boost/thread/exceptions.hpp @@ -12,7 +12,6 @@ #ifndef BOOST_THREAD_EXCEPTIONS_PDM070801_H #define BOOST_THREAD_EXCEPTIONS_PDM070801_H -#include #include // pdm: Sorry, but this class is used all over the place & I end up diff --git a/include/boost/thread/mutex.hpp b/include/boost/thread/mutex.hpp index f2c04d12..19428b39 100644 --- a/include/boost/thread/mutex.hpp +++ b/include/boost/thread/mutex.hpp @@ -12,13 +12,9 @@ #ifndef BOOST_MUTEX_WEK070601_HPP #define BOOST_MUTEX_WEK070601_HPP -#include - -// insist on threading support being available: -#include +#include #include -#include #include #include diff --git a/include/boost/thread/once.hpp b/include/boost/thread/once.hpp index 1a1af563..66666f83 100644 --- a/include/boost/thread/once.hpp +++ b/include/boost/thread/once.hpp @@ -12,10 +12,6 @@ #ifndef BOOST_ONCE_WEK080101_HPP #define BOOST_ONCE_WEK080101_HPP -#include -// insist on threading support being available: -#include - #include #if defined(BOOST_HAS_PTHREADS) diff --git a/include/boost/thread/recursive_mutex.hpp b/include/boost/thread/recursive_mutex.hpp index 1f73b924..6a33c792 100644 --- a/include/boost/thread/recursive_mutex.hpp +++ b/include/boost/thread/recursive_mutex.hpp @@ -12,13 +12,9 @@ #ifndef BOOST_RECURSIVE_MUTEX_WEK070601_HPP #define BOOST_RECURSIVE_MUTEX_WEK070601_HPP -#include - -// insist on threading support being available: -#include +#include #include -#include #include #include diff --git a/include/boost/thread/shared_memory.hpp b/include/boost/thread/shared_memory.hpp index 72e940da..b23a085f 100644 --- a/include/boost/thread/shared_memory.hpp +++ b/include/boost/thread/shared_memory.hpp @@ -12,10 +12,7 @@ #ifndef BOOST_MUTEX_JDM062402_HPP #define BOOST_MUTEX_JDM062402_HPP -#include - -// insist on threading support being available: -#include +#include #include #include diff --git a/include/boost/thread/thread_pool.hpp b/include/boost/thread/thread_pool.hpp index 89a17acd..f66dacd4 100644 --- a/include/boost/thread/thread_pool.hpp +++ b/include/boost/thread/thread_pool.hpp @@ -15,11 +15,6 @@ #ifndef BOOST_THREAD_POOL_JDM031802_HPP #define BOOST_THREAD_POOL_JDM031802_HPP -#include - -// insist on threading support being available: -#include - #include #include diff --git a/include/boost/thread/tss.hpp b/include/boost/thread/tss.hpp index dd70cb09..59a7cd5e 100644 --- a/include/boost/thread/tss.hpp +++ b/include/boost/thread/tss.hpp @@ -12,13 +12,10 @@ #ifndef BOOST_TSS_WEK070601_HPP #define BOOST_TSS_WEK070601_HPP -#include - -// insist on threading support being available: -#include - #include +#ifndef BOOST_THREAD_NO_TSS_CLEANUP + #include #include #include @@ -110,6 +107,7 @@ private: } // namespace boost +#endif BOOST_THREAD_NO_TSS_CLEANUP #endif // BOOST_TSS_WEK070601_HPP // Change Log: diff --git a/include/boost/thread/xtime.hpp b/include/boost/thread/xtime.hpp index f250358d..98b52be0 100644 --- a/include/boost/thread/xtime.hpp +++ b/include/boost/thread/xtime.hpp @@ -12,13 +12,13 @@ #ifndef BOOST_XTIME_WEK070601_HPP #define BOOST_XTIME_WEK070601_HPP -#include -#include #include +#include + namespace boost { -enum xtime_clock_types +typedef enum { TIME_UTC=1 // TIME_TAI, @@ -28,7 +28,7 @@ enum xtime_clock_types // TIME_LOCAL, // TIME_SYNC, // TIME_RESOLUTION -}; +} xtime_clock_types; struct xtime { diff --git a/src/condition.cpp b/src/condition.cpp index 7b51b9fa..bb5f2a5e 100644 --- a/src/condition.cpp +++ b/src/condition.cpp @@ -9,6 +9,8 @@ // about the suitability of this software for any purpose. // It is provided "as is" without express or implied warranty. +#include + #include #include #include diff --git a/src/exceptions.cpp b/src/exceptions.cpp index 65fcfbe3..5d251225 100644 --- a/src/exceptions.cpp +++ b/src/exceptions.cpp @@ -9,6 +9,8 @@ // about the suitability of this software for any purpose. // It is provided "as is" without express or implied warranty. +#include + #include #include diff --git a/src/mutex.cpp b/src/mutex.cpp index 282f1df7..08f24878 100644 --- a/src/mutex.cpp +++ b/src/mutex.cpp @@ -9,6 +9,8 @@ // about the suitability of this software for any purpose. // It is provided "as is" without express or implied warranty. +#include + #include #include #include diff --git a/src/named.cpp b/src/named.cpp index 0bc698ba..b629b5f9 100644 --- a/src/named.cpp +++ b/src/named.cpp @@ -1,3 +1,16 @@ +// Copyright (C) 2001-2003 +// William E. Kempf +// +// Permission to use, copy, modify, distribute and sell this software +// and its documentation for any purpose is hereby granted without fee, +// provided that the above copyright notice appear in all copies and +// that both that copyright notice and this permission notice appear +// in supporting documentation. William E. Kempf makes no representations +// about the suitability of this software for any purpose. +// It is provided "as is" without express or implied warranty. + +#include + #include #include #include @@ -6,78 +19,78 @@ namespace { char* concat(char* result, const char* buf) { - if (result == 0) - return strdup(buf); - - int len = strlen(result) + strlen(buf) + 1; - result = (char*)realloc(result, len); - strcat(result, buf); - return result; + if (result == 0) + return strdup(buf); + + int len = strlen(result) + strlen(buf) + 1; + result = (char*)realloc(result, len); + strcat(result, buf); + return result; } char* get_root() { #if defined(BOOST_HAS_WINTHREADS) - return ""; + return ""; #elif defined(BOOST_HAS_PTHREADS) return "/"; #else - return ""; + return ""; #endif } char* encode(const char* str) { - const char* digits="0123456789abcdef"; - char* result=0; - static char buf[100]; - char* ebuf = buf + 100; - char* p = buf; - *p = 0; - strcat(p, get_root()); - p = p + strlen(p); - while (*str) - { - if (((*str >= '0') && (*str <= '9')) || - ((*str >= 'a') && (*str <= 'z')) || - ((*str >= 'A') && (*str <= 'Z')) || - (*str == '/') || (*str == '.') || (*str == '_')) - { - *p = *str; - } - else if (*str == ' ') - { - *p = '+'; - } - else - { - if (p + 3 >= ebuf) - { - *p = 0; - result = concat(result, buf); - p = buf; - } - *p = '%'; - char* e = p + 2; - int v = *str; - while (e > p) - { - *e-- = digits[v % 16]; - v /= 16; - } - p += 2; - } - if (++p == ebuf) - { - *p = 0; - result = concat(result, buf); - p = buf; - } - ++str; - } - *p = 0; - result = concat(result, buf); - return result; + const char* digits="0123456789abcdef"; + char* result=0; + static char buf[100]; + char* ebuf = buf + 100; + char* p = buf; + *p = 0; + strcat(p, get_root()); + p = p + strlen(p); + while (*str) + { + if (((*str >= '0') && (*str <= '9')) || + ((*str >= 'a') && (*str <= 'z')) || + ((*str >= 'A') && (*str <= 'Z')) || + (*str == '/') || (*str == '.') || (*str == '_')) + { + *p = *str; + } + else if (*str == ' ') + { + *p = '+'; + } + else + { + if (p + 3 >= ebuf) + { + *p = 0; + result = concat(result, buf); + p = buf; + } + *p = '%'; + char* e = p + 2; + int v = *str; + while (e > p) + { + *e-- = digits[v % 16]; + v /= 16; + } + p += 2; + } + if (++p == ebuf) + { + *p = 0; + result = concat(result, buf); + p = buf; + } + ++str; + } + *p = 0; + result = concat(result, buf); + return result; } } // namespace @@ -86,36 +99,36 @@ namespace boost { namespace detail { named_object::named_object(const char* name) - : m_name(0), m_ename(0) + : m_name(0), m_ename(0) { - if (name) - { - m_name = strdup(name); - if (*m_name == '%') - m_ename = m_name + 1; - else - m_ename = encode(name); - } + if (name) + { + m_name = strdup(name); + if (*m_name == '%') + m_ename = m_name + 1; + else + m_ename = encode(name); + } } named_object::~named_object() { - if (m_name) - { - if (*m_name != '%') - free(m_ename); - free(m_name); - } + if (m_name) + { + if (*m_name != '%') + free(m_ename); + free(m_name); + } } const char* named_object::name() const { - return m_name; + return m_name; } const char* named_object::effective_name() const { - return m_ename; + return m_ename; } } // namespace detail diff --git a/src/once.cpp b/src/once.cpp index e829542b..f90e8a2a 100644 --- a/src/once.cpp +++ b/src/once.cpp @@ -9,6 +9,8 @@ // about the suitability of this software for any purpose. // It is provided "as is" without express or implied warranty. +#include + #include #include #include diff --git a/src/recursive_mutex.cpp b/src/recursive_mutex.cpp index 6f07eaea..2226602c 100644 --- a/src/recursive_mutex.cpp +++ b/src/recursive_mutex.cpp @@ -9,6 +9,8 @@ // about the suitability of this software for any purpose. // It is provided "as is" without express or implied warranty. +#include + #include #include #include @@ -38,7 +40,7 @@ recursive_mutex::recursive_mutex(const char* name) : boost::detail::named_object(name) , m_mutex(0) , m_count(0) - , m_critical_section(false) + , m_critical_section(false) { m_critical_section = !name; if (m_critical_section) diff --git a/src/shared_memory.cpp b/src/shared_memory.cpp index 916a4010..4622edf5 100644 --- a/src/shared_memory.cpp +++ b/src/shared_memory.cpp @@ -9,6 +9,8 @@ // about the suitability of this software for any purpose. // It is provided "as is" without express or implied warranty. +#include + #include #include #include @@ -33,14 +35,14 @@ namespace boost { shared_memory::shared_memory(const char *name, size_t len, int flags) - : boost::detail::named_object(name) + : boost::detail::named_object(name) { init(len, flags, 0); } shared_memory::shared_memory(const char *name, size_t len, int flags, const boost::function1& initfunc) - : boost::detail::named_object(name) + : boost::detail::named_object(name) { init(len, flags & create, &initfunc); } @@ -121,51 +123,51 @@ void shared_memory::init(size_t len, int flags, #elif defined(BOOST_HAS_PTHREADS) m_len = len; - sem_t* sem = sem_open(mxname.c_str(), O_CREAT); - if (sem == SEM_FAILED) - throw thread_resource_error(); - res = sem_wait(sem); - assert(res == 0); + sem_t* sem = sem_open(mxname.c_str(), O_CREAT); + if (sem == SEM_FAILED) + throw thread_resource_error(); + res = sem_wait(sem); + assert(res == 0); - int oflag = (flags & write) ? O_RDWR : O_RDONLY; - int cflag = (flags & create) ? O_CREAT|O_TRUNC|O_EXCL : 0; - for (;;) - { - m_hmap = shm_open(m_name.c_str(), oflag|cflag, 0); - if (m_hmap == -1) - { - if (errno != EEXIST || (flags & exclusive)) - { - res = sem_post(sem); - assert(res == 0); - res = sem_close(sem); - assert(res == 0); - res = sem_unlink(mxname.c_str()); - assert(res); - throw thread_resource_error(); - } - m_hmap = shm_open(m_name.c_str(), oflag, 0); - if (m_hmap == -1) - { - if (errno == ENOENT) - continue; - res = sem_post(sem); - assert(res == 0); - res = sem_close(sem); - assert(res); - res = sem_unlink(mxname.c_str()); - assert(res); - throw thread_resource_error(); - } - } - else - should_init = true; - break; - } - - ftruncate(m_hmap, len); - int prot = (flags & write) ? PROT_READ|PROT_WRITE : PROT_READ; - m_ptr = mmap(0, m_len, prot, MAP_SHARED, m_hmap, 0); + int oflag = (flags & write) ? O_RDWR : O_RDONLY; + int cflag = (flags & create) ? O_CREAT|O_TRUNC|O_EXCL : 0; + for (;;) + { + m_hmap = shm_open(m_name.c_str(), oflag|cflag, 0); + if (m_hmap == -1) + { + if (errno != EEXIST || (flags & exclusive)) + { + res = sem_post(sem); + assert(res == 0); + res = sem_close(sem); + assert(res == 0); + res = sem_unlink(mxname.c_str()); + assert(res); + throw thread_resource_error(); + } + m_hmap = shm_open(m_name.c_str(), oflag, 0); + if (m_hmap == -1) + { + if (errno == ENOENT) + continue; + res = sem_post(sem); + assert(res == 0); + res = sem_close(sem); + assert(res); + res = sem_unlink(mxname.c_str()); + assert(res); + throw thread_resource_error(); + } + } + else + should_init = true; + break; + } + + ftruncate(m_hmap, len); + int prot = (flags & write) ? PROT_READ|PROT_WRITE : PROT_READ; + m_ptr = mmap(0, m_len, prot, MAP_SHARED, m_hmap, 0); #endif if (should_init && initfunc) diff --git a/src/thread_pool.cpp b/src/thread_pool.cpp index 11e3cef2..72c46807 100644 --- a/src/thread_pool.cpp +++ b/src/thread_pool.cpp @@ -12,6 +12,8 @@ // Derived loosely from work queue manager in "Programming POSIX Threads" // by David Butenhof. +#include + #include #include #include diff --git a/src/threadmon.cpp b/src/threadmon.cpp index de4d594c..e4936c80 100644 --- a/src/threadmon.cpp +++ b/src/threadmon.cpp @@ -9,7 +9,7 @@ // about the suitability of this software for any purpose. // It is provided "as is" without express or implied warranty. -#include +#include #if defined(BOOST_HAS_WINTHREADS) diff --git a/src/tss.cpp b/src/tss.cpp index e603ffc9..fea176d7 100644 --- a/src/tss.cpp +++ b/src/tss.cpp @@ -9,7 +9,11 @@ // about the suitability of this software for any purpose. // It is provided "as is" without express or implied warranty. +#include + #include +#ifndef BOOST_THREAD_NO_TSS_CLEANUP + #include #include #include @@ -194,6 +198,8 @@ void tss::cleanup(void* value) } // namespace detail } // namespace boost +#endif BOOST_THREAD_NO_TSS_CLEANUP + // Change Log: // 6 Jun 01 // WEKEMPF Initial version. diff --git a/src/xtime.cpp b/src/xtime.cpp index 9f234a90..ae7458b1 100644 --- a/src/xtime.cpp +++ b/src/xtime.cpp @@ -9,6 +9,8 @@ // about the suitability of this software for any purpose. // It is provided "as is" without express or implied warranty. +#include + #include #if defined(BOOST_HAS_FTIME) diff --git a/test/test_thread.cpp b/test/test_thread.cpp index 88fc83f8..4be877b6 100644 --- a/test/test_thread.cpp +++ b/test/test_thread.cpp @@ -22,7 +22,7 @@ int test_value; void simple_thread() { - std::cout << "simple_thread()"; + std::cout << "simple_thread()"; test_value = 999; }