summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--indra/llcommon/CMakeLists.txt2
-rw-r--r--indra/llcommon/llapp.h3
-rw-r--r--indra/llcommon/llapr.h28
-rw-r--r--indra/llcommon/llatomic.cpp28
-rw-r--r--indra/llcommon/llatomic.h69
-rw-r--r--indra/llcommon/llinstancetracker.cpp7
-rw-r--r--indra/llcommon/llinstancetracker.h9
-rw-r--r--indra/llcommon/llmutex.cpp3
-rw-r--r--indra/llcommon/llqueuedthread.h6
-rw-r--r--indra/llcommon/llrefcount.h8
-rw-r--r--indra/llcommon/llworkerthread.h2
-rw-r--r--indra/llcorehttp/_httpservice.h2
-rw-r--r--indra/llcorehttp/_refcounted.h2
-rw-r--r--indra/llcorehttp/_thread.h1
-rw-r--r--indra/llcrashlogger/llcrashlock.cpp1
-rw-r--r--indra/llmessage/llproxy.h2
-rw-r--r--indra/llvfs/llpidlock.cpp1
-rw-r--r--indra/newview/llappviewer.h1
-rw-r--r--indra/newview/llmeshrepository.cpp3
-rw-r--r--indra/newview/lltexturecache.h2
20 files changed, 128 insertions, 52 deletions
diff --git a/indra/llcommon/CMakeLists.txt b/indra/llcommon/CMakeLists.txt
index d9eb13d65a..ac19e6d025 100644
--- a/indra/llcommon/CMakeLists.txt
+++ b/indra/llcommon/CMakeLists.txt
@@ -35,6 +35,7 @@ set(llcommon_SOURCE_FILES
llapp.cpp
llapr.cpp
llassettype.cpp
+ llatomic.cpp
llbase32.cpp
llbase64.cpp
llbitpack.cpp
@@ -135,6 +136,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 acd829d864..245c73e3a2 100644
--- a/indra/llcommon/llapp.h
+++ b/indra/llcommon/llapp.h
@@ -30,9 +30,8 @@
#include <map>
#include "llrun.h"
#include "llsd.h"
+#include <atomic>
// Forward declarations
-template <typename Type> class LLAtomic32;
-typedef LLAtomic32<U32> LLAtomicU32;
class LLErrorThread;
class LLLiveFile;
#if LL_LINUX
diff --git a/indra/llcommon/llapr.h b/indra/llcommon/llapr.h
index 73d1d180ef..da50dda103 100644
--- a/indra/llcommon/llapr.h
+++ b/indra/llcommon/llapr.h
@@ -38,7 +38,6 @@
#include "apr_thread_proc.h"
#include "apr_getopt.h"
#include "apr_signal.h"
-#include "apr_atomic.h"
#include "llstring.h"
@@ -131,33 +130,6 @@ private:
std::unique_ptr<std::mutex> mMutexp;
} ;
-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 CurrentValue() 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;
-};
-
-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.cpp b/indra/llcommon/llatomic.cpp
new file mode 100644
index 0000000000..93aba1f460
--- /dev/null
+++ b/indra/llcommon/llatomic.cpp
@@ -0,0 +1,28 @@
+/**
+ * @file llatomic.cpp
+ *
+ * $LicenseInfo:firstyear=2018&license=viewerlgpl$
+ * Second Life Viewer Source Code
+ * Copyright (C) 2018, Linden Research, Inc.
+ *
+ * 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$
+ */
+
+#include "llatomic.h"
+
+//============================================================================
diff --git a/indra/llcommon/llatomic.h b/indra/llcommon/llatomic.h
new file mode 100644
index 0000000000..8de773846c
--- /dev/null
+++ b/indra/llcommon/llatomic.h
@@ -0,0 +1,69 @@
+/**
+ * @file llatomic.h
+ * @brief Base classes for atomic.
+ *
+ * $LicenseInfo:firstyear=2018&license=viewerlgpl$
+ * Second Life Viewer Source Code
+ * Copyright (C) 2018, Linden Research, Inc.
+ *
+ * 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$
+ */
+
+#ifndef LL_LLATOMIC_H
+#define LL_LLATOMIC_H
+
+#include "stdtypes.h"
+
+#include <atomic>
+
+template <typename Type, typename AtomicType = std::atomic< Type > > class LLAtomicBase
+{
+public:
+ LLAtomicBase() {};
+ LLAtomicBase(Type x) { mData.store(x); }
+ ~LLAtomicBase() {};
+
+ operator const Type() { return mData; }
+
+ Type CurrentValue() const { return mData; }
+
+ Type operator =(const Type& x) { mData.store(x); return mData; }
+ void operator -=(Type x) { mData -= x; }
+ void operator +=(Type x) { mData += x; }
+ Type operator ++(int) { return mData++; }
+ Type operator --(int) { return mData--; }
+
+ Type operator ++() { return ++mData; }
+ Type operator --() { return --mData; }
+
+private:
+ AtomicType mData;
+};
+
+// Typedefs for specialized versions. Using std::atomic_(u)int32_t to get the optimzed implementation.
+#ifdef LL_WINDOWS
+typedef LLAtomicBase<U32, std::atomic_uint32_t> LLAtomicU32;
+typedef LLAtomicBase<S32, std::atomic_int32_t> LLAtomicS32;
+#else
+typedef LLAtomicBase<U32, std::atomic_uint> LLAtomicU32;
+typedef LLAtomicBase<S32, std::atomic_int> LLAtomicS32;
+#endif
+
+typedef LLAtomicBase<bool, std::atomic_bool> LLAtomicBool;
+
+#endif // LL_LLATOMIC_H
diff --git a/indra/llcommon/llinstancetracker.cpp b/indra/llcommon/llinstancetracker.cpp
index 11fc53f8c8..3f990f4869 100644
--- a/indra/llcommon/llinstancetracker.cpp
+++ b/indra/llcommon/llinstancetracker.cpp
@@ -36,17 +36,16 @@
void LLInstanceTrackerBase::StaticBase::incrementDepth()
{
- apr_atomic_inc32(&sIterationNestDepth);
+ ++sIterationNestDepth;
}
void LLInstanceTrackerBase::StaticBase::decrementDepth()
{
llassert(sIterationNestDepth);
- apr_atomic_dec32(&sIterationNestDepth);
+ --sIterationNestDepth;
}
U32 LLInstanceTrackerBase::StaticBase::getDepth()
{
- apr_uint32_t data = apr_atomic_read32(&sIterationNestDepth);
- return data;
+ return sIterationNestDepth;
}
diff --git a/indra/llcommon/llinstancetracker.h b/indra/llcommon/llinstancetracker.h
index 910c8dbd99..363d0bcbd5 100644
--- a/indra/llcommon/llinstancetracker.h
+++ b/indra/llcommon/llinstancetracker.h
@@ -28,6 +28,7 @@
#ifndef LL_LLINSTANCETRACKER_H
#define LL_LLINSTANCETRACKER_H
+#include <atomic>
#include <map>
#include <typeinfo>
@@ -81,8 +82,12 @@ protected:
void decrementDepth();
U32 getDepth();
private:
- U32 sIterationNestDepth;
- };
+#ifdef LL_WINDOWS
+ std::atomic_uint32_t sIterationNestDepth;
+#else
+ std::atomic_uint sIterationNestDepth;
+#endif
+ };
};
LL_COMMON_API void assert_main_thread();
diff --git a/indra/llcommon/llmutex.cpp b/indra/llcommon/llmutex.cpp
index cf84e50953..75f43a4704 100644
--- a/indra/llcommon/llmutex.cpp
+++ b/indra/llcommon/llmutex.cpp
@@ -24,9 +24,6 @@
*/
#include "linden_common.h"
-#include "llapr.h"
-
-#include "apr_portable.h"
#include "llmutex.h"
#include "llthread.h"
diff --git a/indra/llcommon/llqueuedthread.h b/indra/llcommon/llqueuedthread.h
index d3704b0fe2..5d3f873646 100644
--- 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"
@@ -128,7 +128,7 @@ public:
};
protected:
- LLAtomic32<status_t> mStatus;
+ LLAtomicBase<status_t> mStatus;
U32 mPriority;
U32 mFlags;
};
@@ -198,7 +198,7 @@ public:
protected:
BOOL mThreaded; // if false, run on main thread and do updates during update()
BOOL mStarted; // required when mThreaded is false to call startThread() from update()
- LLAtomic32<BOOL> mIdleThread; // request queue is empty (or we are quitting) and the thread is idle
+ LLAtomicBool mIdleThread; // request queue is empty (or we are quitting) and the thread is idle
typedef std::set<QueuedRequest*, queued_request_less> request_queue_t;
request_queue_t mRequestQueue;
diff --git a/indra/llcommon/llrefcount.h b/indra/llcommon/llrefcount.h
index cdc60fa54f..fb0411d27b 100644
--- a/indra/llcommon/llrefcount.h
+++ b/indra/llcommon/llrefcount.h
@@ -29,7 +29,7 @@
#include <boost/noncopyable.hpp>
#include <boost/intrusive_ptr.hpp>
#include "llmutex.h"
-#include "llapr.h"
+#include "llatomic.h"
//----------------------------------------------------------------------------
// RefCount objects should generally only be accessed by way of LLPointer<>'s
@@ -107,8 +107,8 @@ public:
void unref()
{
llassert(mRef >= 1);
- if ((--mRef) == 0) // See note in llapr.h on atomic decrement operator return value.
- {
+ if ((--mRef) == 0)
+ {
// If we hit zero, the caller should be the only smart pointer owning the object and we can delete it.
// It is technically possible for a vanilla pointer to mess this up, or another thread to
// jump in, find this object, create another smart pointer and end up dangling, but if
@@ -124,7 +124,7 @@ public:
}
private:
- LLAtomic32< S32 > mRef;
+ LLAtomicS32 mRef;
};
/**
diff --git a/indra/llcommon/llworkerthread.h b/indra/llcommon/llworkerthread.h
index 09776816a8..b1a6f61360 100644
--- 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 ac518a5de7..d0c37ac195 100644
--- 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 7f713f2298..5cc8914395 100644
--- a/indra/llcorehttp/_refcounted.h
+++ b/indra/llcorehttp/_refcounted.h
@@ -34,7 +34,7 @@
#include <boost/thread.hpp>
#include <boost/intrusive_ptr.hpp>
-#include "llapr.h"
+#include "llatomic.h"
namespace LLCoreInt
diff --git a/indra/llcorehttp/_thread.h b/indra/llcorehttp/_thread.h
index e058d660e5..22b7750bad 100644
--- a/indra/llcorehttp/_thread.h
+++ b/indra/llcorehttp/_thread.h
@@ -33,6 +33,7 @@
#include <boost/function.hpp>
#include <boost/date_time/posix_time/posix_time_types.hpp>
+#include "apr.h" // thread-related functions
#include "_refcounted.h"
namespace LLCoreInt
diff --git a/indra/llcrashlogger/llcrashlock.cpp b/indra/llcrashlogger/llcrashlock.cpp
index 77abfbcf0f..18d164abde 100644
--- a/indra/llcrashlogger/llcrashlock.cpp
+++ b/indra/llcrashlogger/llcrashlock.cpp
@@ -27,6 +27,7 @@
#include "linden_common.h"
+#include "llapr.h" // thread-related functions
#include "llcrashlock.h"
#include "lldir.h"
#include "llsd.h"
diff --git a/indra/llmessage/llproxy.h b/indra/llmessage/llproxy.h
index 688dff7c83..87891901ad 100644
--- a/indra/llmessage/llproxy.h
+++ b/indra/llmessage/llproxy.h
@@ -298,7 +298,7 @@ private:
private:
// Is the HTTP proxy enabled? Safe to read in any thread, but do not write directly.
// Instead use enableHTTPProxy() and disableHTTPProxy() instead.
- mutable LLAtomic32<bool> mHTTPProxyEnabled;
+ mutable LLAtomicBool mHTTPProxyEnabled;
// Mutex to protect shared members in non-main thread calls to applyProxySettings().
mutable LLMutex mProxyMutex;
diff --git a/indra/llvfs/llpidlock.cpp b/indra/llvfs/llpidlock.cpp
index 6572edead3..f770e93d45 100644
--- a/indra/llvfs/llpidlock.cpp
+++ b/indra/llvfs/llpidlock.cpp
@@ -27,6 +27,7 @@
#include "linden_common.h"
+#include "llapr.h" // thread-related functions
#include "llpidlock.h"
#include "lldir.h"
#include "llsd.h"
diff --git a/indra/newview/llappviewer.h b/indra/newview/llappviewer.h
index e607b4a994..788fe6a19b 100644
--- a/indra/newview/llappviewer.h
+++ b/indra/newview/llappviewer.h
@@ -43,6 +43,7 @@
#define LL_LLAPPVIEWER_H
#include "llallocator.h"
+#include "llapr.h"
#include "llcontrol.h"
#include "llsys.h" // for LLOSInfo
#include "lltimer.h"
diff --git a/indra/newview/llmeshrepository.cpp b/indra/newview/llmeshrepository.cpp
index a6002bd57f..2e7141bcfc 100644
--- a/indra/newview/llmeshrepository.cpp
+++ b/indra/newview/llmeshrepository.cpp
@@ -26,10 +26,11 @@
#include "llviewerprecompiledheaders.h"
+#include "llapr.h"
+#include "apr_portable.h"
#include "apr_pools.h"
#include "apr_dso.h"
#include "llhttpconstants.h"
-#include "llapr.h"
#include "llmeshrepository.h"
#include "llagent.h"
diff --git a/indra/newview/lltexturecache.h b/indra/newview/lltexturecache.h
index 987b9375c0..81ea7aeee2 100644
--- a/indra/newview/lltexturecache.h
+++ b/indra/newview/lltexturecache.h
@@ -221,7 +221,7 @@ private:
typedef std::map<LLUUID,S32> size_map_t;
size_map_t mTexturesSizeMap;
S64 mTexturesSizeTotal;
- LLAtomic32<BOOL> mDoPurge;
+ LLAtomicBool mDoPurge;
typedef std::map<S32, Entry> idx_entry_map_t;
idx_entry_map_t mUpdatedEntryMap;