comparison gtk/dw.c @ 340:eff674cb4935

Test fix for Mark's dw_main_sleep() hang.
author bsmith@81767d24-ef19-dc11-ae90-00e081727c95
date Fri, 11 Apr 2003 09:25:30 +0000
parents 44e2bdacd8f3
children 599644ca9064
comparison
equal deleted inserted replaced
339:4482dd0bb87d 340:eff674cb4935
887 * milliseconds: Number of milliseconds to run the loop for. 887 * milliseconds: Number of milliseconds to run the loop for.
888 */ 888 */
889 void dw_main_sleep(int milliseconds) 889 void dw_main_sleep(int milliseconds)
890 { 890 {
891 struct timeval tv, start; 891 struct timeval tv, start;
892 pthread_t curr = pthread_self();
892 893
893 gettimeofday(&start, NULL); 894 gettimeofday(&start, NULL);
894 895
895 if(_dw_thread == (pthread_t)-1 || _dw_thread == pthread_self()) 896 if(_dw_thread == (pthread_t)-1 || _dw_thread == curr)
896 { 897 {
898 pthread_t orig = _dw_thread;
899
897 gettimeofday(&tv, NULL); 900 gettimeofday(&tv, NULL);
898 901
899 while(((tv.tv_sec - start.tv_sec)*1000) + ((tv.tv_usec - start.tv_usec)/1000) <= milliseconds) 902 while(((tv.tv_sec - start.tv_sec)*1000) + ((tv.tv_usec - start.tv_usec)/1000) <= milliseconds)
900 { 903 {
901 gdk_threads_enter(); 904 if(orig == (pthread_t)-1)
905 {
906 gdk_threads_enter();
907 _dw_thread = curr;
908 }
902 if(gtk_events_pending()) 909 if(gtk_events_pending())
903 gtk_main_iteration(); 910 gtk_main_iteration();
904 else 911 else
905 _dw_msleep(1); 912 _dw_msleep(1);
906 gdk_threads_leave(); 913 if(orig == (pthread_t)-1)
914 {
915 _dw_thread = orig;
916 gdk_threads_leave();
917 }
907 gettimeofday(&tv, NULL); 918 gettimeofday(&tv, NULL);
908 } 919 }
909 } 920 }
910 else 921 else
911 _dw_msleep(milliseconds); 922 _dw_msleep(milliseconds);