Line | Source Code | Coverage |
---|
1 | | - |
2 | | - |
3 | | - |
4 | | - |
5 | | - |
6 | | - |
7 | | - |
8 | static void report_error(int code, const char *where, const char *what) | - |
9 | { | - |
10 | if (code != 0) partially evaluated: code != 0 no Evaluation Count:0 | yes Evaluation Count:101767059 |
| 0-101767059 |
11 | QMessageLogger("thread/qwaitcondition_unix.cpp", 61, __PRETTY_FUNCTION__).warning("%s: %s failure: %s", where, what, QString(qt_error_string(code)).toLocal8Bit().constData()); never executed: QMessageLogger("thread/qwaitcondition_unix.cpp", 61, __PRETTY_FUNCTION__).warning("%s: %s failure: %s", where, what, QString(qt_error_string(code)).toLocal8Bit().constData()); | 0 |
12 | } executed: } Execution Count:101744265 | 101744265 |
13 | | - |
14 | class QWaitConditionPrivate { | - |
15 | public: | - |
16 | pthread_mutex_t mutex; | - |
17 | pthread_cond_t cond; | - |
18 | int waiters; | - |
19 | int wakeups; | - |
20 | | - |
21 | bool wait(unsigned long time) | - |
22 | { | - |
23 | int code; | - |
24 | for(;;) { | - |
25 | if (time != (9223372036854775807L * 2UL + 1UL)) { evaluated: time != (9223372036854775807L * 2UL + 1UL) yes Evaluation Count:7137652 | yes Evaluation Count:2927835 |
| 2927835-7137652 |
26 | struct timeval tv; | - |
27 | gettimeofday(&tv, 0); | - |
28 | | - |
29 | timespec ti; | - |
30 | ti.tv_nsec = (tv.tv_usec + (time % 1000) * 1000) * 1000; | - |
31 | ti.tv_sec = tv.tv_sec + (time / 1000) + (ti.tv_nsec / 1000000000); | - |
32 | ti.tv_nsec %= 1000000000; | - |
33 | | - |
34 | code = pthread_cond_timedwait(&cond, &mutex, &ti); | - |
35 | } else { executed: } Execution Count:7137660 | 7137660 |
36 | code = pthread_cond_wait(&cond, &mutex); | - |
37 | } executed: } Execution Count:2927835 | 2927835 |
38 | if (code == 0 && wakeups == 0) { evaluated: code == 0 yes Evaluation Count:10065156 | yes Evaluation Count:316 |
partially evaluated: wakeups == 0 no Evaluation Count:0 | yes Evaluation Count:10065167 |
| 0-10065167 |
39 | | - |
40 | | - |
41 | | - |
42 | continue; never executed: continue; | 0 |
43 | } | - |
44 | break; executed: break; Execution Count:10065487 | 10065487 |
45 | } | - |
46 | | - |
47 | qt_noop(); | - |
48 | --waiters; | - |
49 | if (code == 0) { evaluated: code == 0 yes Evaluation Count:10065165 | yes Evaluation Count:316 |
| 316-10065165 |
50 | qt_noop(); | - |
51 | --wakeups; | - |
52 | } executed: } Execution Count:10065162 | 10065162 |
53 | report_error(pthread_mutex_unlock(&mutex), "QWaitCondition::wait()", "mutex unlock"); | - |
54 | | - |
55 | if (code && code != 110) evaluated: code yes Evaluation Count:316 | yes Evaluation Count:10064389 |
partially evaluated: code != 110 no Evaluation Count:0 | yes Evaluation Count:316 |
| 0-10064389 |
56 | report_error(code, "QWaitCondition::wait()", "cv wait"); never executed: report_error(code, "QWaitCondition::wait()", "cv wait"); | 0 |
57 | | - |
58 | return (code == 0); executed: return (code == 0); Execution Count:10064794 | 10064794 |
59 | } | - |
60 | }; | - |
61 | | - |
62 | | - |
63 | QWaitCondition::QWaitCondition() | - |
64 | { | - |
65 | d = new QWaitConditionPrivate; | - |
66 | report_error(pthread_mutex_init(&d->mutex, __null), "QWaitCondition", "mutex init"); | - |
67 | report_error(pthread_cond_init(&d->cond, __null), "QWaitCondition", "cv init"); | - |
68 | d->waiters = d->wakeups = 0; | - |
69 | } executed: } Execution Count:5128791 | 5128791 |
70 | | - |
71 | | - |
72 | QWaitCondition::~QWaitCondition() | - |
73 | { | - |
74 | report_error(pthread_cond_destroy(&d->cond), "QWaitCondition", "cv destroy"); | - |
75 | report_error(pthread_mutex_destroy(&d->mutex), "QWaitCondition", "mutex destroy"); | - |
76 | delete d; | - |
77 | } executed: } Execution Count:5141844 | 5141844 |
78 | | - |
79 | void QWaitCondition::wakeOne() | - |
80 | { | - |
81 | report_error(pthread_mutex_lock(&d->mutex), "QWaitCondition::wakeOne()", "mutex lock"); | - |
82 | d->wakeups = qMin(d->wakeups + 1, d->waiters); | - |
83 | report_error(pthread_cond_signal(&d->cond), "QWaitCondition::wakeOne()", "cv signal"); | - |
84 | report_error(pthread_mutex_unlock(&d->mutex), "QWaitCondition::wakeOne()", "mutex unlock"); | - |
85 | } executed: } Execution Count:6009952 | 6009952 |
86 | | - |
87 | void QWaitCondition::wakeAll() | - |
88 | { | - |
89 | report_error(pthread_mutex_lock(&d->mutex), "QWaitCondition::wakeAll()", "mutex lock"); | - |
90 | d->wakeups = d->waiters; | - |
91 | report_error(pthread_cond_broadcast(&d->cond), "QWaitCondition::wakeAll()", "cv broadcast"); | - |
92 | report_error(pthread_mutex_unlock(&d->mutex), "QWaitCondition::wakeAll()", "mutex unlock"); | - |
93 | } executed: } Execution Count:14492127 | 14492127 |
94 | | - |
95 | bool QWaitCondition::wait(QMutex *mutex, unsigned long time) | - |
96 | { | - |
97 | if (! mutex) partially evaluated: ! mutex no Evaluation Count:0 | yes Evaluation Count:10065198 |
| 0-10065198 |
98 | return false; never executed: return false; | 0 |
99 | if (mutex->isRecursive()) { partially evaluated: mutex->isRecursive() no Evaluation Count:0 | yes Evaluation Count:10065198 |
| 0-10065198 |
100 | QMessageLogger("thread/qwaitcondition_unix.cpp", 150, __PRETTY_FUNCTION__).warning("QWaitCondition: cannot wait on recursive mutexes"); | - |
101 | return false; never executed: return false; | 0 |
102 | } | - |
103 | | - |
104 | report_error(pthread_mutex_lock(&d->mutex), "QWaitCondition::wait()", "mutex lock"); | - |
105 | ++d->waiters; | - |
106 | mutex->unlock(); | - |
107 | | - |
108 | bool returnValue = d->wait(time); | - |
109 | | - |
110 | mutex->lock(); | - |
111 | | - |
112 | return returnValue; executed: return returnValue; Execution Count:10065213 | 10065213 |
113 | } | - |
114 | | - |
115 | bool QWaitCondition::wait(QReadWriteLock *readWriteLock, unsigned long time) | - |
116 | { | - |
117 | if (!readWriteLock || readWriteLock->d->accessCount == 0) partially evaluated: !readWriteLock no Evaluation Count:0 | yes Evaluation Count:273 |
partially evaluated: readWriteLock->d->accessCount == 0 no Evaluation Count:0 | yes Evaluation Count:273 |
| 0-273 |
118 | return false; never executed: return false; | 0 |
119 | if (readWriteLock->d->accessCount < -1) { partially evaluated: readWriteLock->d->accessCount < -1 no Evaluation Count:0 | yes Evaluation Count:273 |
| 0-273 |
120 | QMessageLogger("thread/qwaitcondition_unix.cpp", 170, __PRETTY_FUNCTION__).warning("QWaitCondition: cannot wait on QReadWriteLocks with recursive lockForWrite()"); | - |
121 | return false; never executed: return false; | 0 |
122 | } | - |
123 | | - |
124 | report_error(pthread_mutex_lock(&d->mutex), "QWaitCondition::wait()", "mutex lock"); | - |
125 | ++d->waiters; | - |
126 | | - |
127 | int previousAccessCount = readWriteLock->d->accessCount; | - |
128 | readWriteLock->unlock(); | - |
129 | | - |
130 | bool returnValue = d->wait(time); | - |
131 | | - |
132 | if (previousAccessCount < 0) evaluated: previousAccessCount < 0 yes Evaluation Count:231 | yes Evaluation Count:42 |
| 42-231 |
133 | readWriteLock->lockForWrite(); executed: readWriteLock->lockForWrite(); Execution Count:231 | 231 |
134 | else | - |
135 | readWriteLock->lockForRead(); executed: readWriteLock->lockForRead(); Execution Count:42 | 42 |
136 | | - |
137 | return returnValue; executed: return returnValue; Execution Count:273 | 273 |
138 | } | - |
139 | | - |
140 | | - |
141 | | - |
| | |