+ p_internal = new wxThreadInternal();
+}
+
+wxThreadError wxThread::Create()
+{
+ if (p_internal->GetState() != STATE_NEW)
+ return wxTHREAD_RUNNING;
+
+ // set up the thread attribute: right now, we only set thread priority
+ pthread_attr_t attr;
+ pthread_attr_init(&attr);
+
+#ifdef HAVE_THREAD_PRIORITY_FUNCTIONS
+ int prio;
+ if ( pthread_attr_getschedpolicy(&attr, &prio) != 0 )
+ {
+ wxLogError(_("Can not retrieve thread scheduling policy."));
+ }
+
+ int min_prio = sched_get_priority_min(prio),
+ max_prio = sched_get_priority_max(prio);
+
+ if ( min_prio == -1 || max_prio == -1 )
+ {
+ wxLogError(_("Can not get priority range for scheduling policy %d."),
+ prio);
+ }
+ else
+ {
+ struct sched_param sp;
+ pthread_attr_getschedparam(&attr, &sp);
+ sp.sched_priority = min_prio +
+ (p_internal->GetPriority()*(max_prio-min_prio))/100;
+ pthread_attr_setschedparam(&attr, &sp);
+ }
+#endif // HAVE_THREAD_PRIORITY_FUNCTIONS
+
+ // create the new OS thread object
+ int rc = pthread_create(&p_internal->thread_id, &attr,
+ wxThreadInternal::PthreadStart, (void *)this);
+ pthread_attr_destroy(&attr);
+
+ if ( rc != 0 )
+ {
+ p_internal->SetState(STATE_EXITED);
+ return wxTHREAD_NO_RESOURCE;
+ }
+
+ return wxTHREAD_NO_ERROR;
+}
+
+wxThreadError wxThread::Run()
+{
+ return p_internal->Run();
+}
+
+// -----------------------------------------------------------------------------
+// misc accessors
+// -----------------------------------------------------------------------------
+
+void wxThread::SetPriority(unsigned int prio)
+{
+ wxCHECK_RET( ((int)WXTHREAD_MIN_PRIORITY <= (int)prio) &&
+ ((int)prio <= (int)WXTHREAD_MAX_PRIORITY),
+ "invalid thread priority" );
+
+ wxCriticalSectionLocker lock(m_critsect);
+
+ switch ( p_internal->GetState() )
+ {
+ case STATE_NEW:
+ // thread not yet started, priority will be set when it is
+ p_internal->SetPriority(prio);
+ break;
+
+ case STATE_RUNNING:
+ case STATE_PAUSED:
+#ifdef HAVE_THREAD_PRIORITY_FUNCTIONS
+ {
+ struct sched_param sparam;
+ sparam.sched_priority = prio;
+
+ if ( pthread_setschedparam(p_internal->GetId(),
+ SCHED_OTHER, &sparam) != 0 )
+ {
+ wxLogError(_("Failed to set thread priority %d."), prio);
+ }
+ }
+#endif // HAVE_THREAD_PRIORITY_FUNCTIONS
+ break;
+
+ case STATE_EXITED:
+ default:
+ wxFAIL_MSG("impossible to set thread priority in this state");
+ }
+}
+
+unsigned int wxThread::GetPriority() const
+{
+ wxCriticalSectionLocker lock((wxCriticalSection &)m_critsect);
+
+ return p_internal->GetPriority();