Commits

davep committed bc01ee2

b782a75c99e6 backout cleanup

  • Participants
  • Parent commits d67d0e1
  • Tags 3.1.0-beta2, DRTVWR-96_3.1.0-beta2

Comments (0)

Files changed (12)

indra/llcommon/llmemory.cpp

 {
 	if(type == STATIC_THREADED || type == VOLATILE_THREADED)
 	{
-		mMutexp = new LLMutex ;
+		mMutexp = new LLMutex(NULL) ;
 	}
 
 	for(S32 i = 0 ; i < SUPER_ALLOCATION ; i++)

indra/llcommon/llthread.cpp

 #include <sched.h>
 #endif
 
-#if !LL_DARWIN
-U32 ll_thread_local local_thread_ID = 0;
-#endif 
-
-U32 LLThread::sIDIter = 0;
-
 //----------------------------------------------------------------------------
 // Usage:
 // void run_func(LLThread* thread)
 // 
 //----------------------------------------------------------------------------
 
+#if !LL_DARWIN
+U32 ll_thread_local sThreadID = 0;
+#endif 
+
+U32 LLThread::sIDIter = 0;
+
 LL_COMMON_API void assert_main_thread()
 {
 	static U32 s_thread_id = LLThread::currentID();
 	LLThread *threadp = (LLThread *)datap;
 
 #if !LL_DARWIN
-	local_thread_ID = threadp->mID;
+	sThreadID = threadp->mID;
 #endif
 
 	// Run the user supplied function
 	mAPRThreadp(NULL),
 	mStatus(STOPPED)
 {
+	mID = ++sIDIter;
+
 	// Thread creation probably CAN be paranoid about APR being initialized, if necessary
 	if (poolp)
 	{
 		if (!isStopped())
 		{
 			// This thread just wouldn't stop, even though we gave it time
-			//llwarns << "LLThread::shutdown() exiting thread before clean exit!" << llendl;
+			//llwarns << "LLThread::~LLThread() exiting thread before clean exit!" << llendl;
 			// Put a stake in its heart.
 			apr_thread_exit(mAPRThreadp, -1);
 			return;
 //============================================================================
 
 LLMutex::LLMutex(apr_pool_t *poolp) :
-	mAPRMutexp(NULL)
+	mAPRMutexp(NULL), mCount(0), mLockingThread(NO_THREAD)
 {
 	//if (poolp)
 	//{
 LLMutex::~LLMutex()
 {
 #if MUTEX_DEBUG
-	llassert_always(!isLocked()); // better not be locked!
+	//bad assertion, the subclass LLSignal might be "locked", and that's OK
+	//llassert_always(!isLocked()); // better not be locked!
 #endif
 	apr_thread_mutex_destroy(mAPRMutexp);
 	mAPRMutexp = NULL;
 
 void LLMutex::lock()
 {
+#if LL_DARWIN
+	if (mLockingThread == LLThread::currentID())
+#else
+	if (mLockingThread == sThreadID)
+#endif
+	{ //redundant lock
+		mCount++;
+		return;
+	}
+	
 	apr_thread_mutex_lock(mAPRMutexp);
+	
 #if MUTEX_DEBUG
 	// Have to have the lock before we can access the debug info
 	U32 id = LLThread::currentID();
 		llerrs << "Already locked in Thread: " << id << llendl;
 	mIsLocked[id] = TRUE;
 #endif
+
+#if LL_DARWIN
+	mLockingThread = LLThread::currentID();
+#else
+	mLockingThread = sThreadID;
+#endif
 }
 
 void LLMutex::unlock()
 {
+	if (mCount > 0)
+	{ //not the root unlock
+		mCount--;
+		return;
+	}
+	
 #if MUTEX_DEBUG
 	// Access the debug info while we have the lock
 	U32 id = LLThread::currentID();
 		llerrs << "Not locked in Thread: " << id << llendl;	
 	mIsLocked[id] = FALSE;
 #endif
+
+	mLockingThread = NO_THREAD;
 	apr_thread_mutex_unlock(mAPRMutexp);
 }
 
 	}
 }
 
+U32 LLMutex::lockingThread() const
+{
+	return mLockingThread;
+}
+
 //============================================================================
 
 LLCondition::LLCondition(apr_pool_t *poolp) :
 
 void LLCondition::wait()
 {
+	if (!isLocked())
+	{ //mAPRMutexp MUST be locked before calling apr_thread_cond_wait
+		apr_thread_mutex_lock(mAPRMutexp);
+#if MUTEX_DEBUG
+		// avoid asserts on destruction in non-release builds
+		U32 id = LLThread::currentID();
+		mIsLocked[id] = TRUE;
+#endif
+	}
 	apr_thread_cond_wait(mAPRCondp, mAPRMutexp);
 }
 
 }
 
 //============================================================================
-LLMutexBase::LLMutexBase() :
-	mLockingThread(NO_THREAD),
-	mCount(0)
-{
-}
-
-void LLMutexBase::lock() 
-{ 
-#if LL_DARWIN
-	if (mLockingThread == LLThread::currentID())
-#else
-	if (mLockingThread == local_thread_ID)
-#endif
-	{ //redundant lock
-		mCount++;
-		return;
-	}
-
-	apr_thread_mutex_lock(mAPRMutexp); 
-
-#if LL_DARWIN
-	mLockingThread = LLThread::currentID();
-#else
-	mLockingThread = local_thread_ID;
-#endif
-}
-
-void LLMutexBase::unlock() 
-{ 
-	if (mCount > 0)
-	{ //not the root unlock
-		mCount--;
-		return;
-	}
-	mLockingThread = NO_THREAD;
-
-	apr_thread_mutex_unlock(mAPRMutexp); 
-}
 
 //----------------------------------------------------------------------------
 

indra/llcommon/llthread.h

 	apr_pool_t *getAPRPool() { return mAPRPoolp; }
 	LLVolatileAPRPool* getLocalAPRFilePool() { return mLocalAPRFilePoolp ; }
 
+	U32 getID() const { return mID; }
+
 private:
 	BOOL				mPaused;
 	
 	BOOL				mIsLocalPool;
 	EThreadStatus		mStatus;
 	U32					mID;
-	
+
 	//a local apr_pool for APRFile operations in this thread. If it exists, LLAPRFile::sAPRFilePoolp should not be used.
 	//Note: this pool is used by APRFile ONLY, do NOT use it for any other purposes.
 	//      otherwise it will cause severe memory leaking!!! --bao
 class LL_COMMON_API LLMutex
 {
 public:
+	typedef enum
+	{
+		NO_THREAD = 0xFFFFFFFF
+	} e_locking_thread;
+
 	LLMutex(apr_pool_t *apr_poolp); // NULL pool constructs a new pool for the mutex
 	virtual ~LLMutex();
 	
 	void lock();		// blocks
 	void unlock();
 	bool isLocked(); 	// non-blocking, but does do a lock/unlock so not free
+	U32 lockingThread() const; //get ID of locking thread
 	
 protected:
 	apr_thread_mutex_t *mAPRMutexp;
+	mutable U32			mCount;
+	mutable U32			mLockingThread;
+	
 	apr_pool_t			*mAPRPoolp;
 	BOOL				mIsLocalPool;
+	
 #if MUTEX_DEBUG
 	std::map<U32, BOOL> mIsLocked;
 #endif

indra/llimage/llimagedxt.cpp

 #include "linden_common.h"
 
 #include "llimagedxt.h"
+#include "llmemory.h"
 
 //static
 void LLImageDXT::checkMinWidthHeight(EFileFormat format, S32& width, S32& height)

indra/llimage/llimagej2c.cpp

 #include "llmemtype.h"
 #include "lltimer.h"
 #include "llmath.h"
+#include "llmemory.h"
 
 typedef LLImageJ2CImpl* (*CreateLLImageJ2CFunction)();
 typedef void (*DestroyLLImageJ2CFunction)(LLImageJ2CImpl*);

indra/llmessage/llcurl.cpp

 	mThreaded = LLCurl::sMultiThreaded && LLThread::currentID() == sMainThreadID;
 	if (mThreaded)
 	{
-		mSignal = new LLCondition();
+		mSignal = new LLCondition(NULL);
 	}
 	else
 	{
 
 	check_curl_code(code);
 	
-	Easy::sHandleMutex = new LLMutex();
-	Easy::sMultiMutex = new LLMutex();
+	Easy::sHandleMutex = new LLMutex(NULL);
+	Easy::sMultiMutex = new LLMutex(NULL);
 
 #if SAFE_SSL
 	S32 mutex_count = CRYPTO_num_locks();

indra/llmessage/lliosocket.h

 	apr_socket_t* getSocket() const { return mSocket; }
 
 	/** 
-	 * @brief Protected constructor since should only make sockets
-	 * with one of the two <code>create()</code> calls.
-	 */
-	LLSocket(apr_socket_t* socket, apr_pool_t* pool);
-
-	/** 
 	 * @brief Set default socket options, with SO_NONBLOCK = 0 and a timeout in us.
 	 * @param timeout Number of microseconds to wait on this socket. Any
 	 * negative number means block-forever. TIMEOUT OF 0 IS NON-PORTABLE.

indra/llmessage/llproxy.cpp

 
 LLProxy::LLProxy():
 		mHTTPProxyEnabled(false),
-		mProxyMutex(),
+		mProxyMutex(NULL),
 		mUDPProxy(),
 		mTCPProxy(),
 		mHTTPProxy(),
  */
 static LLSocket::ptr_t tcp_open_channel(LLHost host)
 {
-	LLSocket::ptr_t socket = LLSocket::create(LLSocket::STREAM_TCP);
+	LLSocket::ptr_t socket = LLSocket::create(NULL, LLSocket::STREAM_TCP);
 	bool connected = socket->blockingConnect(host);
 	if (!connected)
 	{

indra/newview/llfloatermodelpreview.cpp

 	mLastMouseX = 0;
 	mLastMouseY = 0;
 	mGLName = 0;
-	mStatusLock = new LLMutex();
+	mStatusLock = new LLMutex(NULL);
 	mModelPreview = NULL;
 
 	mLODMode[LLModel::LOD_HIGH] = 0;
 //-----------------------------------------------------------------------------
 
 LLModelPreview::LLModelPreview(S32 width, S32 height, LLFloater* fmp)
-: LLViewerDynamicTexture(width, height, 3, ORDER_MIDDLE, FALSE), LLMutex()
+: LLViewerDynamicTexture(width, height, 3, ORDER_MIDDLE, FALSE), LLMutex(NULL)
 , mPelvisZOffset( 0.0f )
 , mLegacyRigValid( false )
 , mRigValidJointUpload( false )

indra/newview/llmeshrepository.cpp

 : LLThread("mesh repo") 
 { 
 	mWaiting = false;
-	mMutex = new LLMutex();
-	mHeaderMutex = new LLMutex();
-	mSignal = new LLCondition();
+	mMutex = new LLMutex(NULL);
+	mHeaderMutex = new LLMutex(NULL);
+	mSignal = new LLCondition(NULL);
 }
 
 LLMeshRepoThread::~LLMeshRepoThread()
 	mUploadTextures = upload_textures;
 	mUploadSkin = upload_skin;
 	mUploadJoints = upload_joints;
-	mMutex = new LLMutex();
+	mMutex = new LLMutex(NULL);
 	mCurlRequest = NULL;
 	mPendingUploads = 0;
 	mFinished = false;
 
 void LLMeshRepository::init()
 {
-	mMeshMutex = new LLMutex();
+	mMeshMutex = new LLMutex(NULL);
 	
 	LLConvexDecomposition::getInstance()->initSystem();
 
 	mQuitting = false;
 	mDone = false;
 
-	mSignal = new LLCondition();
-	mMutex = new LLMutex();
+	mSignal = new LLCondition(NULL);
+	mMutex = new LLMutex(NULL);
 }
 
 LLPhysicsDecomp::~LLPhysicsDecomp()

indra/newview/lltexturecache.cpp

 
 // Included to allow LLTextureCache::purgeTextures() to pause watchdog timeout
 #include "llappviewer.h" 
+#include "llmemory.h"
 
 // Cache organization:
 // cache/texture.entries

indra/newview/llviewermenufile.cpp

 //static
 void LLFilePickerThread::initClass()
 {
-	sMutex = new LLMutex();
+	sMutex = new LLMutex(NULL);
 }
 
 //static