SL-10291 Replace apr_atomic with standard C++11 functionality

master
andreykproductengine 2019-01-15 18:31:17 +02:00
parent 346fc435f1
commit fa15830e02
20 changed files with 128 additions and 52 deletions

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -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"
//============================================================================

69
indra/llcommon/llatomic.h Normal file
View File

@ -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

View File

@ -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;
}

View File

@ -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();

View File

@ -24,9 +24,6 @@
*/
#include "linden_common.h"
#include "llapr.h"
#include "apr_portable.h"
#include "llmutex.h"
#include "llthread.h"

View File

@ -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;

View File

@ -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;
};
/**

View File

@ -33,7 +33,7 @@
#include <string>
#include "llqueuedthread.h"
#include "llapr.h"
#include "llatomic.h"
#define USE_FRAME_CALLBACK_MANAGER 0

View File

@ -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"

View File

@ -34,7 +34,7 @@
#include <boost/thread.hpp>
#include <boost/intrusive_ptr.hpp>
#include "llapr.h"
#include "llatomic.h"
namespace LLCoreInt

View File

@ -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

View File

@ -27,6 +27,7 @@
#include "linden_common.h"
#include "llapr.h" // thread-related functions
#include "llcrashlock.h"
#include "lldir.h"
#include "llsd.h"

View File

@ -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;

View File

@ -27,6 +27,7 @@
#include "linden_common.h"
#include "llapr.h" // thread-related functions
#include "llpidlock.h"
#include "lldir.h"
#include "llsd.h"

View File

@ -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"

View File

@ -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"

View File

@ -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;