From dd67f3a0be26b475f0254cbeee57b64d51743693 Mon Sep 17 00:00:00 2001 From: Drake Arconis <drake@alchemyviewer.org> Date: Tue, 28 Oct 2014 08:10:57 -0400 Subject: [PATCH] changed: Seperate atomics out of llapr --- indra/llcommon/CMakeLists.txt | 1 + indra/llcommon/llapp.h | 14 +++--- indra/llcommon/llapr.h | 39 ----------------- indra/llcommon/llatomic.h | 70 ++++++++++++++++++++++++++++++ indra/llcommon/llinstancetracker.h | 2 +- indra/llcommon/llqueuedthread.h | 2 +- indra/llcommon/llrefcount.h | 1 + indra/llcommon/llworkerthread.h | 2 +- indra/llcorehttp/_httpservice.h | 2 +- indra/llcorehttp/_refcounted.h | 2 +- indra/llcorehttp/_thread.h | 2 + 11 files changed, 84 insertions(+), 53 deletions(-) create mode 100644 indra/llcommon/llatomic.h diff --git a/indra/llcommon/CMakeLists.txt b/indra/llcommon/CMakeLists.txt index b62e3f7362..76ccfb6428 100755 --- a/indra/llcommon/CMakeLists.txt +++ b/indra/llcommon/CMakeLists.txt @@ -123,6 +123,7 @@ set(llcommon_HEADER_FILES llapp.h llapr.h llassettype.h + llatomic.h llbase32.h llbase64.h llbitpack.h diff --git a/indra/llcommon/llapp.h b/indra/llcommon/llapp.h index b5298bdeec..bc0d80f81f 100755 --- a/indra/llcommon/llapp.h +++ b/indra/llcommon/llapp.h @@ -28,21 +28,17 @@ #define LL_LLAPP_H #include <map> +#include "llatomic.h" #include "llrun.h" #include "llsd.h" -// Forward declarations -#if __cplusplus >= 201103L || _MSC_VER >= 1800 -#include "llapr.h" -#else -template <typename Type> class LLAtomic32; -typedef LLAtomic32<U32> LLAtomicU32; -#endif -class LLErrorThread; -class LLLiveFile; + #if LL_LINUX #include <signal.h> #endif +class LLErrorThread; +class LLLiveFile; + typedef void (*LLAppErrorHandler)(); #if !LL_WINDOWS diff --git a/indra/llcommon/llapr.h b/indra/llcommon/llapr.h index d035c23fa0..d8000d787e 100755 --- a/indra/llcommon/llapr.h +++ b/indra/llcommon/llapr.h @@ -29,8 +29,6 @@ #ifndef LL_LLAPR_H #define LL_LLAPR_H -#define AL_ATOMICS_CXX 1 - #if LL_LINUX || LL_SOLARIS #include <sys/param.h> // Need PATH_MAX in APR headers... #endif @@ -41,11 +39,6 @@ #include "apr_thread_mutex.h" #include "apr_getopt.h" #include "apr_signal.h" -#if AL_ATOMICS_CXX && (__cplusplus >= 201103L || _MSC_VER >= 1800) -#include <boost/atomic.hpp> -#else -#include "apr_atomic.h" -#endif #include "llstring.h" @@ -171,38 +164,6 @@ protected: apr_thread_mutex_t* mMutex; }; -#if AL_ATOMICS_CXX && (__cplusplus >= 201103L || _MSC_VER >= 1800) -template<typename Type> -using LLAtomic32 = boost::atomic<Type>; -#else -template <typename Type> class LLAtomic32 -{ -public: - LLAtomic32<Type>() {}; - LLAtomic32<Type>(Type x) {apr_atomic_set32(&mData, apr_uint32_t(x)); }; - ~LLAtomic32<Type>() {}; - - operator const Type() { apr_uint32_t data = apr_atomic_read32(&mData); return Type(data); } - - Type load() const { apr_uint32_t data = apr_atomic_read32(const_cast< volatile apr_uint32_t* >(&mData)); return Type(data); } - - Type operator =(const Type& x) { apr_atomic_set32(&mData, apr_uint32_t(x)); return Type(mData); } - void operator -=(Type x) { apr_atomic_sub32(&mData, apr_uint32_t(x)); } - void operator +=(Type x) { apr_atomic_add32(&mData, apr_uint32_t(x)); } - Type operator ++(int) { return apr_atomic_inc32(&mData); } // Type++ - Type operator --(int) { return apr_atomic_dec32(&mData); } // approximately --Type (0 if final is 0, non-zero otherwise) - - Type operator ++() { return apr_atomic_inc32(&mData); } // Type++ - Type operator --() { return apr_atomic_dec32(&mData); } // approximately --Type (0 if final is 0, non-zero otherwise) - -private: - volatile apr_uint32_t mData; -}; -#endif // AL_ATOMICS_CXX - -typedef LLAtomic32<U32> LLAtomicU32; -typedef LLAtomic32<S32> LLAtomicS32; - // File IO convenience functions. // Returns NULL if the file fails to open, sets *sizep to file size if not NULL // abbreviated flags diff --git a/indra/llcommon/llatomic.h b/indra/llcommon/llatomic.h new file mode 100644 index 0000000000..dbf55ab544 --- /dev/null +++ b/indra/llcommon/llatomic.h @@ -0,0 +1,70 @@ +/** + * @file llatmomic.h + * @brief Base classes for atomics. + * + * $LicenseInfo:firstyear=2014&license=viewerlgpl$ + * Second Life Viewer Source Code + * Copyright (C) 2012, Linden Research, Inc. + * Copyright (C) 2014, Alchemy Development Group + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; + * version 2.1 of the License only. + * + * This library 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 for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + * + * Linden Research, Inc., 945 Battery Street, San Francisco, CA 94111 USA + * $/LicenseInfo$ + */ + +#pragma once + +#include "stdtypes.h" +#define AL_BOOST_ATOMICS 1 + +#if (__cplusplus >= 201103L || _MSC_VER >= 1800) + +#if AL_BOOST_ATOMICS +#include <boost/atomic.hpp> +#elif AL_STD_ATOMICS +#include <boost/atomic.hpp> +#endif +template<typename Type> +using LLAtomic32 = boost::atomic<Type>; +#else +#include "apr_atomic.h" +template <typename Type> class LLAtomic32 +{ +public: + LLAtomic32<Type>() {}; + LLAtomic32<Type>(Type x) {apr_atomic_set32(&mData, apr_uint32_t(x)); }; + ~LLAtomic32<Type>() {}; + + operator const Type() { apr_uint32_t data = apr_atomic_read32(&mData); return Type(data); } + + Type load() const { apr_uint32_t data = apr_atomic_read32(const_cast< volatile apr_uint32_t* >(&mData)); return Type(data); } + + Type operator =(const Type& x) { apr_atomic_set32(&mData, apr_uint32_t(x)); return Type(mData); } + void operator -=(Type x) { apr_atomic_sub32(&mData, apr_uint32_t(x)); } + void operator +=(Type x) { apr_atomic_add32(&mData, apr_uint32_t(x)); } + Type operator ++(int) { return apr_atomic_inc32(&mData); } // Type++ + Type operator --(int) { return apr_atomic_dec32(&mData); } // approximately --Type (0 if final is 0, non-zero otherwise) + + Type operator ++() { return apr_atomic_inc32(&mData); } // Type++ + Type operator --() { return apr_atomic_dec32(&mData); } // approximately --Type (0 if final is 0, non-zero otherwise) + +private: + volatile apr_uint32_t mData; +}; +#endif // AL_ATOMICS_CXX + +typedef LLAtomic32<U32> LLAtomicU32; +typedef LLAtomic32<S32> LLAtomicS32; \ No newline at end of file diff --git a/indra/llcommon/llinstancetracker.h b/indra/llcommon/llinstancetracker.h index d598d376c7..dfb4a599ac 100755 --- a/indra/llcommon/llinstancetracker.h +++ b/indra/llcommon/llinstancetracker.h @@ -31,7 +31,7 @@ #include <map> #include <typeinfo> -#include "llapr.h" +#include "llatomic.h" #include "llstringtable.h" #include <boost/iterator/transform_iterator.hpp> #include <boost/iterator/indirect_iterator.hpp> diff --git a/indra/llcommon/llqueuedthread.h b/indra/llcommon/llqueuedthread.h index 3ae2188e68..120c136943 100755 --- a/indra/llcommon/llqueuedthread.h +++ b/indra/llcommon/llqueuedthread.h @@ -32,7 +32,7 @@ #include <map> #include <set> -#include "llapr.h" +#include "llatomic.h" #include "llthread.h" #include "llsimplehash.h" diff --git a/indra/llcommon/llrefcount.h b/indra/llcommon/llrefcount.h index 53df57788b..bdbc95389a 100755 --- a/indra/llcommon/llrefcount.h +++ b/indra/llcommon/llrefcount.h @@ -28,6 +28,7 @@ #include <boost/noncopyable.hpp> #include <boost/intrusive_ptr.hpp> +#include "llatomic.h" #include "llmutex.h" #include "llapr.h" diff --git a/indra/llcommon/llworkerthread.h b/indra/llcommon/llworkerthread.h index 09776816a8..b1a6f61360 100755 --- a/indra/llcommon/llworkerthread.h +++ b/indra/llcommon/llworkerthread.h @@ -33,7 +33,7 @@ #include <string> #include "llqueuedthread.h" -#include "llapr.h" +#include "llatomic.h" #define USE_FRAME_CALLBACK_MANAGER 0 diff --git a/indra/llcorehttp/_httpservice.h b/indra/llcorehttp/_httpservice.h index cf23f3ab61..955c0bd254 100755 --- a/indra/llcorehttp/_httpservice.h +++ b/indra/llcorehttp/_httpservice.h @@ -31,7 +31,7 @@ #include <vector> #include "linden_common.h" -#include "llapr.h" +#include "llatomic.h" #include "httpcommon.h" #include "httprequest.h" #include "_httppolicyglobal.h" diff --git a/indra/llcorehttp/_refcounted.h b/indra/llcorehttp/_refcounted.h index 402e725152..4b8d1a5128 100755 --- a/indra/llcorehttp/_refcounted.h +++ b/indra/llcorehttp/_refcounted.h @@ -33,7 +33,7 @@ #include "fix_macros.h" #include <boost/thread.hpp> -#include "llapr.h" +#include "llatomic.h" namespace LLCoreInt diff --git a/indra/llcorehttp/_thread.h b/indra/llcorehttp/_thread.h index e058d660e5..fed288d6e0 100755 --- a/indra/llcorehttp/_thread.h +++ b/indra/llcorehttp/_thread.h @@ -33,6 +33,8 @@ #include <boost/function.hpp> #include <boost/date_time/posix_time/posix_time_types.hpp> +#include "llwin32headerslean.h" + #include "_refcounted.h" namespace LLCoreInt -- GitLab