Changeset 665
- Timestamp:
- Mar 10, 2010, 1:33:14 AM (15 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/corelib/kernel/qeventdispatcher_pm.cpp
r664 r665 322 322 int refcnt; 323 323 QWaitCondition cond; 324 bool cancelWait;325 324 326 325 // socket stuff … … 331 330 332 331 fd_set readS, writeS, exS; 333 int maxSockfd ;332 int maxSockfd; 334 333 335 334 // timer stuff … … 699 698 700 699 QSelectThread::QSelectThread() 701 : finish(false), refcnt(0), cancelWait(false),allTimersPosted(false)700 : finish(false), refcnt(0), allTimersPosted(false) 702 701 { 703 702 // initialize socket stuff … … 705 704 FD_ZERO(&writeS); 706 705 FD_ZERO(&exS); 707 maxSockfd = -1;706 maxSockfd = -1; 708 707 709 708 // initialize timer stuff … … 786 785 if (maxSockfd >= 0) { 787 786 fd_set tmpRead = readS, tmpWrite = writeS, tmpEx = exS; 787 788 788 mutex.unlock(); 789 nsel = ::select(maxSockfd + 1, &tmpRead, &tmpWrite, &tmpEx, timeout);789 nsel = ::select(maxSockfd 790 790 if (nsel == -1 && errno == EINVAL) { 791 791 qWarning("QSocketNotifier: select() returned EINVAL, check that " 792 792 "the socket is not an OS/2 file handle."); 793 // give it some sleep to let other threads do something 794 DosSleep(100); 793 // give it some sleep to avoid 100% CPU load due to select() 794 // constantly failing in a tight loop which freezes the system 795 msleep(100); 795 796 } 796 797 mutex.lock(); … … 814 815 } 815 816 if (isSet) { 817 818 819 816 820 FD_CLR(sockfd, setForType(type)); 817 821 updateMaxSockFd(sockfd, Remove); … … 822 826 } else { 823 827 nsel = -1; 824 errno = EINTR; 825 if (!cancelWait) { 826 long msecs = timeout ? 827 timeout->tv_sec * 1000l + timeout->tv_usec / 1000l : LONG_MAX; 828 if (!cond.wait(&mutex, msecs)) 829 nsel = 0; // indicate timeout 830 } 831 cancelWait = false; 828 errno = EINTR; // indicate interrupt 829 long msecs = timeout ? 830 timeout->tv_sec * 1000l + timeout->tv_usec / 1000l : LONG_MAX; 831 maxSockfdInSelect = -1; 832 if (!cond.wait(&mutex, msecs)) 833 nsel = 0; // indicate timeout 832 834 } 833 835 … … 846 848 void QSelectThread::cancelSelectOrIdle() 847 849 { 848 if (maxSockfd >= 0) { 850 if (maxSockfdInSelect < 0) { 851 // terminate the idle or simple wait state 852 cond.wakeOne(); 853 } else { 849 854 // terminate select() execution 850 ::so_cancel(maxSockfd); 851 } else { 852 // terminate the idle or simple wait state 853 if (!cancelWait) { 854 cancelWait = true; 855 cond.wakeOne(); 856 } 855 ::so_cancel(maxSockfdInSelect); 857 856 } 858 857 }
Note:
See TracChangeset
for help on using the changeset viewer.