From cf692c40b0b9f8d0d04cd10a02a84e3f697a2e99 Mon Sep 17 00:00:00 2001
From: Alexander Gavriliuk <alexandrgproductengine@lindenlab.com>
Date: Mon, 20 Mar 2023 10:20:06 +0100
Subject: SL-18721: Faster viewer shutdown time since performance improvements
 can lead to perceived inventory loss due to cache corruption

---
 indra/llcommon/threadpool.cpp | 5 +++++
 indra/llcommon/threadpool.h   | 4 ++++
 2 files changed, 9 insertions(+)

(limited to 'indra/llcommon')

diff --git a/indra/llcommon/threadpool.cpp b/indra/llcommon/threadpool.cpp
index d5adf11264..4a7ead2110 100644
--- a/indra/llcommon/threadpool.cpp
+++ b/indra/llcommon/threadpool.cpp
@@ -39,6 +39,11 @@ void LL::ThreadPool::start()
                 run(tname);
             });
     }
+
+    // Special workflow for LLWindowWin32Thread - it's close() should be called explicitly
+    if (mExplicitShutdown)
+        return;
+
     // Listen on "LLApp", and when the app is shutting down, close the queue
     // and join the workers.
     LLEventPumps::instance().obtain("LLApp").listen(
diff --git a/indra/llcommon/threadpool.h b/indra/llcommon/threadpool.h
index f8eec3b457..0a5f14529b 100644
--- a/indra/llcommon/threadpool.h
+++ b/indra/llcommon/threadpool.h
@@ -59,6 +59,10 @@ namespace LL
          */
         virtual void run();
 
+    protected:
+        // LLWindowWin32Thread should set this flag to true
+        bool mExplicitShutdown { false };
+
     private:
         void run(const std::string& name);
 
-- 
cgit v1.2.3


From 27ee831e38b66bb3415c3df02fd2c518463ba404 Mon Sep 17 00:00:00 2001
From: Nat Goodspeed <nat@lindenlab.com>
Date: Fri, 19 May 2023 15:35:09 -0400
Subject: SL-19744: Remove LLErrorThread and LLAppViewer::handleViewerCrash()

---
 indra/llcommon/llapp.cpp         |  38 +----------
 indra/llcommon/llapp.h           |  16 +----
 indra/llcommon/llerror.h         |   1 -
 indra/llcommon/llerrorthread.cpp | 133 ---------------------------------------
 indra/llcommon/llerrorthread.h   |  46 --------------
 5 files changed, 5 insertions(+), 229 deletions(-)
 delete mode 100644 indra/llcommon/llerrorthread.cpp
 delete mode 100644 indra/llcommon/llerrorthread.h

(limited to 'indra/llcommon')

diff --git a/indra/llcommon/llapp.cpp b/indra/llcommon/llapp.cpp
index d839b19c99..89917b6324 100644
--- a/indra/llcommon/llapp.cpp
+++ b/indra/llcommon/llapp.cpp
@@ -39,7 +39,6 @@
 #include "llcommon.h"
 #include "llapr.h"
 #include "llerrorcontrol.h"
-#include "llerrorthread.h"
 #include "llframetimer.h"
 #include "lllivefile.h"
 #include "llmemory.h"
@@ -108,12 +107,7 @@ LLAppErrorHandler LLApp::sErrorHandler = NULL;
 BOOL LLApp::sErrorThreadRunning = FALSE;
 
 
-LLApp::LLApp() : mThreadErrorp(NULL)
-{
-	commonCtor();
-}
-
-void LLApp::commonCtor()
+LLApp::LLApp()
 {
 	// Set our status to running
 	setStatus(APP_STATUS_RUNNING);
@@ -143,12 +137,6 @@ void LLApp::commonCtor()
 	mCrashReportPipeStr = L"\\\\.\\pipe\\LLCrashReporterPipe";
 }
 
-LLApp::LLApp(LLErrorThread *error_thread) :
-	mThreadErrorp(error_thread)
-{
-	commonCtor();
-}
-
 
 LLApp::~LLApp()
 {
@@ -158,13 +146,6 @@ LLApp::~LLApp()
 	mLiveFiles.clear();
 
 	setStopped();
-	// HACK: wait for the error thread to clean itself
-	ms_sleep(20);
-	if (mThreadErrorp)
-	{
-		delete mThreadErrorp;
-		mThreadErrorp = NULL;
-	}
 
 	SUBSYSTEM_CLEANUP_DBG(LLCommon);
 }
@@ -401,21 +382,6 @@ void LLApp::setupErrorHandling(bool second_instance)
 #endif
 }
 
