|
From: <axl...@us...> - 2009-05-13 02:26:04
|
Revision: 238
http://hgengine.svn.sourceforge.net/hgengine/?rev=238&view=rev
Author: axlecrusher
Date: 2009-05-13 02:25:55 +0000 (Wed, 13 May 2009)
Log Message:
-----------
Fix Thread related bugs.
Works on windows now.
Modified Paths:
--------------
Mercury2/src/MScopedArray.h
Mercury2/src/MSemaphore.cpp
Mercury2/src/MercuryThreads.cpp
Mercury2/src/MercuryThreads.h
Modified: Mercury2/src/MScopedArray.h
===================================================================
--- Mercury2/src/MScopedArray.h 2009-05-13 00:46:57 UTC (rev 237)
+++ Mercury2/src/MScopedArray.h 2009-05-13 02:25:55 UTC (rev 238)
@@ -16,7 +16,7 @@
{
m_criticalSection.Wait();
IncrementReference();
- m_criticalSection.Open();
+ m_criticalSection.UnLock();
}
MScopedArray()
@@ -30,14 +30,14 @@
m_ptr = autoPtr.m_ptr;
m_count = autoPtr.m_count;
IncrementReference();
- m_criticalSection.Open();
+ m_criticalSection.UnLock();
}
inline ~MScopedArray()
{
m_criticalSection.Wait();
DecrementReference();
- m_criticalSection.Open();
+ m_criticalSection.UnLock();
}
inline unsigned int Count()
@@ -45,7 +45,7 @@
unsigned int count = 0;
m_criticalSection.Wait();
if( m_ptr && m_count ) count = *m_count;
- m_criticalSection.Open();
+ m_criticalSection.UnLock();
return count;
}
@@ -54,7 +54,7 @@
m_criticalSection.Wait();
DecrementReference();
m_ptr = NULL;
- m_criticalSection.Open();
+ m_criticalSection.UnLock();
}
/*
void Forget()
@@ -64,7 +64,7 @@
if (m_ptr->m_count)
if ((m_ptr->m_count) > 0) { --m_ptr->m_count; }
m_ptr = NULL;
- m_criticalSection.Open();
+ m_criticalSection.UnLock();
}
*/
//Comparative
@@ -89,7 +89,7 @@
DecrementReference();
m_ptr = rhs.m_ptr;
IncrementReference();
- m_criticalSection.Open();
+ m_criticalSection.UnLock();
return *this;
}
Modified: Mercury2/src/MSemaphore.cpp
===================================================================
--- Mercury2/src/MSemaphore.cpp 2009-05-13 00:46:57 UTC (rev 237)
+++ Mercury2/src/MSemaphore.cpp 2009-05-13 02:25:55 UTC (rev 238)
@@ -33,10 +33,9 @@
#else
-//These functions seem to be missing from x86 WinBase
FORCEINLINE
LONG
-MyInterlockedOr (
+OrAndFetch (
__inout LONG volatile *Destination,
__in LONG Value
)
@@ -49,9 +48,10 @@
Old | Value,
Old) != Old);
- return Old;
+ return Old | Value;
}
+//Function seem to be missing from x86 WinBase
FORCEINLINE
LONG
MyInterlockedAnd (
@@ -72,7 +72,8 @@
unsigned long MSemaphore::Read()
{
- return MyInterlockedOr(&m_counter, 0);
+ return OrAndFetch(&m_counter, 0);
+// return MyInterlockedOr(&m_counter, 0);
}
unsigned long MSemaphore::ReadAndClear()
Modified: Mercury2/src/MercuryThreads.cpp
===================================================================
--- Mercury2/src/MercuryThreads.cpp 2009-05-13 00:46:57 UTC (rev 237)
+++ Mercury2/src/MercuryThreads.cpp 2009-05-13 02:25:55 UTC (rev 238)
@@ -7,7 +7,7 @@
#include <stdio.h>
MercuryThread::MercuryThread()
- :m_name("(null)"), m_haltOnDestroy(true), m_thread(0)
+ :m_haltOnDestroy(true), m_thread(0)
{
#if defined( WIN32 )
mkThreadData = NULL;
@@ -186,7 +186,10 @@
p->nLength = sizeof( SECURITY_ATTRIBUTES );
p->bInheritHandle = true;
p->lpSecurityDescriptor = NULL;
- m_mutex = CreateMutex( p, true, (LPCWSTR)m_name.c_str() );
+ if ( m_name.empty() )
+ m_mutex = CreateMutex( p, true, NULL );
+ else
+ m_mutex = CreateMutex( p, true, (LPCWSTR)m_name.c_str() );
free( p );
return (int)m_mutex;
#else
Modified: Mercury2/src/MercuryThreads.h
===================================================================
--- Mercury2/src/MercuryThreads.h 2009-05-13 00:46:57 UTC (rev 237)
+++ Mercury2/src/MercuryThreads.h 2009-05-13 02:25:55 UTC (rev 238)
@@ -75,12 +75,14 @@
///Unlock a mutex for the next thing waiting in line.
int UnLock( );
+private:
+
///Start up a mutex. You need to do this as well as UnLock() afterwards when in a constructor.
int Open( );
-
+
///Clean up a mutex. This is done automatically on destruction of mutex.
int Close( );
-private:
+
MString m_name;
int iLockCount;
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|