Changeset 69 for trunk/src


Ignore:
Timestamp:
Jul 4, 2009, 2:31:20 PM (16 years ago)
Author:
Dmitry A. Kuminov
Message:

corelib: OS/2: Ported QThread (#13).

Location:
trunk/src/corelib/thread
Files:
3 edited
1 copied

Legend:

Unmodified
Added
Removed
  • trunk/src/corelib/thread/qthread.cpp

    r2 r69  
    154154    terminationEnabled = true;
    155155    terminatePending = false;
     156
     157
     158
     159
    156160#endif
    157161
     
    550554    Initializes the QThread system.
    551555*/
    552 #if defined (Q_OS_WIN)
     556#if defined)
    553557void qt_create_tls();
    554558#endif
     
    560564    qt_global_mutexpool = QMutexPool::instance();
    561565
    562 #if defined (Q_OS_WIN)
     566#if defined)
    563567    qt_create_tls();
    564568#endif
  • trunk/src/corelib/thread/qthread_os2.cpp

    r63 r69  
    33** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
    44** Contact: Qt Software Information ([email protected])
     5
     6
    57**
    68** This file is part of the QtCore module of the Qt Toolkit.
     
    4042****************************************************************************/
    4143
    42 //#define WINVER 0x0500
    43 #define _WIN32_WINNT 0x0400
    44 
    45 
    4644#include "qthread.h"
    4745#include "qthread_p.h"
     
    5351
    5452#include <private/qcoreapplication_p.h>
    55 #include <private/qeventdispatcher_win_p.h>
    56 
    57 #include <windows.h>
    58 
    59 
    60 #ifndef Q_OS_WINCE
    61 #ifndef _MT
    62 #define _MT
    63 #endif
    64 #include <process.h>
    65 #else
    66 #include "qfunctions_wince.h"
    67 #endif
     53#include <private/qeventdispatcher_pm_p.h>
     54
     55#include <qt_os2.h>
    6856
    6957#ifndef QT_NO_THREAD
     58
    7059QT_BEGIN_NAMESPACE
    7160
    72 void qt_watch_adopted_thread(const HANDLE adoptedThreadHandle, QThread *qthread);
    73 void qt_adopted_thread_watcher_function(void *);
    74 
    75 static DWORD qt_current_thread_data_tls_index = TLS_OUT_OF_INDEXES;
    76 void qt_create_tls()
    77 {
    78     if (qt_current_thread_data_tls_index != TLS_OUT_OF_INDEXES)
     61static void qt_watch_adopted_thread(const TID adoptedTID, QThread *qthread);
     62static void qt_adopted_thread_watcher_function(void *);
     63
     64static QThreadData **qt_tls = NULL;
     65
     66static void qt_create_tls()
     67{
     68    if (qt_tls != NULL)
    7969        return;
    8070    static QMutex mutex;
    8171    QMutexLocker locker(&mutex);
    82     qt_current_thread_data_tls_index = TlsAlloc();
     72    APIRET rc = DosAllocThreadLocalMemory((sizeof(QThreadData *) + 3)/4,
     73                                          (PULONG *)&qt_tls);
     74    if (rc != NO_ERROR)
     75        qWarning("qt_create_tls: DosAllocThreadLocalMemory returned %lu", rc);
    8376}
    8477
    8578static void qt_free_tls()
    8679{
    87     if (qt_current_thread_data_tls_index != TLS_OUT_OF_INDEXES) {
    88         TlsFree(qt_current_thread_data_tls_index);
    89         qt_current_thread_data_tls_index = TLS_OUT_OF_INDEXES;
    90     }
    91 }
    92 Q_DESTRUCTOR_FUNCTION(qt_free_tls)
     80    if (qt_tls != NULL) {
     81        DosFreeThreadLocalMemory((PULONG)qt_tls);
     82        qt_tls = NULL;
     83    }
     84}
     85
     86static Q_DESTRUCTOR_FUNCTION(qt_free_tls)
    9387
    9488/*
     
    9892{
    9993    qt_create_tls();
    100     QThreadData *threadData = reinterpret_cast<QThreadData *>(TlsGetValue(qt_current_thread_data_tls_index));
     94    QThreadData *threadData = ;
    10195    if (!threadData) {
    10296        QThread *adopted = 0;
     
    10498            Q_ASSERT(adopted);
    10599            threadData = QThreadData::get2(adopted);
    106             TlsSetValue(qt_current_thread_data_tls_index, threadData);
     100            ;
    107101            adopted->d_func()->running = true;
    108102            adopted->d_func()->finished = false;
     
    112106            // This needs to be called prior to new AdoptedThread() to
    113107            // avoid recursion.
    114             TlsSetValue(qt_current_thread_data_tls_index, threadData);
     108            ;
    115109            threadData->thread = new QAdoptedThread(threadData);
    116110            threadData->deref();
     
    120114            QCoreApplicationPrivate::theMainThread = threadData->thread;
    121115        } else {
    122             HANDLE realHandle = INVALID_HANDLE_VALUE;
    123 #if !defined(Q_OS_WINCE) || (defined(_WIN32_WCE) && (_WIN32_WCE>=0x600))
    124             DuplicateHandle(GetCurrentProcess(),
    125                     GetCurrentThread(),
    126                     GetCurrentProcess(),
    127                     &realHandle,
    128                     0,
    129                     FALSE,
    130                     DUPLICATE_SAME_ACCESS);
    131 #else
    132                         realHandle = (HANDLE)GetCurrentThreadId();
    133 #endif
    134             qt_watch_adopted_thread(realHandle, threadData->thread);
     116            PTIB ptib;
     117            DosGetInfoBlocks(&ptib, NULL);
     118            qt_watch_adopted_thread(ptib->tib_ptib2->tib2_ultid, threadData->thread);
    135119        }
    136120    }
     
    140124void QAdoptedThread::init()
    141125{
    142     d_func()->handle = GetCurrentThread();
    143     d_func()->id = GetCurrentThreadId();
    144 }
    145 
    146 static QVector<HANDLE> qt_adopted_thread_handles;
     126    PTIB ptib;
     127    DosGetInfoBlocks(&ptib, NULL);
     128    d_func()->tid = ptib->tib_ptib2->tib2_ultid;
     129}
     130
     131static QVector<TID> qt_adopted_thread_tids;
    147132static QVector<QThread *> qt_adopted_qthreads;
    148133static QMutex qt_adopted_thread_watcher_mutex;
    149 static HANDLE qt_adopted_thread_watcher_handle = 0;
    150 static HANDLE qt_adopted_thread_wakeup = 0;
     134static = 0;
     135static H;
    151136
    152137/*! \internal
     
    155140    thread if necessary.
    156141*/
    157 void qt_watch_adopted_thread(const HANDLE adoptedThreadHandle, QThread *qthread)
     142, QThread *qthread)
    158143{
    159144    QMutexLocker lock(&qt_adopted_thread_watcher_mutex);
    160     qt_adopted_thread_handles.append(adoptedThreadHandle);
     145    qt_adopted_thread_);
    161146    qt_adopted_qthreads.append(qthread);
    162147
    163148    // Start watcher thread if it is not already running.
    164     if (qt_adopted_thread_watcher_handle == 0) {
    165         if (qt_adopted_thread_wakeup == 0) {
    166             qt_adopted_thread_wakeup = QT_WA_INLINE(CreateEventW(0, false, false, 0),
    167                                                     CreateEventA(0, false, false, 0));
    168             qt_adopted_thread_handles.prepend(qt_adopted_thread_wakeup);
     149    if (qt_adopted_thread_watcher_tid == 0) {
     150        APIRET rc = DosCreateEventSem(NULL, &qt_adopted_thread_wakeup,
     151                                      DCE_AUTORESET, FALSE);
     152        if (rc != NO_ERROR) {
     153            qWarning("qt_watch_adopted_thread: DosCreateEventSem returned %lu", rc);
     154            return;
    169155        }
    170156
    171         qt_adopted_thread_watcher_handle =
    172             (HANDLE)_beginthread(qt_adopted_thread_watcher_function, 0, NULL);
     157        int tid =
     158            (TID)_beginthread(qt_adopted_thread_watcher_function, NULL, 0, NULL);
     159        if (tid == -1)
     160            qErrnoWarning(errno, "qt_watch_adopted_thread: _beginthread failed");
     161        else
     162            qt_adopted_thread_watcher_tid = (TID) tid;
    173163    } else {
    174         SetEvent(qt_adopted_thread_wakeup);
     164        (qt_adopted_thread_wakeup);
    175165    }
    176166}
     
    181171    to make sure it gets cleaned up properly.
    182172*/
    183 void qt_adopted_thread_watcher_function(void *)
     173void qt_adopted_thread_watcher_function(void *)
    184174{
    185175    forever {
    186176        qt_adopted_thread_watcher_mutex.lock();
    187177
    188         if (qt_adopted_thread_handles.count() == 1) {
    189             qt_adopted_thread_watcher_handle = 0;
     178        if (qt_adopted_thread_tids.isEmpty()) {
     179            // our service is no longer necessary
     180            qt_adopted_thread_watcher_tid = 0;
     181            DosCloseEventSem(qt_adopted_thread_wakeup);
     182            qt_adopted_thread_wakeup = NULLHANDLE;
    190183            qt_adopted_thread_watcher_mutex.unlock();
    191184            break;
    192185        }
    193186
    194         QVector<HANDLE> handlesCopy = qt_adopted_thread_handles;
     187        APIRET rc;
     188        TID tid;
     189
     190        for (int i = 0; i < qt_adopted_thread_tids.size();) {
     191            tid = qt_adopted_thread_tids.at(i);
     192            rc = DosWaitThread(&tid, DCWW_NOWAIT);
     193            if (rc != ERROR_THREAD_NOT_TERMINATED) {
     194                if (rc == NO_ERROR || rc == ERROR_INVALID_THREADID) {
     195                    QThreadData::get2(qt_adopted_qthreads.at(i))->deref();
     196                    QMutexLocker lock(&qt_adopted_thread_watcher_mutex);
     197                    qt_adopted_thread_tids.remove(i);
     198                    qt_adopted_qthreads.remove(i);
     199                    continue;
     200                }
     201                qWarning("qt_adopted_thread_watcher_function: DosWaitThread returned %lu", rc);
     202            }
     203            ++i;
     204        }
     205
    195206        qt_adopted_thread_watcher_mutex.unlock();
    196207
    197         DWORD ret = WAIT_TIMEOUT;
    198         int loops = (handlesCopy.count() / MAXIMUM_WAIT_OBJECTS) + 1, offset, count;
    199         if (loops == 1) {
    200             // no need to loop, no timeout
    201             offset = 0;
    202             count = handlesCopy.count();
    203             ret = WaitForMultipleObjects(handlesCopy.count(), handlesCopy.constData(), false, INFINITE);
    204         } else {
    205             int loop = 0;
    206             do {
    207                 offset = loop * MAXIMUM_WAIT_OBJECTS;
    208                 count = qMin(handlesCopy.count() - offset, MAXIMUM_WAIT_OBJECTS);
    209                 ret = WaitForMultipleObjects(count, handlesCopy.constData() + offset, false, 100);
    210                 loop = (loop + 1) % loops;
    211             } while (ret == WAIT_TIMEOUT);
     208        rc = DosWaitEventSem(qt_adopted_thread_wakeup, 300);
     209        if (rc != NO_ERROR && rc != ERROR_TIMEOUT) {
     210            qWarning("qt_adopted_thread_watcher_function: DosWaitEventSem returned %lu", rc);
    212211        }
    213 
    214         if (ret == WAIT_FAILED || !(ret >= WAIT_OBJECT_0 && ret < WAIT_OBJECT_0 + uint(count))) {
    215             qWarning("QThread internal error while waiting for adopted threads: %d", int(GetLastError()));
    216             continue;
    217         }
    218 
    219         const int handleIndex = offset + ret - WAIT_OBJECT_0;
    220         if (handleIndex == 0){
    221             // New handle to watch was added.
    222             continue;
    223         } else {
    224 //             printf("(qt) - qt_adopted_thread_watcher_function... called\n");
    225             const int qthreadIndex = handleIndex - 1;
    226             QThreadData::get2(qt_adopted_qthreads.at(qthreadIndex))->deref();
    227 #if !defined(Q_OS_WINCE) || (defined(_WIN32_WCE) && (_WIN32_WCE>=0x600))
    228             CloseHandle(qt_adopted_thread_handles.at(handleIndex));
    229 #endif
    230             QMutexLocker lock(&qt_adopted_thread_watcher_mutex);
    231             qt_adopted_thread_handles.remove(handleIndex);
    232             qt_adopted_qthreads.remove(qthreadIndex);
    233         }
    234     }
    235 }
    236 
    237 #if !defined(QT_NO_DEBUG) && defined(Q_CC_MSVC) && !defined(Q_OS_WINCE)
    238 
    239 #ifndef Q_OS_WIN64
    240 #  define ULONG_PTR DWORD
    241 #endif
    242 
    243 typedef struct tagTHREADNAME_INFO
    244 {
    245     DWORD dwType;      // must be 0x1000
    246     LPCSTR szName;     // pointer to name (in user addr space)
    247     HANDLE dwThreadID; // thread ID (-1=caller thread)
    248     DWORD dwFlags;     // reserved for future use, must be zero
    249 } THREADNAME_INFO;
    250 
    251 void qt_set_thread_name(HANDLE threadId, LPCSTR threadName)
    252 {
    253     THREADNAME_INFO info;
    254     info.dwType = 0x1000;
    255     info.szName = threadName;
    256     info.dwThreadID = threadId;
    257     info.dwFlags = 0;
    258 
    259     __try
    260     {
    261         RaiseException(0x406D1388, 0, sizeof(info)/sizeof(DWORD), (const ULONG_PTR*)&info);
    262     }
    263     __except (EXCEPTION_CONTINUE_EXECUTION)
    264     {
    265     }
    266 }
    267 #endif // !QT_NO_DEBUG && Q_CC_MSVC && !Q_OS_WINCE
     212    }
     213}
    268214
    269215/**************************************************************************
     
    275221void QThreadPrivate::createEventDispatcher(QThreadData *data)
    276222{
    277     data->eventDispatcher = new QEventDispatcherWin32;
     223    data->eventDispatcher = new QEventDispatcher;
    278224    data->eventDispatcher->startingUp();
    279225}
     
    281227#ifndef QT_NO_THREAD
    282228
    283 unsigned int __stdcall QThreadPrivate::start(void *arg)
     229// static
     230void QThreadPrivate::start(void *arg)
    284231{
    285232    QThread *thr = reinterpret_cast<QThread *>(arg);
     
    287234
    288235    qt_create_tls();
    289     TlsSetValue(qt_current_thread_data_tls_index, data);
     236    ;
    290237
    291238    QThread::setTerminationEnabled(false);
     
    296243        createEventDispatcher(data);
    297244
    298 #if !defined(QT_NO_DEBUG) && defined(Q_CC_MSVC) && !defined(Q_OS_WINCE)
    299     // sets the name of the current thread.
    300     QByteArray objectName = thr->objectName().toLocal8Bit();
    301     qt_set_thread_name((HANDLE)-1,
    302                        objectName.isEmpty() ?
    303                        thr->metaObject()->className() : objectName.constData());
    304 #endif
    305 
    306245    emit thr->started();
    307246    QThread::setTerminationEnabled(true);
     
    309248
    310249    finish(arg);
    311     return 0;
    312 }
    313 
     250}
     251
     252// static
    314253void QThreadPrivate::finish(void *arg, bool lockAnyway)
    315254{
     
    336275    QThreadStorageData::finish(reinterpret_cast<void **>(&d->data->tls));
    337276
    338     if (!d->waiters) {
    339         CloseHandle(d->handle);
    340         d->handle = 0;
    341     }
    342 
    343     d->id = 0;
     277    d->tid = 0;
    344278
    345279    if (lockAnyway)
     
    353287Qt::HANDLE QThread::currentThreadId()
    354288{
    355     return (Qt::HANDLE)GetCurrentThreadId();
     289    PTIB ptib;
     290    DosGetInfoBlocks(&ptib, NULL);
     291    return (Qt::HANDLE)ptib->tib_ptib2->tib2_ultid;
    356292}
    357293
    358294int QThread::idealThreadCount()
    359295{
    360     SYSTEM_INFO sysinfo;
    361     GetSystemInfo(&sysinfo);
    362     return sysinfo.dwNumberOfProcessors;
     296    ULONG cpuCnt = 1;
     297    APIRET rc = DosQuerySysInfo(QSV_NUMPROCESSORS, QSV_NUMPROCESSORS,
     298                                &cpuCnt, sizeof(cpuCnt));
     299    if (rc != NO_ERROR || cpuCnt == 0)
     300        cpuCnt = 1;
     301    return (int) cpuCnt;
    363302}
    364303
    365304void QThread::yieldCurrentThread()
    366305{
    367 #ifndef Q_OS_WINCE
    368     if (QSysInfo::WindowsVersion & QSysInfo::WV_NT_based)
    369         SwitchToThread();
    370     else
    371 #endif
    372         ::Sleep(0);
     306    DosSleep(0);
    373307}
    374308
    375309void QThread::sleep(unsigned long secs)
    376310{
    377     ::Sleep(secs * 1000);
     311    Sleep(secs * 1000);
    378312}
    379313
    380314void QThread::msleep(unsigned long msecs)
    381315{
    382     ::Sleep(msecs);
     316    Sleep(msecs);
    383317}
    384318
    385319void QThread::usleep(unsigned long usecs)
    386320{
    387     ::Sleep((usecs / 1000) + 1);
    388 }
    389 
     321    DosSleep((usecs / 1000) + 1);
     322}
    390323
    391324void QThread::start(Priority priority)
     
    401334    d->terminated = false;
    402335
    403     /*
    404       NOTE: we create the thread in the suspended state, set the
    405       priority and then resume the thread.
    406 
    407       since threads are created with normal priority by default, we
    408       could get into a case where a thread (with priority less than
    409       NormalPriority) tries to create a new thread (also with priority
    410       less than NormalPriority), but the newly created thread preempts
    411       its 'parent' and runs at normal priority.
    412     */
    413     d->handle = (Qt::HANDLE) _beginthreadex(NULL, d->stackSize, QThreadPrivate::start,
    414                                             this, CREATE_SUSPENDED, &(d->id));
    415 
    416     if (!d->handle) {
     336    int tid = _beginthread(QThreadPrivate::start, NULL, d->stackSize, this);
     337    d->tid = tid != -1 ? (TID) tid : 0;
     338
     339    if (tid == -1) {
    417340        qErrnoWarning(errno, "QThread::start: Failed to create thread");
    418341        d->running = false;
     
    421344    }
    422345
    423     // Since Win 9x will have problems if the priority is idle or time critical
    424     // we have to use the closest one instead
    425     int prio;
    426     d->priority = priority;
    427     switch (d->priority) {
    428     case IdlePriority:
    429         if (QSysInfo::WindowsVersion & QSysInfo::WV_DOS_based) {
    430             prio = THREAD_PRIORITY_LOWEST;
    431         } else {
    432             prio = THREAD_PRIORITY_IDLE;
    433         }
    434         break;
    435 
    436     case LowestPriority:
    437         prio = THREAD_PRIORITY_LOWEST;
    438         break;
    439 
    440     case LowPriority:
    441         prio = THREAD_PRIORITY_BELOW_NORMAL;
    442         break;
    443 
    444     case NormalPriority:
    445         prio = THREAD_PRIORITY_NORMAL;
    446         break;
    447 
    448     case HighPriority:
    449         prio = THREAD_PRIORITY_ABOVE_NORMAL;
    450         break;
    451 
    452     case HighestPriority:
    453         prio = THREAD_PRIORITY_HIGHEST;
    454         break;
    455 
    456     case TimeCriticalPriority:
    457         if (QSysInfo::WindowsVersion & QSysInfo::WV_DOS_based) {
    458             prio = THREAD_PRIORITY_HIGHEST;
    459         } else {
    460             prio = THREAD_PRIORITY_TIME_CRITICAL;
    461         }
    462         break;
    463 
    464     case InheritPriority:
    465     default:
    466         prio = GetThreadPriority(GetCurrentThread());
    467         break;
    468     }
    469 
    470     if (!SetThreadPriority(d->handle, prio)) {
    471         qErrnoWarning("QThread::start: Failed to set thread priority");
    472     }
    473 
    474     if (ResumeThread(d->handle) == (DWORD) -1) {
    475         qErrnoWarning("QThread::start: Failed to resume new thread");
    476     }
     346    setPriority(priority);
    477347}
    478348
     
    481351    Q_D(QThread);
    482352    QMutexLocker locker(&d->mutex);
     353
     354
     355
     356
    483357    if (!d->running)
    484358        return;
     
    487361        return;
    488362    }
    489     TerminateThread(d->handle, 0);
     363    );
    490364    d->terminated = true;
    491365    QThreadPrivate::finish(this, false);
     
    497371    QMutexLocker locker(&d->mutex);
    498372
    499     if (d->id == GetCurrentThreadId()) {
     373    if (d->urrentThreadId()) {
    500374        qWarning("QThread::wait: Thread tried to wait on itself");
    501375        return false;
     
    504378        return true;
    505379
    506     ++d->waiters;
    507380    locker.mutex()->unlock();
    508381
    509     bool ret = false;
    510     switch (WaitForSingleObject(d->handle, time)) {
    511     case WAIT_OBJECT_0:
    512         ret = true;
    513         break;
    514     case WAIT_FAILED:
    515         qErrnoWarning("QThread::wait: Thread wait failure");
    516         break;
    517     case WAIT_ABANDONED:
    518     case WAIT_TIMEOUT:
    519     default:
    520         break;
     382    bool ret = true;
     383    TID tid = d->tid;
     384    APIRET rc = NO_ERROR;
     385    if (time == ULONG_MAX) {
     386        rc = DosWaitThread(&tid, DCWW_WAIT);
     387    } else {
     388        ULONG sleep;
     389        do {
     390            // OS/2 doesn't support specifying a maximum time to wait for a
     391            // thread to end other than infininty, so we run a loop of small
     392            // wait intervals (in ms)
     393            enum { THREAD_WAIT_INTERVAL = 1000 };
     394            sleep = time > THREAD_WAIT_INTERVAL ? THREAD_WAIT_INTERVAL : time;
     395            DosSleep(sleep);
     396            rc = DosWaitThread(&tid, DCWW_NOWAIT);
     397            if (rc != ERROR_THREAD_NOT_TERMINATED)
     398                break;
     399            if (d->finished || !d->running) {
     400                rc = 0;
     401                break;
     402            }
     403            time -= sleep;
     404        } while (time);
     405    }
     406    if (rc != NO_ERROR && rc != ERROR_INVALID_THREADID) {
     407        if (rc != ERROR_THREAD_NOT_TERMINATED)
     408            qWarning("QThread::wait: DosWaitThread returned %lu", rc);
     409        ret = false;
    521410    }
    522411
    523412    locker.mutex()->lock();
    524     --d->waiters;
    525413
    526414    if (ret && !d->finished) {
     
    528416        d->terminated = true;
    529417        QThreadPrivate::finish(this, false);
    530     }
    531 
    532     if (d->finished && !d->waiters) {
    533         CloseHandle(d->handle);
    534         d->handle = 0;
    535418    }
    536419
     
    550433        QThreadPrivate::finish(thr, false);
    551434        locker.unlock(); // don't leave the mutex locked!
    552         _endthreadex(0);
     435        _endthread);
    553436    }
    554437}
     
    563446    }
    564447
    565     // copied from start() with a few modifications:
    566 
    567     // Since Win 9x will have problems if the priority is idle or time critical
    568     // we have to use the closest one instead
    569     int prio;
    570448    d->priority = priority;
    571     switch (d->priority) {
    572     case IdlePriority:
    573         if (QSysInfo::WindowsVersion & QSysInfo::WV_DOS_based) {
    574             prio = THREAD_PRIORITY_LOWEST;
    575         } else {
    576             prio = THREAD_PRIORITY_IDLE;
    577         }
    578         break;
    579 
    580     case LowestPriority:
    581         prio = THREAD_PRIORITY_LOWEST;
    582         break;
    583 
    584     case LowPriority:
    585         prio = THREAD_PRIORITY_BELOW_NORMAL;
    586         break;
    587 
    588     case NormalPriority:
    589         prio = THREAD_PRIORITY_NORMAL;
    590         break;
    591 
    592     case HighPriority:
    593         prio = THREAD_PRIORITY_ABOVE_NORMAL;
    594         break;
    595 
    596     case HighestPriority:
    597         prio = THREAD_PRIORITY_HIGHEST;
    598         break;
    599 
    600     case TimeCriticalPriority:
    601         if (QSysInfo::WindowsVersion & QSysInfo::WV_DOS_based) {
    602             prio = THREAD_PRIORITY_HIGHEST;
    603         } else {
    604             prio = THREAD_PRIORITY_TIME_CRITICAL;
    605         }
    606         break;
    607 
    608     case InheritPriority:
    609     default:
    610         qWarning("QThread::setPriority: Argument cannot be InheritPriority");
    611         return;
    612     }
    613 
    614     if (!SetThreadPriority(d->handle, prio)) {
    615         qErrnoWarning("QThread::setPriority: Failed to set thread priority");
    616     }
     449
     450    ULONG prioClass = 0;
     451    LONG prioDelta = 0;
     452    switch (priority) {
     453        case IdlePriority:
     454            prioClass = PRTYC_IDLETIME;
     455            prioDelta = PRTYD_MINIMUM;
     456        break;
     457
     458        case LowestPriority:
     459            prioClass = PRTYC_IDLETIME;
     460            break;
     461
     462        case LowPriority:
     463            prioClass = PRTYC_IDLETIME;
     464            prioDelta = PRTYD_MAXIMUM;
     465            break;
     466
     467        case NormalPriority:
     468                prioClass = PRTYC_REGULAR;
     469                break;
     470
     471        case HighPriority:
     472            prioClass = PRTYC_REGULAR;
     473            prioDelta = PRTYD_MAXIMUM;
     474            break;
     475
     476        case HighestPriority:
     477                prioClass = PRTYC_TIMECRITICAL;
     478                break;
     479
     480        case TimeCriticalPriority:
     481            prioClass = PRTYC_TIMECRITICAL;
     482            prioDelta = PRTYD_MAXIMUM;
     483            break;
     484
     485        case InheritPriority:
     486        default:
     487            PTIB ptib;
     488            DosGetInfoBlocks( &ptib, NULL );
     489            prioClass = (ptib->tib_ptib2->tib2_ulpri >> 8) & 0xFF;
     490            prioDelta = (ptib->tib_ptib2->tib2_ulpri) & 0xFF;
     491            break;
     492    }
     493
     494    APIRET rc = DosSetPriority(PRTYS_THREAD, prioClass, prioDelta, d->tid);
     495    if (rc != NO_ERROR)
     496        qWarning("QThread::setPriority: DosSetPriority returned %lu", rc);
    617497}
    618498
    619499QT_END_NAMESPACE
     500
    620501#endif // QT_NO_THREAD
  • trunk/src/corelib/thread/qthread_p.h

    r2 r69  
    6262#include "QtCore/qmap.h"
    6363#include "private/qobject_p.h"
     64
     65
     66
     67
    6468
    6569QT_BEGIN_NAMESPACE
     
    172176#endif // Q_OS_WIN32
    173177
     178
     179
     180
     181
     182
     183
     184
     185
    174186    QThreadData *data;
    175187
  • trunk/src/corelib/thread/thread.pri

    r2 r69  
    99           thread/qwaitcondition.h \
    1010           thread/qatomic.h
    11        
     11
    1212# private headers
    1313HEADERS += thread/qmutex_p.h \
     
    2323           thread/qsemaphore.cpp \
    2424           thread/qthread.cpp \
    25            thread/qthreadstorage.cpp 
     25           thread/qthreadstorage.cpp
    2626
    2727unix:SOURCES += thread/qmutex_unix.cpp \
     
    3232                 thread/qthread_win.cpp \
    3333                 thread/qwaitcondition_win.cpp
     34
     35
     36
     37
Note: See TracChangeset for help on using the changeset viewer.