From 68401dfe2c39c7251174cb1bc4509ac66b9644be Mon Sep 17 00:00:00 2001 From: Vadim Zeitlin Date: Fri, 5 Mar 1999 16:24:07 +0000 Subject: [PATCH] (more) FreeBSD thread fixes git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@1865 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775 --- include/wx/thread.h | 4 ++-- src/gtk/threadpsx.cpp | 16 ++++++++++++++-- src/gtk1/threadpsx.cpp | 16 ++++++++++++++-- 3 files changed, 30 insertions(+), 6 deletions(-) diff --git a/include/wx/thread.h b/include/wx/thread.h index 1acb78279f..491bf986de 100644 --- a/include/wx/thread.h +++ b/include/wx/thread.h @@ -151,9 +151,9 @@ public: WXCRITICAL_INLINE ~wxCriticalSection(); // enter the section (the same as locking a mutex) - void WXCRITICAL_INLINE Enter(); + WXCRITICAL_INLINE void Enter(); // leave the critical section (same as unlocking a mutex) - void WXCRITICAL_INLINE Leave(); + WXCRITICAL_INLINE void Leave(); private: // no assignment operator nor copy ctor diff --git a/src/gtk/threadpsx.cpp b/src/gtk/threadpsx.cpp index a5732e3aee..faf1421929 100644 --- a/src/gtk/threadpsx.cpp +++ b/src/gtk/threadpsx.cpp @@ -405,7 +405,12 @@ bool wxThread::IsMain() void wxThread::Yield() { +#ifdef HAVE_SCHED_YIELD sched_yield(); +#else // !HAVE_SCHED_YIELD + // may be it will have the desired effect? + Sleep(0); +#endif // HAVE_SCHED_YIELD } void wxThread::Sleep(unsigned long milliseconds) @@ -434,6 +439,7 @@ wxThreadError wxThread::Create() pthread_attr_t attr; pthread_attr_init(&attr); +#ifdef HAVE_THREAD_PRIORITY_FUNCTIONS int prio; if ( pthread_attr_getschedpolicy(&attr, &prio) != 0 ) { @@ -456,6 +462,7 @@ wxThreadError wxThread::Create() (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, @@ -482,8 +489,9 @@ wxThreadError wxThread::Run() void wxThread::SetPriority(unsigned int prio) { - wxCHECK_RET( (WXTHREAD_MIN_PRIORITY <= prio) && - (prio <= WXTHREAD_MAX_PRIORITY), "invalid thread priority" ); + wxCHECK_RET( ((int)WXTHREAD_MIN_PRIORITY <= (int)prio) && + ((int)prio <= (int)WXTHREAD_MAX_PRIORITY), + "invalid thread priority" ); wxCriticalSectionLocker lock(m_critsect); @@ -496,6 +504,7 @@ void wxThread::SetPriority(unsigned int prio) case STATE_RUNNING: case STATE_PAUSED: +#ifdef HAVE_THREAD_PRIORITY_FUNCTIONS { struct sched_param sparam; sparam.sched_priority = prio; @@ -506,6 +515,7 @@ void wxThread::SetPriority(unsigned int prio) wxLogError(_("Failed to set thread priority %d."), prio); } } +#endif // HAVE_THREAD_PRIORITY_FUNCTIONS break; case STATE_EXITED: @@ -604,7 +614,9 @@ wxThreadError wxThread::Kill() return wxTHREAD_NOT_RUNNING; default: +#ifdef HAVE_PTHREAD_CANCEL if ( pthread_cancel(p_internal->GetId()) != 0 ) +#endif { wxLogError(_("Failed to terminate a thread.")); diff --git a/src/gtk1/threadpsx.cpp b/src/gtk1/threadpsx.cpp index a5732e3aee..faf1421929 100644 --- a/src/gtk1/threadpsx.cpp +++ b/src/gtk1/threadpsx.cpp @@ -405,7 +405,12 @@ bool wxThread::IsMain() void wxThread::Yield() { +#ifdef HAVE_SCHED_YIELD sched_yield(); +#else // !HAVE_SCHED_YIELD + // may be it will have the desired effect? + Sleep(0); +#endif // HAVE_SCHED_YIELD } void wxThread::Sleep(unsigned long milliseconds) @@ -434,6 +439,7 @@ wxThreadError wxThread::Create() pthread_attr_t attr; pthread_attr_init(&attr); +#ifdef HAVE_THREAD_PRIORITY_FUNCTIONS int prio; if ( pthread_attr_getschedpolicy(&attr, &prio) != 0 ) { @@ -456,6 +462,7 @@ wxThreadError wxThread::Create() (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, @@ -482,8 +489,9 @@ wxThreadError wxThread::Run() void wxThread::SetPriority(unsigned int prio) { - wxCHECK_RET( (WXTHREAD_MIN_PRIORITY <= prio) && - (prio <= WXTHREAD_MAX_PRIORITY), "invalid thread priority" ); + wxCHECK_RET( ((int)WXTHREAD_MIN_PRIORITY <= (int)prio) && + ((int)prio <= (int)WXTHREAD_MAX_PRIORITY), + "invalid thread priority" ); wxCriticalSectionLocker lock(m_critsect); @@ -496,6 +504,7 @@ void wxThread::SetPriority(unsigned int prio) case STATE_RUNNING: case STATE_PAUSED: +#ifdef HAVE_THREAD_PRIORITY_FUNCTIONS { struct sched_param sparam; sparam.sched_priority = prio; @@ -506,6 +515,7 @@ void wxThread::SetPriority(unsigned int prio) wxLogError(_("Failed to set thread priority %d."), prio); } } +#endif // HAVE_THREAD_PRIORITY_FUNCTIONS break; case STATE_EXITED: @@ -604,7 +614,9 @@ wxThreadError wxThread::Kill() return wxTHREAD_NOT_RUNNING; default: +#ifdef HAVE_PTHREAD_CANCEL if ( pthread_cancel(p_internal->GetId()) != 0 ) +#endif { wxLogError(_("Failed to terminate a thread.")); -- 2.45.2