X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/c25a510b30bd87f26deaf3532a48d29a158f0aea..737255678cb96a8296348fb62603afdd28133ec5:/src/msw/thread.cpp diff --git a/src/msw/thread.cpp b/src/msw/thread.cpp index 472d1916e3..ac600434e9 100644 --- a/src/msw/thread.cpp +++ b/src/msw/thread.cpp @@ -41,7 +41,19 @@ #define _MT #endif -#ifdef __VISUALC__ +#if defined(__VISUALC__) || (defined(__BORLANDC__) && (__BORLANDC__ >= 0x500)) + +#if defined(__BORLANDC__) && !defined(__MT__) +// I can't set -tWM in the IDE (anyone?) so have to do this +#define __MT__ +#endif + +#if defined(__BORLANDC__) && !defined(__MFC_COMPAT__) +// Needed to know about _beginthreadex etc.. +#define __MFC_COMPAT__ +#endif + + #include #endif @@ -99,33 +111,43 @@ static bool gs_waitingForThread = FALSE; class wxMutexInternal { public: - HANDLE p_mutex; + wxMutexInternal() + { + m_mutex = ::CreateMutex(NULL, FALSE, NULL); + if ( !m_mutex ) + { + wxLogSysError(_("Can not create mutex")); + } + } + + ~wxMutexInternal() { if ( m_mutex ) CloseHandle(m_mutex); } + +public: + HANDLE m_mutex; }; wxMutex::wxMutex() { m_internal = new wxMutexInternal; - m_internal->p_mutex = CreateMutex(NULL, FALSE, NULL); - if ( !m_internal->p_mutex ) - { - wxLogSysError(_("Can not create mutex.")); - } m_locked = 0; } wxMutex::~wxMutex() { - if (m_locked > 0) - wxLogDebug(wxT("Warning: freeing a locked mutex (%d locks)."), m_locked); - CloseHandle(m_internal->p_mutex); + if ( m_locked > 0 ) + { + wxLogDebug(_T("Warning: freeing a locked mutex (%d locks)."), m_locked); + } + + delete m_internal; } wxMutexError wxMutex::Lock() { DWORD ret; - ret = WaitForSingleObject(m_internal->p_mutex, INFINITE); + ret = WaitForSingleObject(m_internal->m_mutex, INFINITE); switch ( ret ) { case WAIT_ABANDONED: @@ -152,7 +174,7 @@ wxMutexError wxMutex::TryLock() { DWORD ret; - ret = WaitForSingleObject(m_internal->p_mutex, 0); + ret = WaitForSingleObject(m_internal->m_mutex, 0); if (ret == WAIT_TIMEOUT || ret == WAIT_ABANDONED) return wxMUTEX_BUSY; @@ -165,7 +187,7 @@ wxMutexError wxMutex::Unlock() if (m_locked > 0) m_locked--; - BOOL ret = ReleaseMutex(m_internal->p_mutex); + BOOL ret = ReleaseMutex(m_internal->m_mutex); if ( ret == 0 ) { wxLogSysError(_("Couldn't release a mutex")); @@ -432,7 +454,7 @@ bool wxThreadInternal::Create(wxThread *thread) // for compilers which have it, we should use C RTL function for thread // creation instead of Win32 API one because otherwise we will have memory // leaks if the thread uses C RTL (and most threads do) -#ifdef __VISUALC__ +#if defined(__VISUALC__) || (defined(__BORLANDC__) && (__BORLANDC__ >= 0x500)) typedef unsigned (__stdcall *RtlThreadStart)(void *); m_hThread = (HANDLE)_beginthreadex(NULL, 0, @@ -616,7 +638,12 @@ bool wxThread::SetConcurrency(size_t level) if ( hModKernel ) { pfnSetProcessAffinityMask = (SETPROCESSAFFINITYMASK) - ::GetProcAddress(hModKernel, _T("SetProcessAffinityMask")); + ::GetProcAddress(hModKernel, +#if defined(__BORLANDC__) && (__BORLANDC__ <= 0x520) + "SetProcessAffinityMask"); +#else + _T("SetProcessAffinityMask")); +#endif } // we've discovered a MT version of Win9x! @@ -897,7 +924,7 @@ void wxThread::Exit(ExitCode status) delete this; } -#ifdef __VISUALC__ +#if defined(__VISUALC__) || (defined(__BORLANDC__) && (__BORLANDC__ >= 0x500)) _endthreadex((unsigned)status); #else // !VC++ ::ExitThread((DWORD)status);