// this is where _beginthreadex() is declared
#include <process.h>
- // the return type of the thread function entry point
- typedef wxUIntPtr THREAD_RETVAL;
+ // the return type of the thread function entry point: notice that this
+ // type can't hold a pointer under Win64
+ typedef unsigned THREAD_RETVAL;
// the calling convention of the thread function entry point
#define THREAD_CALLCONV __stdcall
// wxCriticalSection
// ----------------------------------------------------------------------------
-wxCriticalSection::wxCriticalSection()
+wxCriticalSection::wxCriticalSection( wxCriticalSectionType WXUNUSED(critSecType) )
{
wxCOMPILE_TIME_ASSERT( sizeof(CRITICAL_SECTION) <= sizeof(wxCritSectBuffer),
wxCriticalSectionBufferTooSmall );
wxMutexError LockTimeout(DWORD milliseconds);
HANDLE m_mutex;
+
+ unsigned long m_owningThread;
+ wxMutexType m_type;
DECLARE_NO_COPY_CLASS(wxMutexInternal)
};
// all mutexes are recursive under Win32 so we don't use mutexType
-wxMutexInternal::wxMutexInternal(wxMutexType WXUNUSED(mutexType))
+wxMutexInternal::wxMutexInternal(wxMutexType mutexType)
{
// create a nameless (hence intra process and always private) mutex
m_mutex = ::CreateMutex
NULL // no name
);
+ m_type = mutexType;
+ m_owningThread = 0;
+
if ( !m_mutex )
{
wxLogLastError(_T("CreateMutex()"));
}
+
}
wxMutexInternal::~wxMutexInternal()
wxMutexError wxMutexInternal::LockTimeout(DWORD milliseconds)
{
+ if (m_type == wxMUTEX_DEFAULT)
+ {
+ // Don't allow recursive
+ if (m_owningThread != 0)
+ {
+ if (m_owningThread == wxThread::GetCurrentId())
+ return wxMUTEX_DEAD_LOCK;
+ }
+ }
+
DWORD rc = ::WaitForSingleObject(m_mutex, milliseconds);
if ( rc == WAIT_ABANDONED )
{
return wxMUTEX_MISC_ERROR;
}
+ if (m_type == wxMUTEX_DEFAULT)
+ {
+ // required for checking recursiveness
+ m_owningThread = wxThread::GetCurrentId();
+ }
+
return wxMUTEX_NO_ERROR;
}
wxMutexError wxMutexInternal::Unlock()
{
+ // required for checking recursiveness
+ m_owningThread = 0;
+
if ( !::ReleaseMutex(m_mutex) )
{
wxLogLastError(_T("ReleaseMutex()"));
return THREAD_ERROR_EXIT;
}
- rc = (THREAD_RETVAL)thread->Entry();
+ rc = wxPtrToUInt(thread->Entry());
}
wxCATCH_ALL( wxTheApp->OnUnhandledException(); )
wxThread::ExitCode wxThread::Wait()
{
- ExitCode rc = (ExitCode)THREAD_ERROR_EXIT;
+ ExitCode rc = wxUIntToPtr(THREAD_ERROR_EXIT);
// although under Windows we can wait for any thread, it's an error to
// wait for a detached one in wxWin API