thread/qwaitcondition_unix.cpp

Switch to Source codePreprocessed file
LineSource CodeCoverage
1 -
2 -
3 -
4 -
5 -
6 -
7 -
8static void report_error(int code, const char *where, const char *what) -
9{ -
10 if (code != 0)
partially evaluated: code != 0
TRUEFALSE
no
Evaluation Count:0
yes
Evaluation Count:101519225
0-101519225
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:101486884
101486884
13 -
14class QWaitConditionPrivate { -
15public: -
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)
TRUEFALSE
yes
Evaluation Count:7198647
yes
Evaluation Count:2942931
2942931-7198647
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:7198655
7198655
36 code = pthread_cond_wait(&cond, &mutex); -
37 }
executed: }
Execution Count:2942932
2942932
38 if (code == 0 && wakeups == 0) {
evaluated: code == 0
TRUEFALSE
yes
Evaluation Count:10141259
yes
Evaluation Count:316
partially evaluated: wakeups == 0
TRUEFALSE
no
Evaluation Count:0
yes
Evaluation Count:10141263
0-10141263
39 -
40 -
41 -
42 continue;
never executed: continue;
0
43 } -
44 break;
executed: break;
Execution Count:10141579
10141579
45 } -
46 -
47 qt_noop(); -
48 --waiters; -
49 if (code == 0) {
evaluated: code == 0
TRUEFALSE
yes
Evaluation Count:10141260
yes
Evaluation Count:316
316-10141260
50 qt_noop(); -
51 --wakeups; -
52 }
executed: }
Execution Count:10141257
10141257
53 report_error(pthread_mutex_unlock(&mutex), "QWaitCondition::wait()", "mutex unlock"); -
54 -
55 if (code && code != 110)
evaluated: code
TRUEFALSE
yes
Evaluation Count:316
yes
Evaluation Count:10140469
partially evaluated: code != 110
TRUEFALSE
no
Evaluation Count:0
yes
Evaluation Count:316
0-10140469
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:10140797
10140797
59 } -
60}; -
61 -
62 -
63QWaitCondition::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:5191890
5191890
70 -
71 -
72QWaitCondition::~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:5205862
5205862
78 -
79void 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:6019812
6019812
86 -
87void 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:14269781
14269781
94 -
95bool QWaitCondition::wait(QMutex *mutex, unsigned long time) -
96{ -
97 if (! mutex)
partially evaluated: ! mutex
TRUEFALSE
no
Evaluation Count:0
yes
Evaluation Count:10141286
0-10141286
98 return false;
never executed: return false;
0
99 if (mutex->isRecursive()) {
partially evaluated: mutex->isRecursive()
TRUEFALSE
no
Evaluation Count:0
yes
Evaluation Count:10141275
0-10141275
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:10141291
10141291
113} -
114 -
115bool QWaitCondition::wait(QReadWriteLock *readWriteLock, unsigned long time) -
116{ -
117 if (!readWriteLock || readWriteLock->d->accessCount == 0)
partially evaluated: !readWriteLock
TRUEFALSE
no
Evaluation Count:0
yes
Evaluation Count:273
partially evaluated: readWriteLock->d->accessCount == 0
TRUEFALSE
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
TRUEFALSE
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
TRUEFALSE
yes
Evaluation Count:231
yes
Evaluation Count:41
41-231
133 readWriteLock->lockForWrite();
executed: readWriteLock->lockForWrite();
Execution Count:231
231
134 else -
135 readWriteLock->lockForRead();
executed: readWriteLock->lockForRead();
Execution Count:41
41
136 -
137 return returnValue;
executed: return returnValue;
Execution Count:273
273
138} -
139 -
140 -
141 -
Switch to Source codePreprocessed file

Generated by Squish Coco Non-Commercial