+ wxFAIL_MSG(wxT("wxThread::Exit() can't return."));
+
+ return NULL;
+ }
+}
+
+#ifdef wxHAVE_PTHREAD_CLEANUP
+
+// this handler is called when the thread is cancelled
+extern "C" void wxPthreadCleanup(void *ptr)
+{
+ wxThreadInternal::Cleanup((wxThread *)ptr);
+}
+
+void wxThreadInternal::Cleanup(wxThread *thread)
+{
+ if (pthread_getspecific(gs_keySelf) == 0) return;
+ {
+ wxCriticalSectionLocker lock(thread->m_critsect);
+ if ( thread->m_internal->GetState() == STATE_EXITED )
+ {
+ // thread is already considered as finished.
+ return;
+ }
+ }
+
+ // exit the thread gracefully
+ thread->Exit(EXITCODE_CANCELLED);
+}
+
+#endif // wxHAVE_PTHREAD_CLEANUP
+
+// ----------------------------------------------------------------------------
+// wxThreadInternal
+// ----------------------------------------------------------------------------
+
+wxThreadInternal::wxThreadInternal()
+{
+ m_state = STATE_NEW;
+ m_created = false;
+ m_cancelled = false;
+ m_prio = wxPRIORITY_DEFAULT;
+ m_threadId = 0;
+ m_exitcode = 0;
+
+ // set to true only when the thread starts waiting on m_semSuspend
+ m_isPaused = false;
+
+ // defaults for joinable threads
+ m_shouldBeJoined = true;
+ m_isDetached = false;
+}
+
+wxThreadInternal::~wxThreadInternal()
+{
+}
+
+#ifdef HAVE_PTHREAD_ATTR_SETSTACKSIZE
+ #define WXUNUSED_STACKSIZE(identifier) identifier
+#else
+ #define WXUNUSED_STACKSIZE(identifier) WXUNUSED(identifier)
+#endif
+
+wxThreadError wxThreadInternal::Create(wxThread *thread,
+ unsigned int WXUNUSED_STACKSIZE(stackSize))
+{
+ if ( GetState() != STATE_NEW )
+ {
+ // don't recreate thread
+ return wxTHREAD_RUNNING;
+ }