From 023af775d552709dd8f6f8ee77aeb939510aaed2 Mon Sep 17 00:00:00 2001
From: brad kittenbrink <brad@lindenlab.com>
Date: Mon, 22 Nov 2010 19:06:49 -0800
Subject: Added failing unit test which I believe should exercise CHOP-220
 crash.

---
 indra/newview/CMakeLists.txt                       |   1 +
 indra/newview/llagent.h                            |   1 +
 indra/newview/tests/llremoteparcelrequest_test.cpp | 130 +++++++++++++++++++++
 3 files changed, 132 insertions(+)
 create mode 100644 indra/newview/tests/llremoteparcelrequest_test.cpp

(limited to 'indra')

diff --git a/indra/newview/CMakeLists.txt b/indra/newview/CMakeLists.txt
index fa49c1ac4c..679637caf6 100644
--- a/indra/newview/CMakeLists.txt
+++ b/indra/newview/CMakeLists.txt
@@ -1877,6 +1877,7 @@ if (LL_TESTS)
     lldateutil.cpp
     llmediadataclient.cpp
     lllogininstance.cpp
+    llremoteparcelrequest.cpp
     llviewerhelputil.cpp
     llversioninfo.cpp
   )
diff --git a/indra/newview/llagent.h b/indra/newview/llagent.h
index 6c598d5d71..aebebad96a 100644
--- a/indra/newview/llagent.h
+++ b/indra/newview/llagent.h
@@ -33,6 +33,7 @@
 #include "llagentconstants.h"
 #include "llagentdata.h" 			// gAgentID, gAgentSessionID
 #include "llcharacter.h" 			// LLAnimPauseRequest
+#include "llcoordframe.h"			// for mFrameAgent
 #include "llpointer.h"
 #include "lluicolor.h"
 #include "llvoavatardefines.h"
