+ wxCriticalSectionLocker lock(m_critsect);
+
+ if ( p_internal->GetState() == STATE_PAUSED )
+ {
+ p_internal->Resume();
+
+ return wxTHREAD_NO_ERROR;
+ }
+ else
+ {
+ wxLogDebug("Attempt to resume a thread which is not paused.");
+
+ return wxTHREAD_MISC_ERROR;
+ }
+}
+
+// -----------------------------------------------------------------------------
+// exiting thread
+// -----------------------------------------------------------------------------
+
+wxThread::ExitCode wxThread::Delete()
+{
+ m_critsect.Enter();
+ thread_state state = p_internal->GetState();
+ m_critsect.Leave();
+
+ switch ( state )
+ {
+ case STATE_NEW:
+ case STATE_EXITED:
+ // nothing to do
+ break;
+
+ case STATE_PAUSED:
+ // resume the thread first
+ Resume();
+
+ // fall through
+
+ default:
+ // set the flag telling to the thread to stop and wait
+ p_internal->Cancel();
+ }
+
+ return NULL;
+}
+
+wxThreadError wxThread::Kill()
+{
+ switch ( p_internal->GetState() )
+ {
+ case STATE_NEW:
+ case STATE_EXITED:
+ return wxTHREAD_NOT_RUNNING;
+
+ default:
+#ifdef HAVE_PTHREAD_CANCEL
+ if ( pthread_cancel(p_internal->GetId()) != 0 )
+#endif
+ {
+ wxLogError(_("Failed to terminate a thread."));
+
+ return wxTHREAD_MISC_ERROR;
+ }
+
+ return wxTHREAD_NO_ERROR;
+ }
+}
+
+void wxThread::Exit(void *status)
+{
+ // first call user-level clean up code
+ OnExit();
+
+ // next wake up the threads waiting for us (OTOH, this function won't return
+ // until someone waited for us!)
+ p_internal->SignalExit();
+
+ p_internal->SetState(STATE_EXITED);
+
+ // delete both C++ thread object and terminate the OS thread object
+ delete this;
+ pthread_exit(status);
+}
+
+// also test whether we were paused
+bool wxThread::TestDestroy()
+{
+ wxCriticalSectionLocker lock((wxCriticalSection&)m_critsect);
+
+ if ( p_internal->GetState() == STATE_PAUSED )
+ {
+ // leave the crit section or the other threads will stop too if they try
+ // to call any of (seemingly harmless) IsXXX() functions while we sleep
+ m_critsect.Leave();
+
+ p_internal->Pause();
+
+ // enter it back before it's finally left in lock object dtor
+ m_critsect.Enter();
+ }
+
+ return p_internal->WasCancelled();