-void LLApp::startErrorThread()
-{
-	//
-	// Start the error handling thread, which is responsible for taking action
-	// when the app goes into the APP_STATUS_ERROR state
-	//
-	if(!mThreadErrorp)
-	{
-		LL_INFOS() << "Starting error thread" << LL_ENDL;
-		mThreadErrorp = new LLErrorThread();
-		mThreadErrorp->setUserData((void *) this);
-		mThreadErrorp->start();
-	}
-}
-
 void LLApp::setErrorHandler(LLAppErrorHandler handler)
 {
 	LLApp::sErrorHandler = handler;
@@ -476,7 +442,7 @@ void LLApp::setStatus(EAppStatus status)
 // static
 void LLApp::setError()
 {
-	// set app status to ERROR so that the LLErrorThread notices
+	// set app status to ERROR
 	setStatus(APP_STATUS_ERROR);
 }
 
diff --git a/indra/llcommon/llapp.h b/indra/llcommon/llapp.h
index c65fe21c9c..436bc5437e 100644
--- a/indra/llcommon/llapp.h
+++ b/indra/llcommon/llapp.h
@@ -34,7 +34,6 @@
 #include <atomic>
 #include <chrono>
 // Forward declarations
-class LLErrorThread;
 class LLLiveFile;
 #if LL_LINUX
 #include <signal.h>
@@ -53,7 +52,6 @@ void clear_signals();
 
 class LL_COMMON_API LLApp
 {
-	friend class LLErrorThread;
 public:
 	typedef enum e_app_status
 	{
@@ -67,11 +65,6 @@ public:
 	LLApp();
 	virtual ~LLApp();
 
-protected:
-	LLApp(LLErrorThread* error_thread);
-	void commonCtor();
-public:
-	
 	/** 
 	 * @brief Return the static app instance if one was created.
 	 */
@@ -257,14 +250,14 @@ public:
 	void setupErrorHandling(bool mSecondInstance=false);
 
 	void setErrorHandler(LLAppErrorHandler handler);
-	static void runErrorHandler(); // run shortly after we detect an error, ran in the relatively robust context of the LLErrorThread - preferred.
+	static void runErrorHandler(); // run shortly after we detect an error
 	//@}
-	
+
 	// the maximum length of the minidump filename returned by getMiniDumpFilename()
 	static const U32 MAX_MINDUMP_PATH_LENGTH = 256;
 
 	// change the directory where Breakpad minidump files are written to
-    void setDebugFileNames(const std::string &path);
+	void setDebugFileNames(const std::string &path);
 
 	// Return the Google Breakpad minidump filename after a crash.
 	char *getMiniDumpFilename() { return mMinidumpPath; }
@@ -324,9 +317,6 @@ private:
 	typedef int(*signal_handler_func)(int signum);
 	static LLAppErrorHandler sErrorHandler;
 
-	// Default application threads
-	LLErrorThread* mThreadErrorp;		// Waits for app to go to status ERROR, then runs the error callback
-
 	// This is the application level runnable scheduler.
 	LLRunner mRunner;
 
diff --git a/indra/llcommon/llerror.h b/indra/llcommon/llerror.h
index d06c0e2132..020f05e8f5 100644
--- a/indra/llcommon/llerror.h
+++ b/indra/llcommon/llerror.h
@@ -274,7 +274,6 @@ namespace LLError
 		// used to indicate no class info known for logging
 
     //LLCallStacks keeps track of call stacks and output the call stacks to log file
-    //when LLAppViewer::handleViewerCrash() is triggered.
     //
     //Note: to be simple, efficient and necessary to keep track of correct call stacks, 
     //LLCallStacks is designed not to be thread-safe.
diff --git a/indra/llcommon/llerrorthread.cpp b/indra/llcommon/llerrorthread.cpp
deleted file mode 100644
index f6bc68b5c1..0000000000
--- a/indra/llcommon/llerrorthread.cpp
+++ /dev/null
@@ -1,133 +0,0 @@
-/** 
- * @file llerrorthread.cpp
- *
- * $LicenseInfo:firstyear=2004&license=viewerlgpl$
- * Second Life Viewer Source Code
- * Copyright (C) 2010, 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 "linden_common.h"
-#include "llerrorthread.h"
-
-#include "llapp.h"
-#include "lltimer.h"	// ms_sleep()
-
-LLErrorThread::LLErrorThread()
-	: LLThread("Error"),
-	  mUserDatap(NULL)
-{
-}
-
-LLErrorThread::~LLErrorThread()
-{
-}
-
-void LLErrorThread::setUserData(void* user_data)
-{
-	mUserDatap = user_data;
-}
-
-
-void* LLErrorThread::getUserData() const
-{
-	return mUserDatap;
-}
-
-#if !LL_WINDOWS
-//
-// Various signal/error handling functions that can't be put into the class
-//
-void get_child_status(const int waitpid_status, int &process_status, bool &exited, bool do_logging)
-{
-	exited = false;
-	process_status = -1;
-	// The child process exited.  Call its callback, and then clean it up
-	if (WIFEXITED(waitpid_status))
-	{
-		process_status = WEXITSTATUS(waitpid_status);
-		exited = true;
-		if (do_logging)
-		{
-			LL_INFOS() << "get_child_status - Child exited cleanly with return of " << process_status << LL_ENDL;
-		}
-		return;
-	}
-	else if (WIFSIGNALED(waitpid_status))
-	{
-		process_status = WTERMSIG(waitpid_status);
-		exited = true;
-		if (do_logging)
-		{
-			LL_INFOS() << "get_child_status - Child died because of uncaught signal " << process_status << LL_ENDL;
-#ifdef WCOREDUMP
-			if (WCOREDUMP(waitpid_status))
-			{
-				LL_INFOS() << "get_child_status - Child dumped core" << LL_ENDL;
-			}
-			else
-			{
-				LL_INFOS() << "get_child_status - Child didn't dump core" << LL_ENDL;
-			}
-#endif
-		}
-		return;
-	}
-	else if (do_logging)
-	{
-		// This is weird.  I just dump the waitpid status into the status code,
-		// not that there's any way of telling what it is...
-		LL_INFOS() << "get_child_status - Got SIGCHILD but child didn't exit" << LL_ENDL;
-		process_status = waitpid_status;
-	}
-
-}
-#endif
-
-void LLErrorThread::run()
-{
-	LLApp::sErrorThreadRunning = TRUE;
-	// This thread sits and waits for the sole purpose
-	// of waiting for the signal/exception handlers to flag the
-	// application state as APP_STATUS_ERROR.
-	LL_INFOS() << "thread_error - Waiting for an error" << LL_ENDL;
-
-	S32 counter = 0;
-	while (! (LLApp::isError() || LLApp::isStopped()))
-	{
-		ms_sleep(10);
-		counter++;
-	}
-	if (LLApp::isError())
-	{
-		// The app is in an error state, run the application's error handler.
-		//LL_INFOS() << "thread_error - An error has occurred, running error callback!" << LL_ENDL;
-		// Run the error handling callback
-		LLApp::runErrorHandler();
-	}
-	else
-	{
-		// Everything is okay, a clean exit.
-		//LL_INFOS() << "thread_error - Application exited cleanly" << LL_ENDL;
-	}
-	
-	//LL_INFOS() << "thread_error - Exiting" << LL_ENDL;
-	LLApp::sErrorThreadRunning = FALSE;
-}
-
diff --git a/indra/llcommon/llerrorthread.h b/indra/llcommon/llerrorthread.h
deleted file mode 100644
index 474cef3a50..0000000000
--- a/indra/llcommon/llerrorthread.h
+++ /dev/null
@@ -1,46 +0,0 @@
-/** 
- * @file llerrorthread.h
- * @brief Specialized thread to handle runtime errors.
- *
- * $LicenseInfo:firstyear=2004&license=viewerlgpl$
- * Second Life Viewer Source Code
- * Copyright (C) 2010, 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_LLERRORTHREAD_H
-#define LL_LLERRORTHREAD_H
-
-#include "llthread.h"
-
-class LL_COMMON_API LLErrorThread : public LLThread
-{
-public:
-	LLErrorThread();
-	~LLErrorThread();
-
-	/*virtual*/ void run(void);
-	void setUserData(void *user_data);
-	void *getUserData() const;
-
-protected:
-	void* mUserDatap; // User data associated with this thread
-};
-
-#endif // LL_LLERRORTHREAD_H
-- 
cgit v1.2.3


From 863e7f22a75e9d9c9d5c1f826eac6cd0000edac0 Mon Sep 17 00:00:00 2001
From: Nat Goodspeed <nat@lindenlab.com>
Date: Fri, 19 May 2023 16:19:42 -0400
Subject: SL-19744: Remove LLApp::startErrorThread() and references.

---
 indra/llcommon/CMakeLists.txt | 2 --
 indra/llcommon/llapp.cpp      | 6 ------
 indra/llcommon/llapp.h        | 6 ++----
 3 files changed, 2 insertions(+), 12 deletions(-)

(limited to 'indra/llcommon')

diff --git a/indra/llcommon/CMakeLists.txt b/indra/llcommon/CMakeLists.txt
index 54020a4231..ef4899978e 100644
--- a/indra/llcommon/CMakeLists.txt
+++ b/indra/llcommon/CMakeLists.txt
@@ -39,7 +39,6 @@ set(llcommon_SOURCE_FILES
     lldependencies.cpp
     lldictionary.cpp
     llerror.cpp
-    llerrorthread.cpp
     llevent.cpp
     lleventapi.cpp
     lleventcoro.cpp
@@ -151,7 +150,6 @@ set(llcommon_HEADER_FILES
     llendianswizzle.h
     llerror.h
     llerrorcontrol.h
-    llerrorthread.h
     llevent.h
     lleventapi.h
     lleventcoro.h
diff --git a/indra/llcommon/llapp.cpp b/indra/llcommon/llapp.cpp
index 89917b6324..b99166991f 100644
--- a/indra/llcommon/llapp.cpp
+++ b/indra/llcommon/llapp.cpp
@@ -374,12 +374,6 @@ void LLApp::setupErrorHandling(bool second_instance)
 #endif // ! LL_BUGSPLAT
 
 #endif // ! LL_WINDOWS
-
-#ifdef LL_BUGSPLAT
-    // do not start our own error thread
-#else // ! LL_BUGSPLAT
-	startErrorThread();
-#endif
 }
 
 void LLApp::setErrorHandler(LLAppErrorHandler handler)
diff --git a/indra/llcommon/llapp.h b/indra/llcommon/llapp.h
index 436bc5437e..c832c8b142 100644
--- a/indra/llcommon/llapp.h
+++ b/indra/llcommon/llapp.h
@@ -303,13 +303,11 @@ protected:
 	void stepFrame();
 
 private:
-	void startErrorThread();
-	
 	// Contains the filename of the minidump file after a crash.
 	char mMinidumpPath[MAX_MINDUMP_PATH_LENGTH];
     
-    std::string mStaticDebugFileName;
-    std::string mDynamicDebugFileName;
+	std::string mStaticDebugFileName;
+	std::string mDynamicDebugFileName;
 
 	// *NOTE: On Windows, we need a routine to reset the structured
 	// exception handler when some evil driver has taken it over for
-- 
cgit v1.2.3


From 79198eddf76dfa69e8161f7646d8da19853a8a5a Mon Sep 17 00:00:00 2001
From: Andrey Lihatskiy <alihatskiy@productengine.com>
Date: Fri, 7 Jul 2023 20:24:49 +0300
Subject: SL-19966 Reverted "SL-18721: Faster viewer shutdown time since
 performance improvements can lead to perceived inventory loss due to cache
 corruption"

This reverts commit cf692c40b0b9f8d0d04cd10a02a84e3f697a2e99.
---
 indra/llcommon/threadpool.cpp | 5 -----
 indra/llcommon/threadpool.h   | 4 ----
 2 files changed, 9 deletions(-)

(limited to 'indra/llcommon')

diff --git a/indra/llcommon/threadpool.cpp b/indra/llcommon/threadpool.cpp
index 4a7ead2110..d5adf11264 100644
--- a/indra/llcommon/threadpool.cpp
+++ b/indra/llcommon/threadpool.cpp
@@ -39,11 +39,6 @@ void LL::ThreadPool::start()
                 run(tname);
             });
     }
-
-    // Special workflow for LLWindowWin32Thread - it's close() should be called explicitly
-    if (mExplicitShutdown)
-        return;
-
     // Listen on "LLApp", and when the app is shutting down, close the queue
     // and join the workers.
     LLEventPumps::instance().obtain("LLApp").listen(
diff --git a/indra/llcommon/threadpool.h b/indra/llcommon/threadpool.h
index 0a5f14529b..f8eec3b457 100644
--- a/indra/llcommon/threadpool.h
+++ b/indra/llcommon/threadpool.h
@@ -59,10 +59,6 @@ namespace LL
          */
         virtual void run();
 
-    protected:
-        // LLWindowWin32Thread should set this flag to true
-        bool mExplicitShutdown { false };
-
     private:
         void run(const std::string& name);
 
-- 
cgit v1.2.3