diff --git a/indra/newview/tests/llremoteparcelrequest_test.cpp b/indra/newview/tests/llremoteparcelrequest_test.cpp
new file mode 100644
index 0000000000..6f9be3df68
--- /dev/null
+++ b/indra/newview/tests/llremoteparcelrequest_test.cpp
@@ -0,0 +1,130 @@
+/** 
+ * @file llremoteparcelrequest_test.cpp
+ * @author Brad Kittenbrink <brad@lindenlab.com>
+ *
+ * $LicenseInfo:firstyear=2010&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 "../test/lltut.h"
+
+#include "../llremoteparcelrequest.h"
+
+#include "../llagent.h"
+#include "message.h"
+
+namespace {
+	LLControlGroup s_saved_settings("dummy_settings");
+}
+
+LLCurl::Responder::Responder() { }
+LLCurl::Responder::~Responder() { }
+void LLCurl::Responder::error(U32,std::string const &) { }
+void LLCurl::Responder::result(LLSD const &) { }
+void LLCurl::Responder::errorWithContent(U32 status,std::string const &,LLSD const &) { }
+void LLCurl::Responder::completedRaw(U32 status, std::string const &, LLChannelDescriptors const &,boost::shared_ptr<LLBufferArray> const &) { }
+void LLCurl::Responder::completed(U32 status, std::string const &, LLSD const &) { }
+void LLCurl::Responder::completedHeader(U32 status, std::string const &, LLSD const &) { }
+void LLMessageSystem::getF32(char const *,char const *,F32 &,S32) { }
+void LLMessageSystem::getU8(char const *,char const *,U8 &,S32) { }
+void LLMessageSystem::getS32(char const *,char const *,S32 &,S32) { }
+void LLMessageSystem::getString(char const *,char const *, std::string &,S32) { }
+void LLMessageSystem::getUUID(char const *,char const *, LLUUID &,S32) { }
+void LLMessageSystem::nextBlock(char const *) { }
+void LLMessageSystem::addUUID(char const *,LLUUID const &) { }
+void LLMessageSystem::addUUIDFast(char const *,LLUUID const &) { }
+void LLMessageSystem::nextBlockFast(char const *) { }
+void LLMessageSystem::newMessage(char const *) { }
+LLMessageSystem * gMessageSystem;
+char * _PREHASH_AgentID;
+char * _PREHASH_AgentData;
+LLAgent gAgent;
+LLAgent::LLAgent() : mAgentAccess(s_saved_settings) { }
+LLAgent::~LLAgent() { }
+void LLAgent::sendReliableMessage(void) { }
+LLUUID gAgentSessionID;
+LLUUID gAgentID;
+LLUIColor::LLUIColor(void) { }
+LLAgentAccess::LLAgentAccess(LLControlGroup & settings) : mSavedSettings(settings) { }
+LLControlGroup::LLControlGroup(std::string const & name) : LLInstanceTracker<LLControlGroup, std::string>(name) { }
+LLControlGroup::~LLControlGroup(void) { }
+
+namespace tut
+{
+	struct TestObserver : public LLRemoteParcelInfoObserver {
+		TestObserver() : mProcessed(false) { }
+
+		virtual void processParcelInfo(const LLParcelData& parcel_data)
+		{
+			mProcessed = true;
+		}
+
+		virtual void setParcelID(const LLUUID& parcel_id) { }
+
+		virtual void setErrorStatus(U32 status, const std::string& reason) { }
+
+		bool mProcessed;
+	};
+
+    struct RemoteParcelRequestData
+    {
+		RemoteParcelRequestData()
+		{
+		}
+    };
+    
+	typedef test_group<RemoteParcelRequestData> remoteparcelrequest_t;
+	typedef remoteparcelrequest_t::object remoteparcelrequest_object_t;
+	tut::remoteparcelrequest_t tut_remoteparcelrequest("LLRemoteParcelRequest");
+
+	template<> template<>
+	void remoteparcelrequest_object_t::test<1>()
+	{
+		set_test_name("observer pointer");
+
+		boost::scoped_ptr<TestObserver> observer(new TestObserver());
+
+		LLRemoteParcelInfoProcessor & processor = LLRemoteParcelInfoProcessor::instance();
+		processor.addObserver(LLUUID(), observer.get());
+
+		processor.processParcelInfoReply(gMessageSystem, NULL);
+
+		ensure(observer->mProcessed);
+	}
+
+	template<> template<>
+	void remoteparcelrequest_object_t::test<2>()
+	{
+		set_test_name("CHOP-220: dangling observer pointer");
+
+		LLRemoteParcelInfoObserver * observer = new TestObserver();
+
+		LLRemoteParcelInfoProcessor & processor = LLRemoteParcelInfoProcessor::instance();
+		processor.addObserver(LLUUID(), observer);
+
+		delete observer;
+		observer = NULL;
+
+		processor.processParcelInfoReply(gMessageSystem, NULL);
+	}
+}
-- 
cgit v1.2.3


From 7db4d2b88f24ae5fe6051968d6d4c3ba9aadf817 Mon Sep 17 00:00:00 2001
From: brad kittenbrink <brad@lindenlab.com>
Date: Mon, 22 Nov 2010 19:07:17 -0800
Subject: Fix for CHOP-220.  Reviewed by mani.

---
 indra/newview/llpanellandmarks.cpp      |  3 --
 indra/newview/llpanelpick.cpp           |  3 --
 indra/newview/llpanelplaceinfo.cpp      |  4 ---
 indra/newview/llremoteparcelrequest.cpp | 53 ++++++++++++++++++++-------------
 indra/newview/llremoteparcelrequest.h   |  2 +-
 5 files changed, 34 insertions(+), 31 deletions(-)

(limited to 'indra')

diff --git a/indra/newview/llpanellandmarks.cpp b/indra/newview/llpanellandmarks.cpp
index d25b8e0e02..e8c8273a9d 100644
--- a/indra/newview/llpanellandmarks.cpp
+++ b/indra/newview/llpanellandmarks.cpp
@@ -520,9 +520,6 @@ void LLLandmarksPanel::setParcelID(const LLUUID& parcel_id)
 {
 	if (!parcel_id.isNull())
 	{
-        //ext-4655, defensive. remove now incase this gets called twice without a remove
-        LLRemoteParcelInfoProcessor::getInstance()->removeObserver(parcel_id, this);
-        
 		LLRemoteParcelInfoProcessor::getInstance()->addObserver(parcel_id, this);
 		LLRemoteParcelInfoProcessor::getInstance()->sendParcelInfoRequest(parcel_id);
 	}
diff --git a/indra/newview/llpanelpick.cpp b/indra/newview/llpanelpick.cpp
index 271728220c..44cca21a76 100644
--- a/indra/newview/llpanelpick.cpp
+++ b/indra/newview/llpanelpick.cpp
@@ -204,9 +204,6 @@ void LLPanelPickInfo::sendParcelInfoRequest()
 {
 	if (mParcelId != mRequestedId)
 	{
-        //ext-4655, remove now incase this gets called twice without a remove
-        LLRemoteParcelInfoProcessor::getInstance()->removeObserver(mRequestedId, this);
-        
 		LLRemoteParcelInfoProcessor::getInstance()->addObserver(mParcelId, this);
 		LLRemoteParcelInfoProcessor::getInstance()->sendParcelInfoRequest(mParcelId);
 
diff --git a/indra/newview/llpanelplaceinfo.cpp b/indra/newview/llpanelplaceinfo.cpp
index 9cbb512e70..4ae0c0eb12 100644
--- a/indra/newview/llpanelplaceinfo.cpp
+++ b/indra/newview/llpanelplaceinfo.cpp
@@ -128,10 +128,6 @@ void LLPanelPlaceInfo::sendParcelInfoRequest()
 {
 	if (mParcelID != mRequestedID)
 	{
-        //ext-4655, defensive. remove now incase this gets called twice without a remove
-        //as panel never closes its ok atm (but wrong :) 
-        LLRemoteParcelInfoProcessor::getInstance()->removeObserver(mRequestedID, this);
-
 		LLRemoteParcelInfoProcessor::getInstance()->addObserver(mParcelID, this);
 		LLRemoteParcelInfoProcessor::getInstance()->sendParcelInfoRequest(mParcelID);
 
diff --git a/indra/newview/llremoteparcelrequest.cpp b/indra/newview/llremoteparcelrequest.cpp
index d63a48647d..10d4452ed2 100644
--- a/indra/newview/llremoteparcelrequest.cpp
+++ b/indra/newview/llremoteparcelrequest.cpp
@@ -77,23 +77,19 @@ void LLRemoteParcelRequestResponder::error(U32 status, const std::string& reason
 
 void LLRemoteParcelInfoProcessor::addObserver(const LLUUID& parcel_id, LLRemoteParcelInfoObserver* observer)
 {
-	// Check if the observer is already in observers list for this UUID
 	observer_multimap_t::iterator it;
+	observer_multimap_t::iterator end = mObservers.upper_bound(parcel_id);
 
-	it = mObservers.find(parcel_id);
-	while (it != mObservers.end())
+	// Check if the observer is already in observers list for this UUID
+	for(it = mObservers.find(parcel_id); it != end; ++it)
 	{
-		if (it->second == observer)
+		if (it->second.get() == observer)
 		{
 			return;
 		}
-		else
-		{
-			++it;
-		}
 	}
 
-	mObservers.insert(std::pair<LLUUID, LLRemoteParcelInfoObserver*>(parcel_id, observer));
+	mObservers.insert(std::make_pair(parcel_id, observer->getObserverHandle()));
 }
 
 void LLRemoteParcelInfoProcessor::removeObserver(const LLUUID& parcel_id, LLRemoteParcelInfoObserver* observer)
@@ -104,19 +100,15 @@ void LLRemoteParcelInfoProcessor::removeObserver(const LLUUID& parcel_id, LLRemo
 	}
 
 	observer_multimap_t::iterator it;
+	observer_multimap_t::iterator end = mObservers.upper_bound(parcel_id);
 
-	it = mObservers.find(parcel_id);
-	while (it != mObservers.end())
+	for(it = mObservers.find(parcel_id); it != end; ++it)
 	{
-		if (it->second == observer)
+		if (it->second.get() == observer)
 		{
 			mObservers.erase(it);
 			break;
 		}
-		else
-		{
-			++it;
-		}
 	}
 }
 
@@ -141,13 +133,34 @@ void LLRemoteParcelInfoProcessor::processParcelInfoReply(LLMessageSystem* msg, v
 	msg->getS32		("Data", "SalePrice", parcel_data.sale_price);
 	msg->getS32		("Data", "AuctionID", parcel_data.auction_id);
 
-	LLRemoteParcelInfoProcessor::observer_multimap_t observers = LLRemoteParcelInfoProcessor::getInstance()->mObservers;
+	LLRemoteParcelInfoProcessor::observer_multimap_t & observers = LLRemoteParcelInfoProcessor::getInstance()->mObservers;
+
+	typedef std::vector<observer_multimap_t::iterator> deadlist_t;
+	deadlist_t dead_iters;
 
-	observer_multimap_t::iterator oi = observers.find(parcel_data.parcel_id);
+	observer_multimap_t::iterator oi;
 	observer_multimap_t::iterator end = observers.upper_bound(parcel_data.parcel_id);
-	for (; oi != end; ++oi)
+
+	for (oi = observers.find(parcel_data.parcel_id); oi != end; ++oi)
+	{
+		LLRemoteParcelInfoObserver * observer = oi->second.get();
+		if(observer)
+		{
+			observer->processParcelInfo(parcel_data);
+		}
+		else
+		{
+			// the handle points to an expired observer, so don't keep it
+			// around anymore
+			dead_iters.push_back(oi);
+		}
+	}
+
+	deadlist_t::iterator i;
+	deadlist_t::iterator end_dead = dead_iters.end();
+	for(i = dead_iters.begin(); i != end_dead; ++i)
 	{
-		oi->second->processParcelInfo(parcel_data);
+		observers.erase(*i);
 	}
 }
 
diff --git a/indra/newview/llremoteparcelrequest.h b/indra/newview/llremoteparcelrequest.h
index a6c62995a9..74cf1616df 100644
--- a/indra/newview/llremoteparcelrequest.h
+++ b/indra/newview/llremoteparcelrequest.h
@@ -98,7 +98,7 @@ public:
 	static void processParcelInfoReply(LLMessageSystem* msg, void**);
 
 private:
-	typedef std::multimap<LLUUID, LLRemoteParcelInfoObserver*> observer_multimap_t;
+	typedef std::multimap<LLUUID, LLHandle<LLRemoteParcelInfoObserver> > observer_multimap_t;
 	observer_multimap_t mObservers;
 };
 
-- 
cgit v1.2.3


From 7233506624dc4c315c883b6e9e1f5a3f1d373132 Mon Sep 17 00:00:00 2001
From: brad kittenbrink <brad@lindenlab.com>
Date: Mon, 22 Nov 2010 19:51:47 -0800
Subject: Minor improvement to CHOP-220 unit test.

---
 indra/newview/tests/llremoteparcelrequest_test.cpp | 212 +++++++++++----------
 1 file changed, 108 insertions(+), 104 deletions(-)

(limited to 'indra')

diff --git a/indra/newview/tests/llremoteparcelrequest_test.cpp b/indra/newview/tests/llremoteparcelrequest_test.cpp
index 6f9be3df68..a6c1f69c82 100644
--- a/indra/newview/tests/llremoteparcelrequest_test.cpp
+++ b/indra/newview/tests/llremoteparcelrequest_test.cpp
@@ -1,44 +1,45 @@
-/** 
- * @file llremoteparcelrequest_test.cpp
- * @author Brad Kittenbrink <brad@lindenlab.com>
- *
- * $LicenseInfo:firstyear=2010&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 "../test/lltut.h"
-
-#include "../llremoteparcelrequest.h"
-
-#include "../llagent.h"
-#include "message.h"
-
-namespace {
-	LLControlGroup s_saved_settings("dummy_settings");
-}
-
-LLCurl::Responder::Responder() { }
-LLCurl::Responder::~Responder() { }
+/** 
+ * @file llremoteparcelrequest_test.cpp
+ * @author Brad Kittenbrink <brad@lindenlab.com>
+ *
+ * $LicenseInfo:firstyear=2010&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 "../test/lltut.h"
+
+#include "../llremoteparcelrequest.h"
+
+#include "../llagent.h"
+#include "message.h"
+
+namespace {
+	LLControlGroup s_saved_settings("dummy_settings");
+	const LLUUID TEST_PARCEL_ID("11111111-1111-1111-1111-111111111111");
+}
+
+LLCurl::Responder::Responder() { }
+LLCurl::Responder::~Responder() { }
 void LLCurl::Responder::error(U32,std::string const &) { }
 void LLCurl::Responder::result(LLSD const &) { }
 void LLCurl::Responder::errorWithContent(U32 status,std::string const &,LLSD const &) { }
@@ -49,7 +50,10 @@ void LLMessageSystem::getF32(char const *,char const *,F32 &,S32) { }
 void LLMessageSystem::getU8(char const *,char const *,U8 &,S32) { }
 void LLMessageSystem::getS32(char const *,char const *,S32 &,S32) { }
 void LLMessageSystem::getString(char const *,char const *, std::string &,S32) { }
-void LLMessageSystem::getUUID(char const *,char const *, LLUUID &,S32) { }
+void LLMessageSystem::getUUID(char const *,char const *, LLUUID & out_id,S32)
+{
+	out_id = TEST_PARCEL_ID;
+}
 void LLMessageSystem::nextBlock(char const *) { }
 void LLMessageSystem::addUUID(char const *,LLUUID const &) { }
 void LLMessageSystem::addUUIDFast(char const *,LLUUID const &) { }
@@ -63,68 +67,68 @@ LLAgent::LLAgent() : mAgentAccess(s_saved_settings) { }
 LLAgent::~LLAgent() { }
 void LLAgent::sendReliableMessage(void) { }
 LLUUID gAgentSessionID;
-LLUUID gAgentID;
+LLUUID gAgentID;
 LLUIColor::LLUIColor(void) { }
 LLAgentAccess::LLAgentAccess(LLControlGroup & settings) : mSavedSettings(settings) { }
 LLControlGroup::LLControlGroup(std::string const & name) : LLInstanceTracker<LLControlGroup, std::string>(name) { }
-LLControlGroup::~LLControlGroup(void) { }
-
-namespace tut
-{
-	struct TestObserver : public LLRemoteParcelInfoObserver {
-		TestObserver() : mProcessed(false) { }
-
-		virtual void processParcelInfo(const LLParcelData& parcel_data)
-		{
-			mProcessed = true;
-		}
-
-		virtual void setParcelID(const LLUUID& parcel_id) { }
-
-		virtual void setErrorStatus(U32 status, const std::string& reason) { }
-
-		bool mProcessed;
-	};
-
-    struct RemoteParcelRequestData
-    {
-		RemoteParcelRequestData()
-		{
-		}
-    };
-    
-	typedef test_group<RemoteParcelRequestData> remoteparcelrequest_t;
-	typedef remoteparcelrequest_t::object remoteparcelrequest_object_t;
-	tut::remoteparcelrequest_t tut_remoteparcelrequest("LLRemoteParcelRequest");
-
-	template<> template<>
-	void remoteparcelrequest_object_t::test<1>()
-	{
-		set_test_name("observer pointer");
-
-		boost::scoped_ptr<TestObserver> observer(new TestObserver());
-
-		LLRemoteParcelInfoProcessor & processor = LLRemoteParcelInfoProcessor::instance();
-		processor.addObserver(LLUUID(), observer.get());
-
-		processor.processParcelInfoReply(gMessageSystem, NULL);
-
-		ensure(observer->mProcessed);
-	}
-
-	template<> template<>
-	void remoteparcelrequest_object_t::test<2>()
-	{
-		set_test_name("CHOP-220: dangling observer pointer");
-
-		LLRemoteParcelInfoObserver * observer = new TestObserver();
-
-		LLRemoteParcelInfoProcessor & processor = LLRemoteParcelInfoProcessor::instance();
-		processor.addObserver(LLUUID(), observer);
-
-		delete observer;
-		observer = NULL;
-
-		processor.processParcelInfoReply(gMessageSystem, NULL);
-	}
-}
+LLControlGroup::~LLControlGroup(void) { }
+
+namespace tut
+{
+	struct TestObserver : public LLRemoteParcelInfoObserver {
+		TestObserver() : mProcessed(false) { }
+
+		virtual void processParcelInfo(const LLParcelData& parcel_data)
+		{
+			mProcessed = true;
+		}
+
+		virtual void setParcelID(const LLUUID& parcel_id) { }
+
+		virtual void setErrorStatus(U32 status, const std::string& reason) { }
+
+		bool mProcessed;
+	};
+
+    struct RemoteParcelRequestData
+    {
+		RemoteParcelRequestData()
+		{
+		}
+    };
+    
+	typedef test_group<RemoteParcelRequestData> remoteparcelrequest_t;
+	typedef remoteparcelrequest_t::object remoteparcelrequest_object_t;
+	tut::remoteparcelrequest_t tut_remoteparcelrequest("LLRemoteParcelRequest");
+
+	template<> template<>
+	void remoteparcelrequest_object_t::test<1>()
+	{
+		set_test_name("observer pointer");
+
+		boost::scoped_ptr<TestObserver> observer(new TestObserver());
+
+		LLRemoteParcelInfoProcessor & processor = LLRemoteParcelInfoProcessor::instance();
+		processor.addObserver(LLUUID(TEST_PARCEL_ID), observer.get());
+
+		processor.processParcelInfoReply(gMessageSystem, NULL);
+
+		ensure(observer->mProcessed);
+	}
+
+	template<> template<>
+	void remoteparcelrequest_object_t::test<2>()
+	{
+		set_test_name("CHOP-220: dangling observer pointer");
+
+		LLRemoteParcelInfoObserver * observer = new TestObserver();
+
+		LLRemoteParcelInfoProcessor & processor = LLRemoteParcelInfoProcessor::instance();
+		processor.addObserver(LLUUID(TEST_PARCEL_ID), observer);
+
+		delete observer;
+		observer = NULL;
+
+		processor.processParcelInfoReply(gMessageSystem, NULL);
+	}
+}
-- 
cgit v1.2.3


From 5c70975179d21fbd96dbf5de31c4c92c2b384f78 Mon Sep 17 00:00:00 2001
From: "Andrew A. de Laix" <alain@lindenlab.com>
Date: Tue, 23 Nov 2010 11:40:54 -0800
Subject: [mq]: thread_state_fix

---
 indra/llcommon/llthread.cpp | 24 ++++++++++++++++++------
 1 file changed, 18 insertions(+), 6 deletions(-)

(limited to 'indra')

diff --git a/indra/llcommon/llthread.cpp b/indra/llcommon/llthread.cpp
index 148aaf8aed..49d05ef411 100644
--- a/indra/llcommon/llthread.cpp
+++ b/indra/llcommon/llthread.cpp
@@ -63,9 +63,6 @@ void *APR_THREAD_FUNC LLThread::staticRun(apr_thread_t *apr_threadp, void *datap
 {
 	LLThread *threadp = (LLThread *)datap;
 
-	// Set thread state to running
-	threadp->mStatus = RUNNING;
-
 	// Run the user supplied function
 	threadp->run();
 
@@ -167,10 +164,25 @@ void LLThread::shutdown()
 
 void LLThread::start()
 {
-	apr_thread_create(&mAPRThreadp, NULL, staticRun, (void *)this, mAPRPoolp);	
+	llassert(isStopped());
+	
+	// Set thread state to running
+	mStatus = RUNNING;
 
-	// We won't bother joining
-	apr_thread_detach(mAPRThreadp);
+	apr_status_t status =
+		apr_thread_create(&mAPRThreadp, NULL, staticRun, (void *)this, mAPRPoolp);
+	
+	if(status == APR_SUCCESS)
+	{	
+		// We won't bother joining
+		apr_thread_detach(mAPRThreadp);
+	}
+	else
+	{
+		mStatus = STOPPED;
+		llwarns << "failed to start thread " << mName << llendl;
+		ll_apr_warn_status(status);
+	}
 }
 
 //============================================================================
-- 
cgit v1.2.3