// Licence: wxWindows licence
/////////////////////////////////////////////////////////////////////////////
-#ifdef __GNUG__
+#if defined(__GNUG__) && !defined(NO_GCC_PRAGMA)
#pragma implementation "thread.h"
#endif
(defined(__GNUG__) && defined(__MSVCRT__)) || \
defined(__WATCOMC__) || defined(__MWERKS__)
+#ifndef __WXWINCE__
#undef wxUSE_BEGIN_THREAD
#define wxUSE_BEGIN_THREAD
#endif
+#endif
+
#ifdef wxUSE_BEGIN_THREAD
// this is where _beginthreadex() is declared
#include <process.h>
wxSemaphoreInternal::wxSemaphoreInternal(int initialcount, int maxcount)
{
+#ifndef __WXWINCE__
if ( maxcount == 0 )
{
// make it practically infinite
maxcount,
NULL // no name
);
-
+#endif
if ( !m_semaphore )
{
wxLogLastError(_T("CreateSemaphore()"));
wxSemaError wxSemaphoreInternal::Post()
{
+#ifndef __WXWINCE__
if ( !::ReleaseSemaphore(m_semaphore, 1, NULL /* ptr to previous count */) )
+#endif
{
wxLogLastError(_T("ReleaseSemaphore"));
wxMutex& m_mutex;
wxSemaphore m_semaphore;
+
+ DECLARE_NO_COPY_CLASS(wxConditionInternal)
};
wxConditionInternal::wxConditionInternal(wxMutex& mutex)
if ( shouldResume )
Resume();
- // does is still run?
+ // is it still running?
if ( isRunning || m_state == STATE_RUNNING )
{
if ( wxThread::IsMain() )
break;
case WAIT_OBJECT_0 + 1:
- // new message arrived, process it
+ // new message arrived, process it -- but only if we're the
+ // main thread as we don't support processing messages in
+ // the other ones
+ //
+ // NB: we still must include QS_ALLINPUT even when waiting
+ // in a secondary thread because if it had created some
+ // window somehow (possible not even using wxWindows)
+ // the system might dead lock then
+ if ( wxThread::IsMain() )
{
// it looks that sometimes WAIT_OBJECT_0 + 1 is
// returned but there are no messages in the thread
if ( pRc )
*pRc = rc;
+ // we don't need the thread handle any more
+ Free();
+
+ wxCriticalSectionLocker lock(cs);
+ SetState(STATE_EXITED);
+
return rc == (wxThread::ExitCode)-1 ? wxTHREAD_MISC_ERROR
: wxTHREAD_NO_ERROR;
}
return ::GetCurrentThreadId() == gs_idMainThread;
}
-#ifdef Yield
-#undef Yield
-#endif
-
void wxThread::Yield()
{
// 0 argument to Sleep() is special and means to just give away the rest of
bool wxThread::SetConcurrency(size_t level)
{
+#ifndef __WXWINCE__
wxASSERT_MSG( IsMain(), _T("should only be called from the main thread") );
// ok only for the default one
return FALSE;
}
-
+#endif
return TRUE;
}
(void)m_internal->WaitForTerminate(false, m_critsect, &rc);
- m_internal->Free();
-
- wxCriticalSectionLocker lock(m_critsect);
- m_internal->SetState(STATE_EXITED);
-
return rc;
}
wxThreadError wxThread::Delete(ExitCode *pRc)
{
- wxThreadError rc = m_internal->WaitForTerminate(true, m_critsect, pRc);
-
- if ( IsDetached() )
- {
- delete this;
- }
- else // joinable
- {
- // update the status of the joinable thread
- wxCriticalSectionLocker lock(m_critsect);
- m_internal->SetState(STATE_EXITED);
- }
-
- return rc;
+ return m_internal->WaitForTerminate(true, m_critsect, pRc);
}
wxThreadError wxThread::Kill()