Changeset 846 for trunk/src/corelib/thread/qthread_unix.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/thread/qthread_unix.cpp
r651 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]) … … 93 93 #endif 94 94 95 96 97 98 99 100 101 102 103 104 95 105 QT_BEGIN_NAMESPACE 96 106 97 107 #ifndef QT_NO_THREAD 108 109 98 110 99 111 static pthread_once_t current_thread_data_once = PTHREAD_ONCE_INIT; … … 130 142 } 131 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 132 197 QThreadData *QThreadData::current() 133 198 { 134 pthread_once(¤t_thread_data_once, create_current_thread_data_key); 135 136 QThreadData *data = reinterpret_cast<QThreadData *>(pthread_getspecific(current_thread_data_key)); 199 QThreadData *data = get_thread_data(); 137 200 if (!data) { 138 201 void *a; … … 141 204 Q_ASSERT(adopted); 142 205 data = QThreadData::get2(adopted); 143 pthread_setspecific(current_thread_data_key,data);206 data); 144 207 adopted->d_func()->running = true; 145 208 adopted->d_func()->finished = false; … … 147 210 } else { 148 211 data = new QThreadData; 149 pthread_setspecific(current_thread_data_key, data);150 212 QT_TRY { 213 151 214 data->thread = new QAdoptedThread(data); 152 215 } QT_CATCH(...) { 153 pthread_setspecific(current_thread_data_key, 0);216 ); 154 217 data->deref(); 155 218 data = 0; … … 170 233 d->thread_id = pthread_self(); 171 234 #ifdef Q_OS_SYMBIAN 172 d->data->symbian_thread_handle = RThread(); 173 TThreadId threadId = d->data->symbian_thread_handle.Id(); 174 d->data->symbian_thread_handle.Open(threadId); 235 init_symbian_thread_handle(d->data->symbian_thread_handle); 175 236 #endif 176 237 } … … 222 283 QThreadData *data = QThreadData::get2(thr); 223 284 285 286 287 288 289 224 290 #ifdef Q_OS_SYMBIAN 225 291 // Because Symbian Open C does not provide a way to convert between … … 227 293 // handle when creating a thread, until we are running in the new thread. 228 294 // Here, we pick up the current thread and assign that to the handle. 229 data->symbian_thread_handle = RThread(); 230 TThreadId threadId = data->symbian_thread_handle.Id(); 231 data->symbian_thread_handle.Open(threadId); 232 #endif 233 234 pthread_once(¤t_thread_data_once, create_current_thread_data_key); 235 pthread_setspecific(current_thread_data_key, data); 295 init_symbian_thread_handle(data->symbian_thread_handle); 296 297 // On symbian, threads other than the main thread are non critical by default 298 // This means a worker thread can crash without crashing the application - to 299 // use this feature, we would need to use RThread::Logon in the main thread 300 // to catch abnormal thread exit and emit the finished signal. 301 // For the sake of cross platform consistency, we set the thread as process critical 302 // - advanced users who want the symbian behaviour can change the critical 303 // attribute of the thread again once the app gains control in run() 304 User::SetCritical(User::EProcessCritical); 305 #endif 306 307 set_thread_data(data); 236 308 237 309 data->ref(); … … 437 509 } 438 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 439 544 void QThread::start(Priority priority) 440 545 { … … 447 552 d->finished = false; 448 553 d->terminated = false; 554 555 449 556 450 557 pthread_attr_t attr; … … 454 561 d->priority = priority; 455 562 456 #if defined(Q _OS_DARWIN) || !defined(Q_OS_OPENBSD) && !defined(Q_OS_SYMBIAN) && defined(_POSIX_THREAD_PRIORITY_SCHEDULING) && (_POSIX_THREAD_PRIORITY_SCHEDULING-0 >= 0)563 #if defined(Q) 457 564 // ### Need to implement thread sheduling and priorities for symbian os. Implementation removed for now 458 565 switch (priority) { … … 473 580 } 474 581 475 int prio_min = sched_get_priority_min(sched_policy); 476 int prio_max = sched_get_priority_max(sched_policy); 477 if (prio_min == -1 || prio_max == -1) { 582 int prio; 583 if (!calculateUnixPriority(priority, &sched_policy, &prio)) { 478 584 // failed to get the scheduling parameters, don't 479 585 // bother setting the priority … … 482 588 } 483 589 484 int prio;485 switch (priority) {486 case IdlePriority:487 prio = prio_min;488 break;489 490 case TimeCriticalPriority:491 prio = prio_max;492 break;493 494 default:495 // crudely scale our priority enum values to the prio_min/prio_max496 prio = (priority * (prio_max - prio_min) / TimeCriticalPriority) + prio_min;497 prio = qMax(prio_min, qMin(prio_max, prio));498 break;499 }500 501 590 sched_param sp; 502 591 sp.sched_priority = prio; … … 506 595 || pthread_attr_setschedparam(&attr, &sp) != 0) { 507 596 // could not set scheduling hints, fallback to inheriting them 597 508 598 pthread_attr_setinheritsched(&attr, PTHREAD_INHERIT_SCHED); 599 509 600 } 510 601 break; 511 602 } 512 603 } 513 #endif // _POSIX_THREAD_PRIORITY_SCHEDULING604 #endif // _THREAD_PRIORITY_SCHEDULING 514 605 515 606 #ifdef Q_OS_SYMBIAN … … 617 708 618 709 while (d->running) { 710 711 712 713 714 715 716 717 718 719 720 721 619 722 if (!d->thread_done.wait(locker.mutex(), time)) 620 723 return false; … … 662 765 // copied from start() with a few modifications: 663 766 664 #if defined(Q_OS_DARWIN) || !defined(Q_OS_OPENBSD) && defined(_POSIX_THREAD_PRIORITY_SCHEDULING) && (_POSIX_THREAD_PRIORITY_SCHEDULING-0 >= 0)767 #if 665 768 int sched_policy; 666 769 sched_param param; … … 673 776 } 674 777 675 int prio_min = sched_get_priority_min(sched_policy); 676 int prio_max = sched_get_priority_max(sched_policy); 677 if (prio_min == -1 || prio_max == -1) { 778 int prio; 779 if (!calculateUnixPriority(priority, &sched_policy, &prio)) { 678 780 // failed to get the scheduling parameters, don't 679 781 // bother setting the priority … … 682 784 } 683 785 684 int prio;685 switch (priority) {686 case InheritPriority:687 qWarning("QThread::setPriority: Argument cannot be InheritPriority");688 return;689 690 case IdlePriority:691 prio = prio_min;692 break;693 694 case TimeCriticalPriority:695 prio = prio_max;696 break;697 698 default:699 // crudely scale our priority enum values to the prio_min/prio_max700 prio = (priority * (prio_max - prio_min) / TimeCriticalPriority) + prio_min;701 prio = qMax(prio_min, qMin(prio_max, prio));702 break;703 }704 705 786 param.sched_priority = prio; 706 pthread_setschedparam(d->thread_id, sched_policy, ¶m); 787 int status = pthread_setschedparam(d->thread_id, sched_policy, ¶m); 788 789 # ifdef SCHED_IDLE 790 // were we trying to set to idle priority and failed? 791 if (status == -1 && sched_policy == SCHED_IDLE && errno == EINVAL) { 792 // reset to lowest priority possible 793 pthread_getschedparam(d->thread_id, &sched_policy, ¶m); 794 param.sched_priority = sched_get_priority_min(sched_policy); 795 pthread_setschedparam(d->thread_id, sched_policy, ¶m); 796 } 797 # else 798 Q_UNUSED(status); 799 # endif // SCHED_IDLE 707 800 #endif 708 801 }
Note:
See TracChangeset
for help on using the changeset viewer.