Timestamp:
May 5, 2011, 5:36:53 AM (14 years ago)
Author:
Dmitry A. Kuminov
Message:

trunk: Merged in qt 4.7.2 sources from branches/vendor/nokia/qt.

Location:
trunk
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk

  • trunk/src/corelib/kernel/qeventdispatcher_symbian.cpp

    r769 r846  
    11/****************************************************************************
    22**
    3 ** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies).
     3** Copyright (C) 201 Nokia Corporation and/or its subsidiary(-ies).
    44** All rights reserved.
    55** Contact: Nokia Corporation ([email protected])
     
    4848#include <errno.h>
    4949
    50 #include <net/if.h>
    51 
    5250QT_BEGIN_NAMESPACE
    5351
     
    10199{
    102100public:
    103     QSelectMutexGrabber(int fd, QMutex *threadMutex, QMutex *selectCallMutex)
    104         : m_threadMutex(threadMutex), m_selectCallMutex(selectCallMutex), bHasThreadLock(false)
     101    QSelectMutexGrabber(int utex)
     102        : m_)
    105103    {
    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())
    110105            return;
    111         }
    112 
    113         // still check that SelectThread
    114         // is in select call
    115         if (m_selectCallMutex->tryLock()) {
    116             m_selectCallMutex->unlock();
    117             return;
    118         }
    119106
    120107        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) {}
    125114    }
    126115
    127116    ~QSelectMutexGrabber()
    128117    {
    129         if(bHasThreadLock)
    130             m_threadMutex->unlock();
     118        m_mutex->unlock();
    131119    }
    132120
    133121private:
    134     QMutex *m_threadMutex;
    135     QMutex *m_selectCallMutex;
    136     bool bHasThreadLock;
     122    QMutex *m_mutex;
    137123};
    138124
     
    142128 * this as a base class with convenience functions.
    143129 *
    144  * Here is how it works: On every RunL, the deriving class should call okToRun(). This will allow
    145  * exactly one run of the active object, and mark it as such. If it is called again, it will return
    146  * 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 * .
    147133 *
    148134 * The QCompleteDeferredAOs class is a special object that runs after all others, which will
     
    164150}
    165151
    166 bool QActiveObject::okToRun()
     152bool QActiveObject::()
    167153{
    168154    Q_ASSERT(!m_hasRunAgain);
     
    172158        m_hasAlreadyRun = true;
    173159        m_iterationCount = m_dispatcher->iterationCount();
    174         return true;
     160        return e;
    175161    } else {
    176162        // The event has already occurred.
    177163        m_dispatcher->addDeferredActiveObject(this);
    178164        m_hasRunAgain = true;
    179         return false;
     165        return e;
    180166    }
    181167}
     
    193179
    194180QWakeUpActiveObject::QWakeUpActiveObject(QEventDispatcherSymbian *dispatcher)
    195     : CActive(WAKE_UP_PRIORITY),
    196       m_dispatcher(dispatcher)
     181    : QActiveObject(WAKE_UP_PRIORITY, dispatcher)
    197182{
    198183    CActiveScheduler::Add(this);
     
    216201void QWakeUpActiveObject::RunL()
    217202{
     203
     204
     205
    218206    iStatus = KRequestPending;
    219207    SetActive();
     
    230218{
    231219    Cancel();
     220
    232221}
    233222
     
    236225    if (m_timerInfo->interval > 0) {
    237226        m_rTimer.Cancel();
    238         m_rTimer.Close();
    239227    } else {
    240228        if (iStatus.Int() == KRequestPending) {
     
    247235void QTimerActiveObject::RunL()
    248236{
    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    }
    251243    // All Symbian error codes are negative.
    252244    if (error < 0) {
     
    281273    }
    282274
    283     if (!okToRun())
     275    if (())
    284276        return;
    285277
     
    311303    m_timerInfo->msLeft = m_timerInfo->interval;
    312304    if (m_timerInfo->interval > 0) {
    313         m_rTimer.CreateLocal();
     305        if (!m_rTimer.Handle()) {
     306            qt_symbian_throwIfError(m_rTimer.CreateLocal());
     307        }
    314308        StartTimer();
    315309    } else {
     
    416410        int ret;
    417411        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);
    424413        savedSelectErrno = errno;
    425 
    426         char buffer;
    427 
    428         while (::read(m_pipeEnds[0], &buffer, 1) > 0) {}
    429414
    430415        if(ret == 0) {
     
    447432                // after loop update notifiers for all of them
    448433
    449                 // as we dont have "exception" notifier type
     434                // as we dont have "exception" notifier type
    450435                // we should force monitoring fd_set of this
    451436                // type as well
     
    502487        }
    503488
    504         m_waitCond.wait(&m_mutex);
     489        if (FD_ISSET(m_pipeEnds[0], &readfds))
     490            m_waitCond.wait(&m_mutex);
    505491    }
    506492
     
    516502    }
    517503
    518     QMutexLocker locker(&m_grabberMutex);
    519 
    520     QSelectMutexGrabber lock(m_pipeEnds[1], &m_mutex, &m_selectCallMutex);
     504    Q);
     505
     506    QSelectMutexGrabber lock(m_pipeEnds[1], utex);
    521507
    522508    Q_ASSERT(!m_AOStatuses.contains(notifier));
     
    529515void QSelectThread::cancelSocketEvents ( QSocketNotifier *notifier )
    530516{
    531     QMutexLocker locker(&m_grabberMutex);
    532 
    533     QSelectMutexGrabber lock(m_pipeEnds[1], &m_mutex, &m_selectCallMutex);
     517    Q);
     518
     519    QSelectMutexGrabber lock(m_pipeEnds[1], utex);
    534520
    535521    m_AOStatuses.remove(notifier);
     
    540526void QSelectThread::restart()
    541527{
    542     QMutexLocker locker(&m_grabberMutex);
    543 
    544     QSelectMutexGrabber lock(m_pipeEnds[1], &m_mutex, &m_selectCallMutex);
     528    Q);
     529
     530    QSelectMutexGrabber lock(m_pipeEnds[1], utex);
    545531
    546532    m_waitCond.wakeAll();
     
    598584             * then signal RequestComplete for it
    599585             */
    600             qWarning("exception on %d [will do setdefaultif(0) - hack]", i.key()->socket());
     586            qWarning("exception on %d [will - hack]", i.key()->socket());
    601587            // quick fix; there is a bug
    602588            // when doing read on socket
     
    604590            // after offline-ing the device
    605591            // 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());
    611593            toRemove.append(i.key());
    612594            TRequestStatus *status = i.value();
     
    653635void QSocketActiveObject::RunL()
    654636{
    655     if (!okToRun())
     637    if (())
    656638        return;
    657639
     
    738720QEventDispatcherSymbian::QEventDispatcherSymbian(QObject *parent)
    739721    : QAbstractEventDispatcher(parent),
     722
    740723      m_activeScheduler(0),
    741724      m_wakeUpAO(0),
     
    744727      m_wakeUpDone(0),
    745728      m_iterationCount(0),
     729
    746730      m_noSocketEvents(false)
    747731{
     
    769753}
    770754
     755
     756
     757
     758
     759
     760
    771761void QEventDispatcherSymbian::closingDown()
    772762{
    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;
    776768
    777769    delete m_completeDeferredAOs;
     
    786778    bool handledAnyEvent = false;
    787779    bool oldNoSocketEventsValue = m_noSocketEvents;
     780
     781
     782
    788783
    789784    QT_TRY {
     
    876871
    877872    m_noSocketEvents = oldNoSocketEventsValue;
     873
    878874
    879875    return handledAnyEvent;
     
    896892
    897893    timerInfo->inTimerEvent = true;
     894
     895
    898896
    899897    QTimerEvent event(timerInfo->timerId);
    900898    QCoreApplication::sendEvent(timerInfo->receiver, &event);
    901899
     900
    902901    timerInfo->inTimerEvent = false;
    903902
     
    979978inline void QEventDispatcherSymbian::addDeferredActiveObject(QActiveObject *object)
    980979{
    981     if (m_deferredActiveObjects.isEmpty()) {
    982         m_completeDeferredAOs->complete();
    983     }
     980    queueDeferredActiveObjectsCompletion();
    984981    m_deferredActiveObjects.append(object);
    985982}
     
    988985{
    989986    m_deferredActiveObjects.removeAll(object);
     987
     988
     989
     990
     991
    990992}
    991993
     
    10291031    QSocketActiveObject *socketAO = q_check_ptr(new QSocketActiveObject(this, notifier));
    10301032    m_notifiers.insert(notifier, socketAO);
    1031     m_selectThread.requestSocketEvents(notifier, &socketAO->iStatus);
     1033    .requestSocketEvents(notifier, &socketAO->iStatus);
    10321034}
    10331035
    10341036void QEventDispatcherSymbian::unregisterSocketNotifier ( QSocketNotifier * notifier )
    10351037{
    1036     m_selectThread.cancelSocketEvents(notifier);
     1038    if (m_selectThread)
     1039        m_selectThread->cancelSocketEvents(notifier);
    10371040    if (m_notifiers.contains(notifier)) {
    10381041        QSocketActiveObject *sockObj = *m_notifiers.find(notifier);
     
    10451048void QEventDispatcherSymbian::reactivateSocketNotifier(QSocketNotifier *notifier)
    10461049{
    1047     m_selectThread.requestSocketEvents(notifier, &m_notifiers[notifier]->iStatus);
     1050    .requestSocketEvents(notifier, &m_notifiers[notifier]->iStatus);
    10481051}
    10491052
     
    10651068
    10661069    timer->timerAO->Start();
     1070
     1071
     1072
     1073
     1074
     1075
     1076
     1077
    10671078}
    10681079
     
    11281139
    11291140QT_END_NAMESPACE
     1141
     1142
Note: See TracChangeset for help on using the changeset viewer.