Changeset 846 for trunk/src/corelib/kernel/qeventdispatcher_symbian.cpp
- Timestamp:
- May 5, 2011, 5:36:53 AM (14 years ago)
- Location:
- trunk
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk
- Property svn:mergeinfo changed
/branches/vendor/nokia/qt/4.7.2 (added) merged: 845 /branches/vendor/nokia/qt/current merged: 844 /branches/vendor/nokia/qt/4.6.3 removed
- Property svn:mergeinfo changed
-
trunk/src/corelib/kernel/qeventdispatcher_symbian.cpp
r769 r846 1 1 /**************************************************************************** 2 2 ** 3 ** Copyright (C) 201 0Nokia Corporation and/or its subsidiary(-ies).3 ** Copyright (C) 201 Nokia Corporation and/or its subsidiary(-ies). 4 4 ** All rights reserved. 5 5 ** Contact: Nokia Corporation ([email protected]) … … 48 48 #include <errno.h> 49 49 50 #include <net/if.h>51 52 50 QT_BEGIN_NAMESPACE 53 51 … … 101 99 { 102 100 public: 103 QSelectMutexGrabber(int fd, QMutex *threadMutex, QMutex *selectCallMutex)104 : m_ threadMutex(threadMutex), m_selectCallMutex(selectCallMutex), bHasThreadLock(false)101 QSelectMutexGrabber(int utex) 102 : m_) 105 103 { 106 // see if selectThread is waiting m_waitCond 107 // if yes ... dont write to pipe 108 if (m_threadMutex->tryLock()) { 109 bHasThreadLock = true; 104 if (m_mutex->tryLock()) 110 105 return; 111 }112 113 // still check that SelectThread114 // is in select call115 if (m_selectCallMutex->tryLock()) {116 m_selectCallMutex->unlock();117 return;118 }119 106 120 107 char dummy = 0; 121 qt_pipe_write(fd, &dummy, 1); 122 123 m_threadMutex->lock(); 124 bHasThreadLock = true; 108 qt_pipe_write(writeFd, &dummy, 1); 109 110 m_mutex->lock(); 111 112 char buffer; 113 while (::read(readFd, &buffer, 1) > 0) {} 125 114 } 126 115 127 116 ~QSelectMutexGrabber() 128 117 { 129 if(bHasThreadLock) 130 m_threadMutex->unlock(); 118 m_mutex->unlock(); 131 119 } 132 120 133 121 private: 134 QMutex *m_threadMutex; 135 QMutex *m_selectCallMutex; 136 bool bHasThreadLock; 122 QMutex *m_mutex; 137 123 }; 138 124 … … 142 128 * this as a base class with convenience functions. 143 129 * 144 * Here is how it works: On every RunL, the deriving class should call okToRun(). This will allow145 * exactly one run of the active object, and mark it as such. If it is called again, it will return146 * false, and add the object to a queue so it can be run later.130 * Here is how it works: On every RunL, the deriving class should call 131 * 132 * . 147 133 * 148 134 * The QCompleteDeferredAOs class is a special object that runs after all others, which will … … 164 150 } 165 151 166 bool QActiveObject:: okToRun()152 bool QActiveObject::() 167 153 { 168 154 Q_ASSERT(!m_hasRunAgain); … … 172 158 m_hasAlreadyRun = true; 173 159 m_iterationCount = m_dispatcher->iterationCount(); 174 return true;160 return e; 175 161 } else { 176 162 // The event has already occurred. 177 163 m_dispatcher->addDeferredActiveObject(this); 178 164 m_hasRunAgain = true; 179 return false;165 return e; 180 166 } 181 167 } … … 193 179 194 180 QWakeUpActiveObject::QWakeUpActiveObject(QEventDispatcherSymbian *dispatcher) 195 : CActive(WAKE_UP_PRIORITY), 196 m_dispatcher(dispatcher) 181 : QActiveObject(WAKE_UP_PRIORITY, dispatcher) 197 182 { 198 183 CActiveScheduler::Add(this); … … 216 201 void QWakeUpActiveObject::RunL() 217 202 { 203 204 205 218 206 iStatus = KRequestPending; 219 207 SetActive(); … … 230 218 { 231 219 Cancel(); 220 232 221 } 233 222 … … 236 225 if (m_timerInfo->interval > 0) { 237 226 m_rTimer.Cancel(); 238 m_rTimer.Close();239 227 } else { 240 228 if (iStatus.Int() == KRequestPending) { … … 247 235 void QTimerActiveObject::RunL() 248 236 { 249 int error; 250 QT_TRYCATCH_ERROR(error, Run()); 237 int error = KErrNone; 238 if (iStatus == KErrNone) { 239 QT_TRYCATCH_ERROR(error, Run()); 240 } else { 241 error = iStatus.Int(); 242 } 251 243 // All Symbian error codes are negative. 252 244 if (error < 0) { … … 281 273 } 282 274 283 if ( !okToRun())275 if (()) 284 276 return; 285 277 … … 311 303 m_timerInfo->msLeft = m_timerInfo->interval; 312 304 if (m_timerInfo->interval > 0) { 313 m_rTimer.CreateLocal(); 305 if (!m_rTimer.Handle()) { 306 qt_symbian_throwIfError(m_rTimer.CreateLocal()); 307 } 314 308 StartTimer(); 315 309 } else { … … 416 410 int ret; 417 411 int savedSelectErrno; 418 { 419 // helps fighting the race condition between 420 // selctthread and new socket requests (cancel, restart ...) 421 QMutexLocker locker(&m_selectCallMutex); 422 ret = qt_socket_select(maxfd, &readfds, &writefds, &exceptionfds, 0); 423 } 412 ret = qt_socket_select(maxfd, &readfds, &writefds, &exceptionfds, 0); 424 413 savedSelectErrno = errno; 425 426 char buffer;427 428 while (::read(m_pipeEnds[0], &buffer, 1) > 0) {}429 414 430 415 if(ret == 0) { … … 447 432 // after loop update notifiers for all of them 448 433 449 // as we don t have "exception" notifier type434 // as we dont have "exception" notifier type 450 435 // we should force monitoring fd_set of this 451 436 // type as well … … 502 487 } 503 488 504 m_waitCond.wait(&m_mutex); 489 if (FD_ISSET(m_pipeEnds[0], &readfds)) 490 m_waitCond.wait(&m_mutex); 505 491 } 506 492 … … 516 502 } 517 503 518 Q MutexLocker locker(&m_grabberMutex);519 520 QSelectMutexGrabber lock(m_pipeEnds[1], &m_mutex, &m_selectCallMutex);504 Q); 505 506 QSelectMutexGrabber lock(m_pipeEnds[1], utex); 521 507 522 508 Q_ASSERT(!m_AOStatuses.contains(notifier)); … … 529 515 void QSelectThread::cancelSocketEvents ( QSocketNotifier *notifier ) 530 516 { 531 Q MutexLocker locker(&m_grabberMutex);532 533 QSelectMutexGrabber lock(m_pipeEnds[1], &m_mutex, &m_selectCallMutex);517 Q); 518 519 QSelectMutexGrabber lock(m_pipeEnds[1], utex); 534 520 535 521 m_AOStatuses.remove(notifier); … … 540 526 void QSelectThread::restart() 541 527 { 542 Q MutexLocker locker(&m_grabberMutex);543 544 QSelectMutexGrabber lock(m_pipeEnds[1], &m_mutex, &m_selectCallMutex);528 Q); 529 530 QSelectMutexGrabber lock(m_pipeEnds[1], utex); 545 531 546 532 m_waitCond.wakeAll(); … … 598 584 * then signal RequestComplete for it 599 585 */ 600 qWarning("exception on %d [will do setdefaultif(0)- hack]", i.key()->socket());586 qWarning("exception on %d [will - hack]", i.key()->socket()); 601 587 // quick fix; there is a bug 602 588 // when doing read on socket … … 604 590 // after offline-ing the device 605 591 // on some devices we do get exception 606 // close all exiting sockets 607 // and reset default IAP 608 if(::setdefaultif(0) != KErrNone) // well we can't do much about it 609 qWarning("setdefaultif(0) failed"); 610 592 ::close(i.key()->socket()); 611 593 toRemove.append(i.key()); 612 594 TRequestStatus *status = i.value(); … … 653 635 void QSocketActiveObject::RunL() 654 636 { 655 if ( !okToRun())637 if (()) 656 638 return; 657 639 … … 738 720 QEventDispatcherSymbian::QEventDispatcherSymbian(QObject *parent) 739 721 : QAbstractEventDispatcher(parent), 722 740 723 m_activeScheduler(0), 741 724 m_wakeUpAO(0), … … 744 727 m_wakeUpDone(0), 745 728 m_iterationCount(0), 729 746 730 m_noSocketEvents(false) 747 731 { … … 769 753 } 770 754 755 756 757 758 759 760 771 761 void QEventDispatcherSymbian::closingDown() 772 762 { 773 if (m_selectThread.isRunning()) { 774 m_selectThread.stop(); 775 } 763 if (m_selectThread && m_selectThread->isRunning()) { 764 m_selectThread->stop(); 765 } 766 delete m_selectThread; 767 m_selectThread = 0; 776 768 777 769 delete m_completeDeferredAOs; … … 786 778 bool handledAnyEvent = false; 787 779 bool oldNoSocketEventsValue = m_noSocketEvents; 780 781 782 788 783 789 784 QT_TRY { … … 876 871 877 872 m_noSocketEvents = oldNoSocketEventsValue; 873 878 874 879 875 return handledAnyEvent; … … 896 892 897 893 timerInfo->inTimerEvent = true; 894 895 898 896 899 897 QTimerEvent event(timerInfo->timerId); 900 898 QCoreApplication::sendEvent(timerInfo->receiver, &event); 901 899 900 902 901 timerInfo->inTimerEvent = false; 903 902 … … 979 978 inline void QEventDispatcherSymbian::addDeferredActiveObject(QActiveObject *object) 980 979 { 981 if (m_deferredActiveObjects.isEmpty()) { 982 m_completeDeferredAOs->complete(); 983 } 980 queueDeferredActiveObjectsCompletion(); 984 981 m_deferredActiveObjects.append(object); 985 982 } … … 988 985 { 989 986 m_deferredActiveObjects.removeAll(object); 987 988 989 990 991 990 992 } 991 993 … … 1029 1031 QSocketActiveObject *socketAO = q_check_ptr(new QSocketActiveObject(this, notifier)); 1030 1032 m_notifiers.insert(notifier, socketAO); 1031 m_selectThread.requestSocketEvents(notifier, &socketAO->iStatus);1033 .requestSocketEvents(notifier, &socketAO->iStatus); 1032 1034 } 1033 1035 1034 1036 void QEventDispatcherSymbian::unregisterSocketNotifier ( QSocketNotifier * notifier ) 1035 1037 { 1036 m_selectThread.cancelSocketEvents(notifier); 1038 if (m_selectThread) 1039 m_selectThread->cancelSocketEvents(notifier); 1037 1040 if (m_notifiers.contains(notifier)) { 1038 1041 QSocketActiveObject *sockObj = *m_notifiers.find(notifier); … … 1045 1048 void QEventDispatcherSymbian::reactivateSocketNotifier(QSocketNotifier *notifier) 1046 1049 { 1047 m_selectThread.requestSocketEvents(notifier, &m_notifiers[notifier]->iStatus);1050 .requestSocketEvents(notifier, &m_notifiers[notifier]->iStatus); 1048 1051 } 1049 1052 … … 1065 1068 1066 1069 timer->timerAO->Start(); 1070 1071 1072 1073 1074 1075 1076 1077 1067 1078 } 1068 1079 … … 1128 1139 1129 1140 QT_END_NAMESPACE 1141 1142
Note:
See TracChangeset
for help on using the changeset viewer.