qsharedmemory.cpp

Absolute File Name:/home/qt/qt5_coco/qt5/qtbase/src/corelib/kernel/qsharedmemory.cpp
Switch to Source codePreprocessed file
LineSourceCount
1-
2-
3-
4-
5-
6-
7QString-
8QSharedMemoryPrivate::makePlatformSafeKey(const QString &key,-
9 const QString &prefix)-
10{-
11 if (key.isEmpty()
key.isEmpty()Description
TRUEevaluated 3737 times by 2 tests
Evaluated by:
  • tst_QSharedMemory
  • tst_qapplication - unknown status
FALSEevaluated 7354 times by 4 tests
Evaluated by:
  • tst_QSharedMemory
  • tst_QSystemSemaphore
  • tst_qsharedmemory - unknown status
  • tst_qsystemsemaphore - unknown status
)
3737-7354
12 return
executed 3737 times by 2 tests: return QString();
Executed by:
  • tst_QSharedMemory
  • tst_qapplication - unknown status
QString();
executed 3737 times by 2 tests: return QString();
Executed by:
  • tst_QSharedMemory
  • tst_qapplication - unknown status
3737
13-
14 QString result = prefix;-
15-
16 QString part1 = key;-
17 part1.replace(QRegExp(QLatin1String("[^A-Za-z]")), QString());-
18 result.append(part1);-
19-
20 QByteArray hex = QCryptographicHash::hash(key.toUtf8(), QCryptographicHash::Sha1).toHex();-
21 result.append(QLatin1String(hex));-
22-
23-
24-
25-
26-
27 return
executed 7354 times by 4 tests: return QDir::tempPath() + QLatin1Char('/') + result;
Executed by:
  • tst_QSharedMemory
  • tst_QSystemSemaphore
  • tst_qsharedmemory - unknown status
  • tst_qsystemsemaphore - unknown status
QDir::tempPath() + QLatin1Char('/') + result;
executed 7354 times by 4 tests: return QDir::tempPath() + QLatin1Char('/') + result;
Executed by:
  • tst_QSharedMemory
  • tst_QSystemSemaphore
  • tst_qsharedmemory - unknown status
  • tst_qsystemsemaphore - unknown status
7354
28-
29}-
30QSharedMemory::QSharedMemory(QObject *parent)-
31 : QObject(*new QSharedMemoryPrivate, parent)-
32{-
33}
executed 4 times by 3 tests: end of block
Executed by:
  • tst_QApplication
  • tst_QSharedMemory
  • tst_qsharedmemory - unknown status
4
34QSharedMemory::QSharedMemory(const QString &key, QObject *parent)-
35 : QObject(*new QSharedMemoryPrivate, parent)-
36{-
37 setKey(key);-
38}
executed 3608 times by 1 test: end of block
Executed by:
  • tst_QSharedMemory
3608
39QSharedMemory::~QSharedMemory()-
40{-
41 setKey(QString());-
42}
executed 3611 times by 2 tests: end of block
Executed by:
  • tst_QSharedMemory
  • tst_qapplication - unknown status
3611
43void QSharedMemory::setKey(const QString &key)-
44{-
45 QSharedMemoryPrivate * const d = d_func();-
46 if (key == d->key
key == d->keyDescription
TRUEevaluated 129 times by 2 tests
Evaluated by:
  • tst_QSharedMemory
  • tst_qapplication - unknown status
FALSEevaluated 7101 times by 2 tests
Evaluated by:
  • tst_QSharedMemory
  • tst_qsharedmemory - unknown status
&& d->makePlatformSafeKey(key) == d->nativeKey
d->makePlatfor...= d->nativeKeyDescription
TRUEevaluated 124 times by 2 tests
Evaluated by:
  • tst_QSharedMemory
  • tst_qapplication - unknown status
FALSEevaluated 5 times by 1 test
Evaluated by:
  • tst_QSharedMemory
)
5-7101
47 return;
executed 124 times by 2 tests: return;
Executed by:
  • tst_QSharedMemory
  • tst_qapplication - unknown status
124
48-
49 if (isAttached()
isAttached()Description
TRUEevaluated 3465 times by 1 test
Evaluated by:
  • tst_QSharedMemory
FALSEevaluated 3641 times by 2 tests
Evaluated by:
  • tst_QSharedMemory
  • tst_qsharedmemory - unknown status
)
3465-3641
50 detach();
executed 3465 times by 1 test: detach();
Executed by:
  • tst_QSharedMemory
3465
51 d->cleanHandle();-
52 d->key = key;-
53 d->nativeKey = d->makePlatformSafeKey(key);-
54}
executed 7106 times by 2 tests: end of block
Executed by:
  • tst_QSharedMemory
  • tst_qsharedmemory - unknown status
