Commit 504a138c authored by Anchor's avatar Anchor
Browse files

Merge

parents f9f129f9 34322f8f
......@@ -547,3 +547,4 @@ ac3b1332ad4f55b7182a8cbcc1254535a0069f75 5.1.7-release
a3143db58a0f6b005232bf9018e7fef17ff9ec90 6.1.0-release
50f0ece62ddb5a244ecb6d00ef5a89d80ad50efa 6.1.1-release
82a89165e5929a6c3073d6cd60a543cb395f147b 6.2.0-release
706bdc7e25c6e6b8fb56f4a13fcce2936e70a79c 6.2.1-release
......@@ -374,6 +374,7 @@ Cinder Roxley
STORM-2116
STORM-2127
STORM-2144
SL-3404
Clara Young
Coaldust Numbers
VWR-1095
......@@ -779,6 +780,7 @@ Jonathan Yap
STORM-2100
STORM-2104
STORM-2142
SL-10089
Kadah Coba
STORM-1060
STORM-1843
......@@ -1069,6 +1071,8 @@ Nicky Dasmijn
STORM-2010
STORM-2082
MAINT-6665
SL-10291
SL-10293
Nicky Perian
OPEN-1
STORM-1087
......
......@@ -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
......
......@@ -153,7 +153,6 @@ const U8 SIM_ACCESS_DOWN = 254;
const U8 SIM_ACCESS_MAX = SIM_ACCESS_ADULT;
// attachment constants
const S32 MAX_AGENT_ATTACHMENTS = 38;
const U8 ATTACHMENT_ADD = 0x80;
// god levels
......
......@@ -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
......
......@@ -28,13 +28,12 @@
#include "linden_common.h"
#include "llapr.h"
#include "llmutex.h"
#include "apr_dso.h"
#include "llthreadlocalstorage.h"
apr_pool_t *gAPRPoolp = NULL; // Global APR memory pool
LLVolatileAPRPool *LLAPRFile::sAPRFilePoolp = NULL ; //global volatile APR memory pool.
apr_thread_mutex_t *gLogMutexp = NULL;
apr_thread_mutex_t *gCallStacksLogMutexp = NULL;
const S32 FULL_VOLATILE_APR_POOL = 1024 ; //number of references to LLVolatileAPRPool
......@@ -48,10 +47,6 @@ void ll_init_apr()
if (!gAPRPoolp)
{
apr_pool_create(&gAPRPoolp, NULL);
// Initialize the logging mutex
apr_thread_mutex_create(&gLogMutexp, APR_THREAD_MUTEX_UNNESTED, gAPRPoolp);
apr_thread_mutex_create(&gCallStacksLogMutexp, APR_THREAD_MUTEX_UNNESTED, gAPRPoolp);
}
if(!LLAPRFile::sAPRFilePoolp)
......@@ -75,23 +70,6 @@ void ll_cleanup_apr()
LL_INFOS("APR") << "Cleaning up APR" << LL_ENDL;
if (gLogMutexp)
{
// Clean up the logging mutex
// All other threads NEED to be done before we clean up APR, so this is okay.
apr_thread_mutex_destroy(gLogMutexp);
gLogMutexp = NULL;
}
if (gCallStacksLogMutexp)
{
// Clean up the logging mutex
// All other threads NEED to be done before we clean up APR, so this is okay.
apr_thread_mutex_destroy(gCallStacksLogMutexp);
gCallStacksLogMutexp = NULL;
}
LLThreadLocalPointerBase::destroyAllThreadLocalStorage();
if (gAPRPoolp)
......@@ -168,26 +146,19 @@ apr_pool_t* LLAPRPool::getAPRPool()
LLVolatileAPRPool::LLVolatileAPRPool(BOOL is_local, apr_pool_t *parent, apr_size_t size, BOOL releasePoolFlag)
: LLAPRPool(parent, size, releasePoolFlag),
mNumActiveRef(0),
mNumTotalRef(0),
mMutexPool(NULL),
mMutexp(NULL)
mNumTotalRef(0)
{
//create mutex
if(!is_local) //not a local apr_pool, that is: shared by multiple threads.
{
apr_pool_create(&mMutexPool, NULL); // Create a pool for mutex
apr_thread_mutex_create(&mMutexp, APR_THREAD_MUTEX_UNNESTED, mMutexPool);
mMutexp.reset(new std::mutex());
}
}
LLVolatileAPRPool::~LLVolatileAPRPool()
{
//delete mutex
if(mMutexp)
{
apr_thread_mutex_destroy(mMutexp);
apr_pool_destroy(mMutexPool);
}
mMutexp.reset();
}
//
......@@ -201,7 +172,7 @@ apr_pool_t* LLVolatileAPRPool::getAPRPool()
apr_pool_t* LLVolatileAPRPool::getVolatileAPRPool()
{
LLScopedLock lock(mMutexp) ;
LLScopedLock lock(mMutexp.get()) ;
mNumTotalRef++ ;
mNumActiveRef++ ;
......@@ -216,7 +187,7 @@ apr_pool_t* LLVolatileAPRPool::getVolatileAPRPool()
void LLVolatileAPRPool::clearVolatileAPRPool()
{
LLScopedLock lock(mMutexp) ;
LLScopedLock lock(mMutexp.get());
if(mNumActiveRef > 0)
{
......@@ -250,44 +221,6 @@ BOOL LLVolatileAPRPool::isFull()
{
return mNumTotalRef > FULL_VOLATILE_APR_POOL ;
}
//---------------------------------------------------------------------
//
// LLScopedLock
//
LLScopedLock::LLScopedLock(apr_thread_mutex_t* mutex) : mMutex(mutex)
{
if(mutex)
{
if(ll_apr_warn_status(apr_thread_mutex_lock(mMutex)))
{
mLocked = false;
}
else
{
mLocked = true;
}
}
else
{
mLocked = false;
}
}
LLScopedLock::~LLScopedLock()
{
unlock();
}
void LLScopedLock::unlock()
{
if(mLocked)
{
if(!ll_apr_warn_status(apr_thread_mutex_unlock(mMutex)))
{
mLocked = false;
}
}
}
//---------------------------------------------------------------------
......
......@@ -36,15 +36,22 @@
#include <boost/noncopyable.hpp>
#include "llwin32headerslean.h"
#include "apr_thread_proc.h"
#include "apr_thread_mutex.h"
#include "apr_getopt.h"
#include "apr_signal.h"
#include "apr_atomic.h"
#include "llstring.h"
extern LL_COMMON_API apr_thread_mutex_t* gLogMutexp;
extern apr_thread_mutex_t* gCallStacksLogMutexp;
#if LL_WINDOWS
#pragma warning (push)
#pragma warning (disable:4265)
#endif
// warning C4265: 'std::_Pad' : class has virtual functions, but destructor is not virtual
#include <mutex>
#if LL_WINDOWS
#pragma warning (pop)
#endif
struct apr_dso_handle_t;
/**
......@@ -120,77 +127,9 @@ class LL_COMMON_API LLVolatileAPRPool : public LLAPRPool
S32 mNumActiveRef ; //number of active pointers pointing to the apr_pool.
S32 mNumTotalRef ; //number of total pointers pointing to the apr_pool since last creating.
apr_thread_mutex_t *mMutexp;
apr_pool_t *mMutexPool;
std::unique_ptr<std::mutex> mMutexp;
} ;
/**
* @class LLScopedLock
* @brief Small class to help lock and unlock mutexes.
*
* This class is used to have a stack level lock once you already have
* an apr mutex handy. The constructor handles the lock, and the
* destructor handles the unlock. Instances of this class are
* <b>not</b> thread safe.
*/
class LL_COMMON_API LLScopedLock : private boost::noncopyable
{
public:
/**
* @brief Constructor which accepts a mutex, and locks it.
*
* @param mutex An allocated APR mutex. If you pass in NULL,
* this wrapper will not lock.
*/
LLScopedLock(apr_thread_mutex_t* mutex);
/**
* @brief Destructor which unlocks the mutex if still locked.
*/
~LLScopedLock();
/**
* @brief Check lock.
*/
bool isLocked() const { return mLocked; }
/**
* @brief This method unlocks the mutex.
*/
void unlock();
protected:
bool mLocked;
apr_thread_mutex_t* mMutex;
};
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
......
/**
* @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"
//============================================================================
/**
* @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
......@@ -390,15 +390,22 @@ namespace
{
llifstream file(filename().c_str());
if (file.is_open())
if (!file.is_open())
{
LLSDSerialize::fromXML(configuration, file);
LL_WARNS() << filename() << " failed to open file; not changing configuration" << LL_ENDL;
return false;
}
if (LLSDSerialize::fromXML(configuration, file) == LLSDParser::PARSE_FAILURE)
{
LL_WARNS() << filename() << " parcing error; not changing configuration" << LL_ENDL;
return false;
}
if (configuration.isUndefined())
if (configuration.isUndefined() || !configuration.isMap() || configuration.emptyMap())
{
LL_WARNS() << filename() << " missing, ill-formed,"
" or simply undefined; not changing configuration"
LL_WARNS() << filename() << " missing, ill-formed, or simply undefined"
" content; not changing configuration"
<< LL_ENDL;
return false;
}
......@@ -860,19 +867,24 @@ namespace LLError
setEnabledLogTypesMask(config["enabled-log-types-mask"].asInteger());
}
LLSD sets = config["settings"];
LLSD::array_const_iterator a, end;
for (a = sets.beginArray(), end = sets.endArray(); a != end; ++a)
{
const LLSD& entry = *a;
ELevel level = decodeLevel(entry["level"]);
setLevels(s->mFunctionLevelMap, entry["functions"], level);
setLevels(s->mClassLevelMap, entry["classes"], level);
setLevels(s->mFileLevelMap, entry["files"], level);
setLevels(s->mTagLevelMap, entry["tags"], level);
}
if (config.has("settings") && config["settings"].isArray())
{
LLSD sets = config["settings"];
LLSD::array_const_iterator a, end;
for (a = sets.beginArray(), end = sets.endArray(); a != end; ++a)
{
const LLSD& entry = *a;
if (entry.isMap() && !entry.emptyMap())
{
ELevel level = decodeLevel(entry["level"]);
setLevels(s->mFunctionLevelMap, entry["functions"], level);
setLevels(s->mClassLevelMap, entry["classes"], level);
setLevels(s->mFileLevelMap, entry["files"], level);
setLevels(s->mTagLevelMap, entry["tags"], level);
}
}
}
}
}
......@@ -1136,6 +1148,9 @@ namespace
}
namespace {
LLMutex gLogMutex;
LLMutex gCallStacksLogMutex;
bool checkLevelMap(const LevelMap& map, const std::string& key,
LLError::ELevel& level)
{
......@@ -1175,56 +1190,6 @@ namespace {
}
return found_level;
}
class LogLock
{
public:
LogLock();
~LogLock();
bool ok() const { return mOK; }
private:
bool mLocked;
bool mOK;
};
LogLock::LogLock()
: mLocked(false), mOK(false)
{
if (!gLogMutexp)
{
mOK = true;
return;
}
const int MAX_RETRIES = 5;
for (int attempts = 0; attempts < MAX_RETRIES; ++attempts)
{
apr_status_t s = apr_thread_mutex_trylock(gLogMutexp);
if (!APR_STATUS_IS_EBUSY(s))
{
mLocked = true;
mOK = true;
return;
}
ms_sleep(1);
//apr_thread_yield();
// Just yielding won't necessarily work, I had problems with
// this on Linux - doug 12/02/04
}
// We're hosed, we can't get the mutex. Blah.
std::cerr << "LogLock::LogLock: failed to get mutex for log"
<< std::endl;
}
LogLock::~LogLock()
{
if (mLocked)
{
apr_thread_mutex_unlock(gLogMutexp);
}
}
}
namespace LLError
......@@ -1232,8 +1197,8 @@ namespace LLError
bool Log::shouldLog(CallSite& site)
{
LogLock lock;
if (!lock.ok())
LLMutexTrylock lock(&gLogMutex, 5);
if (!lock.isLocked())
{
return false;
}
......@@ -1283,11 +1248,11 @@ namespace LLError
std::ostringstream* Log::out()
{
LogLock lock;
LLMutexTrylock lock(&gLogMutex,5);
// If we hit a logging request very late during shutdown processing,
// when either of the relevant LLSingletons has already been deleted,
// DO NOT resurrect them.
if (lock.ok() && ! (Settings::wasDeleted() || Globals::wasDeleted()))
if (lock.isLocked() && ! (Settings::wasDeleted() || Globals::wasDeleted()))
{
Globals* g = Globals::getInstance();
......@@ -1303,8 +1268,8 @@ namespace LLError
void Log::flush(std::ostringstream* out, char* message)
{
LogLock lock;
if (!lock.ok())
LLMutexTrylock lock(&gLogMutex,5);
if (!lock.isLocked())
{
return;
}
......@@ -1343,8 +1308,8 @@ namespace LLError
void Log::flush(std::ostringstream* out, const CallSite& site)
{
LogLock lock;
if (!lock.ok())
LLMutexTrylock lock(&gLogMutex,5);
if (!lock.isLocked())
{
return;
}
......@@ -1514,69 +1479,6 @@ namespace LLError
char** LLCallStacks::sBuffer = NULL ;
S32 LLCallStacks::sIndex = 0 ;
#define SINGLE_THREADED 1
class CallStacksLogLock
{
public:
CallStacksLogLock();
~CallStacksLogLock();