]> git.saurik.com Git - wxWidgets.git/blobdiff - src/gtk1/threadpsx.cpp
Added more '#pragma implementation' for gcc.
[wxWidgets.git] / src / gtk1 / threadpsx.cpp
index 79542d5e192882a87861188ff6b3dbfea461d838..99239908efc0c7c164e796b5abffa6d06ebb9bfa 100644 (file)
     #include <sched.h>
 #endif
 
+#ifdef __SUN__
+extern int usleep(unsigned int useconds);
+#endif
+
+
 #include "wx/thread.h"
 #include "wx/module.h"
 #include "wx/utils.h"
@@ -405,14 +410,17 @@ 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)
 {
-    // FIXME how to test for nanosleep() availability?
-
-    usleep(milliseconds * 1000); // usleep(3) wants microseconds
+    wxUsleep(milliseconds);
 }
 
 // -----------------------------------------------------------------------------
@@ -436,6 +444,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 )
     {
@@ -458,6 +467,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,
@@ -484,8 +494,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);
 
@@ -498,6 +509,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;
@@ -508,6 +520,7 @@ void wxThread::SetPriority(unsigned int prio)
                     wxLogError(_("Failed to set thread priority %d."), prio);
                 }
             }
+#endif // HAVE_THREAD_PRIORITY_FUNCTIONS
             break;
 
         case STATE_EXITED:
@@ -606,7 +619,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."));