X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/882eefb1f78d3608b667b2f0d7b3d55944a6f2d1..9d2f3c71d83c52fc4db6c8041de533562816b1d6:/src/unix/threadpsx.cpp diff --git a/src/unix/threadpsx.cpp b/src/unix/threadpsx.cpp index bb105415ce..475d0b72b8 100644 --- a/src/unix/threadpsx.cpp +++ b/src/unix/threadpsx.cpp @@ -24,12 +24,13 @@ #pragma implementation "thread.h" #endif -#include "wx/thread.h" +// With simple makefiles, we must ignore the file body if not using +// threads. +#include "wx/setup.h" -#if !wxUSE_THREADS - #error This file needs wxUSE_THREADS -#endif +#if wxUSE_THREADS +#include "wx/thread.h" #include "wx/module.h" #include "wx/utils.h" #include "wx/log.h" @@ -42,7 +43,7 @@ #include #include -#ifdef HAVE_SCHED_H +#if HAVE_SCHED_H #include #endif @@ -286,7 +287,7 @@ void *wxThreadInternal::PthreadStart(void *ptr) int rc = pthread_setspecific(gs_keySelf, thread); if ( rc != 0 ) { - wxLogSysError(rc, _("Can not start thread: error writing TLS.")); + wxLogSysError(rc, _("Cannot start thread: error writing TLS")); return (void *)-1; } @@ -452,7 +453,9 @@ wxThread::wxThread() wxThreadError wxThread::Create() { - if (p_internal->GetState() != STATE_NEW) + // Maybe we could think about recreate the thread once it has exited. + if (p_internal->GetState() != STATE_NEW && + p_internal->GetState() != STATE_EXITED) return wxTHREAD_RUNNING; // set up the thread attribute: right now, we only set thread priority @@ -463,7 +466,7 @@ wxThreadError wxThread::Create() int prio; if ( pthread_attr_getschedpolicy(&attr, &prio) != 0 ) { - wxLogError(_("Can not retrieve thread scheduling policy.")); + wxLogError(_("Cannot retrieve thread scheduling policy.")); } int min_prio = sched_get_priority_min(prio), @@ -471,7 +474,7 @@ wxThreadError wxThread::Create() if ( min_prio == -1 || max_prio == -1 ) { - wxLogError(_("Can not get priority range for scheduling policy %d."), + wxLogError(_("Cannot get priority range for scheduling policy %d."), prio); } else @@ -484,6 +487,11 @@ wxThreadError wxThread::Create() } #endif // HAVE_THREAD_PRIORITY_FUNCTIONS +#ifdef HAVE_PTHREAD_ATTR_SETSCOPE + // this will make the threads created by this process really concurrent + pthread_attr_setscope(&attr, PTHREAD_SCOPE_SYSTEM); +#endif // HAVE_PTHREAD_ATTR_SETSCOPE + // create the new OS thread object int rc = pthread_create(p_internal->GetIdPtr(), &attr, wxThreadInternal::PthreadStart, (void *)this); @@ -662,7 +670,8 @@ void wxThread::Exit(void *status) p_internal->SetState(STATE_EXITED); // delete both C++ thread object and terminate the OS thread object - delete this; + // GL: This is very ugly and buggy ... +// delete this; pthread_exit(status); } @@ -736,10 +745,11 @@ IMPLEMENT_DYNAMIC_CLASS(wxThreadModule, wxModule) bool wxThreadModule::OnInit() { - if ( pthread_key_create(&gs_keySelf, NULL /* dtor function */) != 0 ) + int rc = pthread_key_create(&gs_keySelf, NULL /* dtor function */); + if ( rc != 0 ) { - wxLogError(_("Thread module initialization failed: " - "failed to create pthread key.")); + wxLogSysError(rc, _("Thread module initialization failed: " + "failed to create thread key")); return FALSE; } @@ -793,3 +803,5 @@ void wxMutexGuiLeave() gs_mutexGui->Unlock(); } +#endif + // wxUSE_THREADS