From ffdcf33364ebfdc1829cb7c7eea6ae4c908d12f1 Mon Sep 17 00:00:00 2001 From: Nat Goodspeed Date: Wed, 12 Jun 2024 16:42:39 -0400 Subject: Extract TempSet from llcallbacklist.cpp into its own tempset.h. --- indra/llcommon/CMakeLists.txt | 1 + indra/llcommon/llcallbacklist.cpp | 27 +------------------------- indra/llcommon/tempset.h | 41 +++++++++++++++++++++++++++++++++++++++ 3 files changed, 43 insertions(+), 26 deletions(-) create mode 100755 indra/llcommon/tempset.h (limited to 'indra') diff --git a/indra/llcommon/CMakeLists.txt b/indra/llcommon/CMakeLists.txt index d5440d6bc8..20670d7ebe 100644 --- a/indra/llcommon/CMakeLists.txt +++ b/indra/llcommon/CMakeLists.txt @@ -259,6 +259,7 @@ set(llcommon_HEADER_FILES lualistener.h stdtypes.h stringize.h + tempset.h threadpool.h threadpool_fwd.h threadsafeschedule.h diff --git a/indra/llcommon/llcallbacklist.cpp b/indra/llcommon/llcallbacklist.cpp index 015475a903..555c793333 100644 --- a/indra/llcommon/llcallbacklist.cpp +++ b/indra/llcommon/llcallbacklist.cpp @@ -29,6 +29,7 @@ #include "llerror.h" #include "llexception.h" #include "llsdutil.h" +#include "tempset.h" #include #include #include @@ -292,32 +293,6 @@ void Timers::setTimeslice(F32 timeslice) } } -// RAII class to set specified variable to specified value -// only for the duration of containing scope -template -class TempSet -{ -public: - TempSet(VAR& var, const VALUE& value): - mVar(var), - mOldValue(mVar) - { - mVar = value; - } - - TempSet(const TempSet&) = delete; - TempSet& operator=(const TempSet&) = delete; - - ~TempSet() - { - mVar = mOldValue; - } - -private: - VAR& mVar; - VALUE mOldValue; -}; - bool Timers::tick() { // Fetch current time only on entry, even though running some mQueue task diff --git a/indra/llcommon/tempset.h b/indra/llcommon/tempset.h new file mode 100755 index 0000000000..e1496bd5fc --- /dev/null +++ b/indra/llcommon/tempset.h @@ -0,0 +1,41 @@ +/** + * @file tempset.h + * @author Nat Goodspeed + * @date 2024-06-12 + * @brief Temporarily override a variable for scope duration, then restore + * + * $LicenseInfo:firstyear=2024&license=viewerlgpl$ + * Copyright (c) 2024, Linden Research, Inc. + * $/LicenseInfo$ + */ + +#if ! defined(LL_TEMPSET_H) +#define LL_TEMPSET_H + +// RAII class to set specified variable to specified value +// only for the duration of containing scope +template +class TempSet +{ +public: + TempSet(VAR& var, const VALUE& value): + mVar(var), + mOldValue(mVar) + { + mVar = value; + } + + TempSet(const TempSet&) = delete; + TempSet& operator=(const TempSet&) = delete; + + ~TempSet() + { + mVar = mOldValue; + } + +private: + VAR& mVar; + VALUE mOldValue; +}; + +#endif /* ! defined(LL_TEMPSET_H) */ -- cgit v1.2.3