Fixed several bugs in threading code for OS/2. Thread sample now working.
git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@23307 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
@@ -732,7 +732,7 @@ public:
|
|||||||
|
|
||||||
#if wxUSE_THREADS
|
#if wxUSE_THREADS
|
||||||
|
|
||||||
#if defined(__WXMSW__) || defined(__WXMAC__) || defined(__WXPM__)
|
#if defined(__WXMSW__) || defined(__WXMAC__) || defined(__WXPM__) || defined(__EMX__)
|
||||||
// unlock GUI if there are threads waiting for and lock it back when
|
// unlock GUI if there are threads waiting for and lock it back when
|
||||||
// there are no more of them - should be called periodically by the main
|
// there are no more of them - should be called periodically by the main
|
||||||
// thread
|
// thread
|
||||||
|
@@ -377,7 +377,7 @@ public:
|
|||||||
TID GetId() const { return m_hThread; }
|
TID GetId() const { return m_hThread; }
|
||||||
|
|
||||||
// thread function
|
// thread function
|
||||||
static DWORD OS2ThreadStart(ULONG ulParam);
|
static void OS2ThreadStart(void* pParam);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
// Threads in OS/2 have only an ID, so m_hThread is both it's handle and ID
|
// Threads in OS/2 have only an ID, so m_hThread is both it's handle and ID
|
||||||
@@ -388,16 +388,20 @@ private:
|
|||||||
unsigned int m_nPriority; // thread priority in "wx" units
|
unsigned int m_nPriority; // thread priority in "wx" units
|
||||||
};
|
};
|
||||||
|
|
||||||
ULONG wxThreadInternal::OS2ThreadStart(
|
void wxThreadInternal::OS2ThreadStart(
|
||||||
ULONG ulParam
|
void * pParam
|
||||||
)
|
)
|
||||||
{
|
{
|
||||||
DWORD dwRet;
|
DWORD dwRet;
|
||||||
bool bWasCancelled;
|
bool bWasCancelled;
|
||||||
|
|
||||||
// first of all, check whether we hadn't been cancelled already and don't
|
wxThread *pThread = (wxThread *)pParam;
|
||||||
// start the user code at all then
|
|
||||||
wxThread *pThread = (wxThread *)ulParam;
|
// first of all, wait for the thread to be started.
|
||||||
|
pThread->m_critsect.Enter();
|
||||||
|
pThread->m_critsect.Leave();
|
||||||
|
// Now check whether we hadn't been cancelled already and don't
|
||||||
|
// start the user code at all in this case.
|
||||||
if ( pThread->m_internal->GetState() == STATE_EXITED )
|
if ( pThread->m_internal->GetState() == STATE_EXITED )
|
||||||
{
|
{
|
||||||
dwRet = (DWORD)-1;
|
dwRet = (DWORD)-1;
|
||||||
@@ -425,7 +429,7 @@ ULONG wxThreadInternal::OS2ThreadStart(
|
|||||||
delete pThread;
|
delete pThread;
|
||||||
}
|
}
|
||||||
//else: the joinable threads handle will be closed when Wait() is done
|
//else: the joinable threads handle will be closed when Wait() is done
|
||||||
return dwRet;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
void wxThreadInternal::SetPriority(
|
void wxThreadInternal::SetPriority(
|
||||||
@@ -468,20 +472,20 @@ bool wxThreadInternal::Create(
|
|||||||
, unsigned int uStackSize
|
, unsigned int uStackSize
|
||||||
)
|
)
|
||||||
{
|
{
|
||||||
APIRET ulrc;
|
int tid;
|
||||||
|
|
||||||
ulrc = ::DosCreateThread( &m_hThread
|
if (!uStackSize)
|
||||||
,(PFNTHREAD)wxThreadInternal::OS2ThreadStart
|
uStackSize = 131072;
|
||||||
,(ULONG)pThread
|
pThread->m_critsect.Enter();
|
||||||
,CREATE_SUSPENDED | STACK_SPARSE
|
tid = _beginthread(wxThreadInternal::OS2ThreadStart,
|
||||||
,(ULONG)uStackSize
|
NULL, uStackSize, pThread);
|
||||||
);
|
if(tid == -1)
|
||||||
if(ulrc != 0)
|
|
||||||
{
|
{
|
||||||
wxLogSysError(_("Can't create thread"));
|
wxLogSysError(_("Can't create thread"));
|
||||||
|
|
||||||
return FALSE;
|
return FALSE;
|
||||||
}
|
}
|
||||||
|
m_hThread = tid;
|
||||||
if (m_nPriority != WXTHREAD_DEFAULT_PRIORITY)
|
if (m_nPriority != WXTHREAD_DEFAULT_PRIORITY)
|
||||||
{
|
{
|
||||||
SetPriority(m_nPriority);
|
SetPriority(m_nPriority);
|
||||||
@@ -509,7 +513,7 @@ bool wxThreadInternal::Resume()
|
|||||||
|
|
||||||
if (ulrc != 0)
|
if (ulrc != 0)
|
||||||
{
|
{
|
||||||
wxLogSysError(_("Can not suspend thread %lu"), m_hThread);
|
wxLogSysError(_("Can not resume thread %lu"), m_hThread);
|
||||||
return FALSE;
|
return FALSE;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -527,8 +531,6 @@ bool wxThreadInternal::Resume()
|
|||||||
// static functions
|
// static functions
|
||||||
// ----------------
|
// ----------------
|
||||||
|
|
||||||
bool WXDLLEXPORT wxGuiOwnedByMainThread();
|
|
||||||
|
|
||||||
wxThread *wxThread::This()
|
wxThread *wxThread::This()
|
||||||
{
|
{
|
||||||
wxThread* pThread = m_pThread;
|
wxThread* pThread = m_pThread;
|
||||||
@@ -651,6 +653,13 @@ wxThreadError wxThread::Pause()
|
|||||||
|
|
||||||
wxThreadError wxThread::Resume()
|
wxThreadError wxThread::Resume()
|
||||||
{
|
{
|
||||||
|
if (m_internal->GetState() == STATE_NEW)
|
||||||
|
{
|
||||||
|
m_internal->SetState(STATE_RUNNING);
|
||||||
|
m_critsect.Leave();
|
||||||
|
return wxTHREAD_NO_ERROR;
|
||||||
|
}
|
||||||
|
|
||||||
wxCriticalSectionLocker lock((wxCriticalSection &)m_critsect);
|
wxCriticalSectionLocker lock((wxCriticalSection &)m_critsect);
|
||||||
|
|
||||||
return m_internal->Resume() ? wxTHREAD_NO_ERROR : wxTHREAD_MISC_ERROR;
|
return m_internal->Resume() ? wxTHREAD_NO_ERROR : wxTHREAD_MISC_ERROR;
|
||||||
@@ -745,25 +754,42 @@ wxThreadError wxThread::Delete(ExitCode *pRc)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
result = ::DosWaitThread(&hThread, DCWW_WAIT);
|
result = ::DosWaitThread(&hThread, DCWW_NOWAIT);
|
||||||
// FIXME: We ought to have a message processing loop here!!
|
// FIXME: We ought to have a message processing loop here!!
|
||||||
|
|
||||||
switch ( result )
|
switch ( result )
|
||||||
{
|
{
|
||||||
|
case ERROR_INTERRUPT:
|
||||||
case ERROR_THREAD_NOT_TERMINATED:
|
case ERROR_THREAD_NOT_TERMINATED:
|
||||||
|
break;
|
||||||
case ERROR_INVALID_THREADID:
|
case ERROR_INVALID_THREADID:
|
||||||
// error
|
|
||||||
wxLogSysError(_("Can not wait for thread termination"));
|
|
||||||
Kill();
|
|
||||||
return wxTHREAD_KILLED;
|
|
||||||
|
|
||||||
case NO_ERROR:
|
case NO_ERROR:
|
||||||
// thread we're waiting for terminated
|
// thread we're waiting for just terminated
|
||||||
break;
|
// or even does not exist any more.
|
||||||
|
result = NO_ERROR;
|
||||||
|
break;
|
||||||
default:
|
default:
|
||||||
wxFAIL_MSG(wxT("unexpected result of DosWaitThread"));
|
wxFAIL_MSG(wxT("unexpected result of DosWaitThread"));
|
||||||
}
|
}
|
||||||
|
if ( IsMain() )
|
||||||
|
{
|
||||||
|
// event processing - needed if we are the main thread
|
||||||
|
// to give other threads a chance to do remaining GUI
|
||||||
|
// processing and terminate cleanly.
|
||||||
|
wxTheApp->HandleSockets();
|
||||||
|
if (wxTheApp->Pending())
|
||||||
|
if ( !wxTheApp->DoMessage() )
|
||||||
|
{
|
||||||
|
// WM_QUIT received: kill the thread
|
||||||
|
Kill();
|
||||||
|
|
||||||
|
return wxTHREAD_KILLED;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
wxUsleep(10);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
wxUsleep(10);
|
||||||
} while ( result != NO_ERROR );
|
} while ( result != NO_ERROR );
|
||||||
#else // !wxUSE_GUI
|
#else // !wxUSE_GUI
|
||||||
// simply wait for the thread to terminate
|
// simply wait for the thread to terminate
|
||||||
@@ -830,7 +856,7 @@ void wxThread::Exit(
|
|||||||
)
|
)
|
||||||
{
|
{
|
||||||
delete this;
|
delete this;
|
||||||
::DosExit(EXIT_THREAD, ULONG(pStatus));
|
_endthread();
|
||||||
wxFAIL_MSG(wxT("Couldn't return from DosExit()!"));
|
wxFAIL_MSG(wxT("Couldn't return from DosExit()!"));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user