7106
55void QSharedMemory::setNativeKey(const QString &key)-
56{-
57 QSharedMemoryPrivate * const d = d_func();-
58 if (key == d->nativeKey
key == d->nativeKeyDescription
TRUEevaluated 2 times by 1 test
Evaluated by:
  • tst_QSharedMemory
FALSEevaluated 7 times by 1 test
Evaluated by:
  • tst_QSharedMemory
&& d->key.isNull()
d->key.isNull()Description
TRUEevaluated 2 times by 1 test
Evaluated by:
  • tst_QSharedMemory
FALSEnever evaluated
)
0-7
59 return;
executed 2 times by 1 test: return;
Executed by:
  • tst_QSharedMemory
2
60-
61 if (isAttached()
isAttached()Description
TRUEnever evaluated
FALSEevaluated 7 times by 1 test
Evaluated by:
  • tst_QSharedMemory
)
0-7
62 detach();
never executed: detach();
0
63 d->cleanHandle();-
64 d->key = QString();-
65 d->nativeKey = key;-
66}
executed 7 times by 1 test: end of block
Executed by:
  • tst_QSharedMemory
7
67-
68bool QSharedMemoryPrivate::initKey()-
69{-
70 if (!cleanHandle()
!cleanHandle()Description
TRUEnever evaluated
FALSEevaluated 3645 times by 2 tests
Evaluated by:
  • tst_QSharedMemory
  • tst_qsharedmemory - unknown status
)
0-3645
71 return
never executed: return false;
false;
never executed: return false;
0
72-
73 systemSemaphore.setKey(QString(), 1);-
74 systemSemaphore.setKey(key, 1);-
75 if (systemSemaphore.error() != QSystemSemaphore::NoError
systemSemaphor...phore::NoErrorDescription
TRUEevaluated 54 times by 1 test
Evaluated by:
  • tst_QSharedMemory
FALSEevaluated 3591 times by 2 tests
Evaluated by:
  • tst_QSharedMemory
  • tst_qsharedmemory - unknown status
) {
54-3591
76 QString function = QLatin1String("QSharedMemoryPrivate::initKey");-
77 errorString = QSharedMemory::tr("%1: unable to set key on lock").arg(function);-
78 switch(systemSemaphore.error()) {-
79 case
never executed: case QSystemSemaphore::PermissionDenied:
QSystemSemaphore::PermissionDenied:
never executed: case QSystemSemaphore::PermissionDenied:
0
80 error = QSharedMemory::PermissionDenied;-
81 break;
never executed: break;
0
82 case
executed 52 times by 1 test: case QSystemSemaphore::KeyError:
Executed by:
  • tst_QSharedMemory
QSystemSemaphore::KeyError:
executed 52 times by 1 test: case QSystemSemaphore::KeyError:
Executed by:
  • tst_QSharedMemory
52
83 error = QSharedMemory::KeyError;-
84 break;
executed 52 times by 1 test: break;
Executed by:
  • tst_QSharedMemory
52
85 case
never executed: case QSystemSemaphore::AlreadyExists:
QSystemSemaphore::AlreadyExists:
never executed: case QSystemSemaphore::AlreadyExists:
0
86 error = QSharedMemory::AlreadyExists;-
87 break;
never executed: break;
0
88 case
never executed: case QSystemSemaphore::NotFound:
QSystemSemaphore::NotFound:
never executed: case QSystemSemaphore::NotFound:
0
89 error = QSharedMemory::NotFound;-
90 break;
never executed: break;
0
91 case
executed 2 times by 1 test: case QSystemSemaphore::OutOfResources:
Executed by:
  • tst_QSharedMemory
QSystemSemaphore::OutOfResources:
executed 2 times by 1 test: case QSystemSemaphore::OutOfResources:
Executed by:
  • tst_QSharedMemory
2
92 error = QSharedMemory::OutOfResources;-
93 break;
executed 2 times by 1 test: break;
Executed by:
  • tst_QSharedMemory
2
94 case
never executed: case QSystemSemaphore::UnknownError:
QSystemSemaphore::UnknownError:
never executed: case QSystemSemaphore::UnknownError:
0
95 default
never executed: default:
:
never executed: default:
0
96 error = QSharedMemory::UnknownError;-
97 break;
never executed: break;
0
98 }-
99 return
executed 54 times by 1 test: return false;
Executed by:
  • tst_QSharedMemory
false;
executed 54 times by 1 test: return false;
Executed by:
  • tst_QSharedMemory
54
100 }-
101-
102 errorString = QString();-
103 error = QSharedMemory::NoError;-
104 return
executed 3591 times by 2 tests: return true;
Executed by:
  • tst_QSharedMemory
  • tst_qsharedmemory - unknown status
true;
executed 3591 times by 2 tests: return true;
Executed by:
  • tst_QSharedMemory
  • tst_qsharedmemory - unknown status
3591
105}-
106QString QSharedMemory::key() const-
107{-
108 const QSharedMemoryPrivate * const d = d_func();-
109 return
executed 48 times by 1 test: return d->key;
Executed by:
  • tst_QSharedMemory
d->key;
executed 48 times by 1 test: return d->key;
Executed by:
  • tst_QSharedMemory
48
110}-
111QString QSharedMemory::nativeKey() const-
112{-
113 const QSharedMemoryPrivate * const d = d_func();-
114 return
executed 39 times by 1 test: return d->nativeKey;
Executed by:
  • tst_QSharedMemory
d->nativeKey;
executed 39 times by 1 test: return d->nativeKey;
Executed by:
  • tst_QSharedMemory
39
115}-
116bool QSharedMemory::create(int size, AccessMode mode)-
117{-
118 QSharedMemoryPrivate * const d = d_func();-
119-
120 if (!d->initKey()
!d->initKey()Description
TRUEevaluated 1 time by 1 test
Evaluated by:
  • tst_QSharedMemory
FALSEevaluated 3521 times by 2 tests
Evaluated by:
  • tst_QSharedMemory
  • tst_qsharedmemory - unknown status
)
1-3521
121 return
executed 1 time by 1 test: return false;
Executed by:
  • tst_QSharedMemory
false;
executed 1 time by 1 test: return false;
Executed by:
  • tst_QSharedMemory
1
122-
123-
124-
125-
126-
127 d->systemSemaphore.setKey(d->key, 1, QSystemSemaphore::Create);-
128-
129-
130-
131 QString function = QLatin1String("QSharedMemory::create");-
132-
133 QSharedMemoryLocker lock(this);-
134 if (!d->key.isNull()
!d->key.isNull()Description
TRUEevaluated 3468 times by 2 tests
Evaluated by:
  • tst_QSharedMemory
  • tst_qsharedmemory - unknown status
FALSEevaluated 53 times by 1 test
Evaluated by:
  • tst_QSharedMemory
&& !d->tryLocker(&lock, function)
!d->tryLocker(&lock, function)Description
TRUEnever evaluated
FALSEevaluated 3468 times by 2 tests
Evaluated by:
  • tst_QSharedMemory
  • tst_qsharedmemory - unknown status
)
0-3468
135 return
never executed: return false;
false;
never executed: return false;
0
136-
137-
138 if (size <= 0
size <= 0Description
TRUEevaluated 1 time by 1 test
Evaluated by:
  • tst_QSharedMemory
FALSEevaluated 3520 times by 2 tests
Evaluated by:
  • tst_QSharedMemory
  • tst_qsharedmemory - unknown status
) {
1-3520
139 d->error = QSharedMemory::InvalidSize;-
140 d->errorString =-
141 QSharedMemory::tr("%1: create size is less then 0").arg(function);-
142 return
executed 1 time by 1 test: return false;
Executed by:
  • tst_QSharedMemory
false;
executed 1 time by 1 test: return false;
Executed by:
  • tst_QSharedMemory
1
143 }-
144-
145 if (!d->create(size)
!d->create(size)Description
TRUEevaluated 55 times by 1 test
Evaluated by:
  • tst_QSharedMemory
FALSEevaluated 3465 times by 2 tests
Evaluated by:
  • tst_QSharedMemory
  • tst_qsharedmemory - unknown status
)
55-3465
146 return
executed 55 times by 1 test: return false;
Executed by:
  • tst_QSharedMemory
false;
executed 55 times by 1 test: return false;
Executed by:
  • tst_QSharedMemory
55
147-
148 return
executed 3465 times by 2 tests: return d->attach(mode);
Executed by:
  • tst_QSharedMemory
  • tst_qsharedmemory - unknown status
d->attach(mode);
executed 3465 times by 2 tests: return d->attach(mode);
Executed by:
  • tst_QSharedMemory
  • tst_qsharedmemory - unknown status
3465
149}-
150-
151-
152-
153-
154-
155-
156-
157int QSharedMemory::size() const-
158{-
159 const QSharedMemoryPrivate * const d = d_func();-
160 return
executed 17 times by 1 test: return d->size;
Executed by:
  • tst_QSharedMemory
d->size;
executed 17 times by 1 test: return d->size;
Executed by:
  • tst_QSharedMemory
17
161}-
162bool QSharedMemory::attach(AccessMode mode)-
163{-
164 QSharedMemoryPrivate * const d = d_func();-
165-
166 if (isAttached()
isAttached()Description
TRUEnever evaluated
FALSEevaluated 123 times by 1 test
Evaluated by:
  • tst_QSharedMemory
|| !d->initKey()
!d->initKey()Description
TRUEevaluated 53 times by 1 test
Evaluated by:
  • tst_QSharedMemory
FALSEevaluated 70 times by 1 test
Evaluated by:
  • tst_QSharedMemory
)
0-123
167 return
executed 53 times by 1 test: return false;
Executed by:
  • tst_QSharedMemory
false;
executed 53 times by 1 test: return false;
Executed by:
  • tst_QSharedMemory
53
168-
169 QSharedMemoryLocker lock(this);-
170 if (!d->key.isNull()
!d->key.isNull()Description
TRUEevaluated 69 times by 1 test
Evaluated by:
  • tst_QSharedMemory
FALSEevaluated 1 time by 1 test
Evaluated by:
  • tst_QSharedMemory
&& !d->tryLocker(&lock, QLatin1String("QSharedMemory::attach"))
!d->tryLocker(...ory::attach"))Description
TRUEnever evaluated
FALSEevaluated 69 times by 1 test
Evaluated by:
  • tst_QSharedMemory
)
0-69
171 return
never executed: return false;
false;
never executed: return false;
0
172-
173-
174 if (isAttached()
isAttached()Description
TRUEnever evaluated
FALSEevaluated 70 times by 1 test
Evaluated by:
  • tst_QSharedMemory
|| !d->handle()
!d->handle()Description
TRUEevaluated 3 times by 1 test
Evaluated by:
  • tst_QSharedMemory
FALSEevaluated 67 times by 1 test
Evaluated by:
  • tst_QSharedMemory
)
0-70
175 return
executed 3 times by 1 test: return false;
Executed by:
  • tst_QSharedMemory
false;
executed 3 times by 1 test: return false;
Executed by:
  • tst_QSharedMemory
3
176-
177 return
executed 67 times by 1 test: return d->attach(mode);
Executed by:
  • tst_QSharedMemory
d->attach(mode);
executed 67 times by 1 test: return d->attach(mode);
Executed by:
  • tst_QSharedMemory
67
178}-
179-
180-
181-
182-
183-
184-
185-
186bool QSharedMemory::isAttached() const-
187{-
188 const QSharedMemoryPrivate * const d = d_func();-
189 return
executed 11064 times by 2 tests: return (0 != d->memory);
Executed by:
  • tst_QSharedMemory
  • tst_qsharedmemory - unknown status
(0 != d->memory);
executed 11064 times by 2 tests: return (0 != d->memory);
Executed by:
  • tst_QSharedMemory
  • tst_qsharedmemory - unknown status
11064
190}-
191bool QSharedMemory::detach()-
192{-
193 QSharedMemoryPrivate * const d = d_func();-
194 if (!isAttached()
!isAttached()Description
TRUEevaluated 64 times by 1 test
Evaluated by:
  • tst_QSharedMemory
FALSEevaluated 3531 times by 1 test
Evaluated by:
  • tst_QSharedMemory
)
64-3531
195 return
executed 64 times by 1 test: return false;
Executed by:
  • tst_QSharedMemory
false;
executed 64 times by 1 test: return false;
Executed by:
  • tst_QSharedMemory
64
196-
197-
198 QSharedMemoryLocker lock(this);-
199 if (!d->key.isNull()
!d->key.isNull()Description
TRUEevaluated 3531 times by 1 test
Evaluated by:
  • tst_QSharedMemory
FALSEnever evaluated
&& !d->tryLocker(&lock, QLatin1String("QSharedMemory::detach"))
!d->tryLocker(...ory::detach"))Description
TRUEnever evaluated
FALSEevaluated 3531 times by 1 test
Evaluated by:
  • tst_QSharedMemory
)
0-3531
200 return
never executed: return false;
false;
never executed: return false;
0
201-
202-
203 return
executed 3531 times by 1 test: return d->detach();
Executed by:
  • tst_QSharedMemory
d->detach();
executed 3531 times by 1 test: return d->detach();
Executed by:
  • tst_QSharedMemory
3531
204}-
205void *QSharedMemory::data()-
206{-
207 QSharedMemoryPrivate * const d = d_func();-
208 return
executed 106 times by 2 tests: return d->memory;
Executed by:
  • tst_QSharedMemory
  • tst_qsharedmemory - unknown status
d->memory;
executed 106 times by 2 tests: return d->memory;
Executed by:
  • tst_QSharedMemory
  • tst_qsharedmemory - unknown status
106
209}-
210const void* QSharedMemory::constData() const-
211{-
212 const QSharedMemoryPrivate * const d = d_func();-
213 return
never executed: return d->memory;
d->memory;
never executed: return d->memory;
0
214}-
215-
216-
217-
218-
219const void *QSharedMemory::data() const-
220{-
221 const QSharedMemoryPrivate * const d = d_func();-
222 return
never executed: return d->memory;
d->memory;
never executed: return d->memory;
0
223}-
224bool QSharedMemory::lock()-
225{-
226 QSharedMemoryPrivate * const d = d_func();-
227 if (d->lockedByMe
d->lockedByMeDescription
TRUEevaluated 2 times by 1 test
Evaluated by:
  • tst_QSharedMemory
FALSEevaluated 7581 times by 2 tests
Evaluated by:
  • tst_QSharedMemory
  • tst_qsharedmemory - unknown status
) {
2-7581
228 QMessageLogger(__FILE__, 507, __PRETTY_FUNCTION__).warning("QSharedMemory::lock: already locked");-
229 return
executed 2 times by 1 test: return true;
Executed by:
  • tst_QSharedMemory
true;
executed 2 times by 1 test: return true;
Executed by:
  • tst_QSharedMemory
2
230 }-
231 if (d->systemSemaphore.acquire()
d->systemSemaphore.acquire()Description
TRUEevaluated 7579 times by 2 tests
Evaluated by:
  • tst_QSharedMemory
  • tst_qsharedmemory - unknown status
FALSEevaluated 2 times by 1 test
Evaluated by:
  • tst_QSharedMemory
) {
2-7579
232 d->lockedByMe = true;-
233 return
executed 7579 times by 2 tests: return true;
Executed by:
  • tst_QSharedMemory
  • tst_qsharedmemory - unknown status
true;
executed 7579 times by 2 tests: return true;
Executed by:
  • tst_QSharedMemory
  • tst_qsharedmemory - unknown status
7579
234 }-
235 QString function = QLatin1String("QSharedMemory::lock");-
236 d->errorString = QSharedMemory::tr("%1: unable to lock").arg(function);-
237 d->error = QSharedMemory::LockError;-
238 return
executed 2 times by 1 test: return false;
Executed by:
  • tst_QSharedMemory
false;
executed 2 times by 1 test: return false;
Executed by:
  • tst_QSharedMemory
2
239}-
240bool QSharedMemory::unlock()-
241{-
242 QSharedMemoryPrivate * const d = d_func();-
243 if (!d->lockedByMe
!d->lockedByMeDescription
TRUEevaluated 54 times by 1 test
Evaluated by:
  • tst_QSharedMemory
FALSEevaluated 7578 times by 2 tests
Evaluated by:
  • tst_QSharedMemory
  • tst_qsharedmemory - unknown status
)
54-7578
244 return
executed 54 times by 1 test: return false;
Executed by:
  • tst_QSharedMemory
false;
executed 54 times by 1 test: return false;
Executed by:
  • tst_QSharedMemory
54
245 d->lockedByMe = false;-
246 if (d->systemSemaphore.release()
d->systemSemaphore.release()Description
TRUEevaluated 7578 times by 2 tests
Evaluated by:
  • tst_QSharedMemory
  • tst_qsharedmemory - unknown status
FALSEnever evaluated
)
0-7578
247 return
executed 7578 times by 2 tests: return true;
Executed by:
  • tst_QSharedMemory
  • tst_qsharedmemory - unknown status
true;
executed 7578 times by 2 tests: return true;
Executed by:
  • tst_QSharedMemory
  • tst_qsharedmemory - unknown status
7578
248 QString function = QLatin1String("QSharedMemory::unlock");-
249 d->errorString = QSharedMemory::tr("%1: unable to unlock").arg(function);-
250 d->error = QSharedMemory::LockError;-
251 return
never executed: return false;
false;
never executed: return false;
0
252}-
253QSharedMemory::SharedMemoryError QSharedMemory::error() const-
254{-
255 const QSharedMemoryPrivate * const d = d_func();-
256 return
executed 23 times by 1 test: return d->error;
Executed by:
  • tst_QSharedMemory
d->error;
executed 23 times by 1 test: return d->error;
Executed by:
  • tst_QSharedMemory
23
257}-
258QString QSharedMemory::errorString() const-
259{-
260 const QSharedMemoryPrivate * const d = d_func();-
261 return
executed 18 times by 1 test: return d->errorString;
Executed by:
  • tst_QSharedMemory
d->errorString;
executed 18 times by 1 test: return d->errorString;
Executed by:
  • tst_QSharedMemory
18
262}-
263-
264-
265-
266-
Switch to Source codePreprocessed file

Generated by Squish Coco Non-Commercial 4.3.0-BETA-master-30-08-2018-4cb69e9