| Absolute File Name: | /home/qt/qt5_coco/qt5/qtbase/src/corelib/kernel/qsharedmemory.cpp |
| Switch to Source code | Preprocessed file |
| Line | Source | Count | ||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| 1 | - | |||||||||||||
| 2 | - | |||||||||||||
| 3 | - | |||||||||||||
| 4 | - | |||||||||||||
| 5 | - | |||||||||||||
| 6 | - | |||||||||||||
| 7 | QString | - | ||||||||||||
| 8 | QSharedMemoryPrivate::makePlatformSafeKey(const QString &key, | - | ||||||||||||
| 9 | const QString &prefix) | - | ||||||||||||
| 10 | { | - | ||||||||||||
| 11 | if (key.isEmpty()
| 3737-7354 | ||||||||||||
| 12 | return executed 3737 times by 2 tests: QString();return QString();Executed by:
executed 3737 times by 2 tests: return QString();Executed by:
| 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: QDir::tempPath() + QLatin1Char('/') + result;return QDir::tempPath() + QLatin1Char('/') + result;Executed by:
executed 7354 times by 4 tests: return QDir::tempPath() + QLatin1Char('/') + result;Executed by:
| 7354 | ||||||||||||
| 28 | - | |||||||||||||
| 29 | } | - | ||||||||||||
| 30 | QSharedMemory::QSharedMemory(QObject *parent) | - | ||||||||||||
| 31 | : QObject(*new QSharedMemoryPrivate, parent) | - | ||||||||||||
| 32 | { | - | ||||||||||||
| 33 | } executed 4 times by 3 tests: end of blockExecuted by:
| 4 | ||||||||||||
| 34 | QSharedMemory::QSharedMemory(const QString &key, QObject *parent) | - | ||||||||||||
| 35 | : QObject(*new QSharedMemoryPrivate, parent) | - | ||||||||||||
| 36 | { | - | ||||||||||||
| 37 | setKey(key); | - | ||||||||||||
| 38 | } executed 3608 times by 1 test: end of blockExecuted by:
| 3608 | ||||||||||||
| 39 | QSharedMemory::~QSharedMemory() | - | ||||||||||||
| 40 | { | - | ||||||||||||
| 41 | setKey(QString()); | - | ||||||||||||
| 42 | } executed 3611 times by 2 tests: end of blockExecuted by:
| 3611 | ||||||||||||
| 43 | void QSharedMemory::setKey(const QString &key) | - | ||||||||||||
| 44 | { | - | ||||||||||||
| 45 | QSharedMemoryPrivate * const d = d_func(); | - | ||||||||||||
| 46 | if (key == d->key
| 5-7101 | ||||||||||||
| 47 | return; executed 124 times by 2 tests: return;Executed by:
| 124 | ||||||||||||
| 48 | - | |||||||||||||
| 49 | if (isAttached()
| 3465-3641 | ||||||||||||
| 50 | detach(); executed 3465 times by 1 test: detach();Executed by:
| 3465 | ||||||||||||
| 51 | d->cleanHandle(); | - | ||||||||||||
| 52 | d->key = key; | - | ||||||||||||
| 53 | d->nativeKey = d->makePlatformSafeKey(key); | - | ||||||||||||
| 54 | } executed 7106 times by 2 tests: end of blockExecuted by:
| 7106 | ||||||||||||
| 55 | void QSharedMemory::setNativeKey(const QString &key) | - | ||||||||||||
| 56 | { | - | ||||||||||||
| 57 | QSharedMemoryPrivate * const d = d_func(); | - | ||||||||||||
| 58 | if (key == d->nativeKey
| 0-7 | ||||||||||||
| 59 | return; executed 2 times by 1 test: return;Executed by:
| 2 | ||||||||||||
| 60 | - | |||||||||||||
| 61 | if (isAttached()
| 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 blockExecuted by:
| 7 | ||||||||||||
| 67 | - | |||||||||||||
| 68 | bool QSharedMemoryPrivate::initKey() | - | ||||||||||||
| 69 | { | - | ||||||||||||
| 70 | if (!cleanHandle()
| 0-3645 | ||||||||||||
| 71 | return never executed: false;return false;never executed: return false; | 0 | ||||||||||||
| 72 | - | |||||||||||||
| 73 | systemSemaphore.setKey(QString(), 1); | - | ||||||||||||
| 74 | systemSemaphore.setKey(key, 1); | - | ||||||||||||
| 75 | if (systemSemaphore.error() != QSystemSemaphore::NoError
| 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: QSystemSemaphore::PermissionDenied:case 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: QSystemSemaphore::KeyError:case QSystemSemaphore::KeyError:Executed by:
executed 52 times by 1 test: case QSystemSemaphore::KeyError:Executed by:
| 52 | ||||||||||||
| 83 | error = QSharedMemory::KeyError; | - | ||||||||||||
| 84 | break; executed 52 times by 1 test: break;Executed by:
| 52 | ||||||||||||
| 85 | case never executed: QSystemSemaphore::AlreadyExists:case QSystemSemaphore::AlreadyExists:never executed: case QSystemSemaphore::AlreadyExists: | 0 | ||||||||||||
| 86 | error = QSharedMemory::AlreadyExists; | - | ||||||||||||
| 87 | break; never executed: break; | 0 | ||||||||||||
| 88 | case never executed: QSystemSemaphore::NotFound:case 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: QSystemSemaphore::OutOfResources:case QSystemSemaphore::OutOfResources:Executed by:
executed 2 times by 1 test: case QSystemSemaphore::OutOfResources:Executed by:
| 2 | ||||||||||||
| 92 | error = QSharedMemory::OutOfResources; | - | ||||||||||||
| 93 | break; executed 2 times by 1 test: break;Executed by:
| 2 | ||||||||||||
| 94 | case never executed: QSystemSemaphore::UnknownError:case 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: false;return false;Executed by:
executed 54 times by 1 test: return false;Executed by:
| 54 | ||||||||||||
| 100 | } | - | ||||||||||||
| 101 | - | |||||||||||||
| 102 | errorString = QString(); | - | ||||||||||||
| 103 | error = QSharedMemory::NoError; | - | ||||||||||||
| 104 | return executed 3591 times by 2 tests: true;return true;Executed by:
executed 3591 times by 2 tests: return true;Executed by:
| 3591 | ||||||||||||
| 105 | } | - | ||||||||||||
| 106 | QString QSharedMemory::key() const | - | ||||||||||||
| 107 | { | - | ||||||||||||
| 108 | const QSharedMemoryPrivate * const d = d_func(); | - | ||||||||||||
| 109 | return executed 48 times by 1 test: d->key;return d->key;Executed by:
executed 48 times by 1 test: return d->key;Executed by:
| 48 | ||||||||||||
| 110 | } | - | ||||||||||||
| 111 | QString QSharedMemory::nativeKey() const | - | ||||||||||||
| 112 | { | - | ||||||||||||
| 113 | const QSharedMemoryPrivate * const d = d_func(); | - | ||||||||||||
| 114 | return executed 39 times by 1 test: d->nativeKey;return d->nativeKey;Executed by:
executed 39 times by 1 test: return d->nativeKey;Executed by:
| 39 | ||||||||||||
| 115 | } | - | ||||||||||||
| 116 | bool QSharedMemory::create(int size, AccessMode mode) | - | ||||||||||||
| 117 | { | - | ||||||||||||
| 118 | QSharedMemoryPrivate * const d = d_func(); | - | ||||||||||||
| 119 | - | |||||||||||||
| 120 | if (!d->initKey()
| 1-3521 | ||||||||||||
| 121 | return executed 1 time by 1 test: false;return false;Executed by:
executed 1 time by 1 test: return false;Executed by:
| 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()
| 0-3468 | ||||||||||||
| 135 | return never executed: false;return false;never executed: return false; | 0 | ||||||||||||
| 136 | - | |||||||||||||
| 137 | - | |||||||||||||
| 138 | if (size <= 0
| 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: false;return false;Executed by:
executed 1 time by 1 test: return false;Executed by:
| 1 | ||||||||||||
| 143 | } | - | ||||||||||||
| 144 | - | |||||||||||||
| 145 | if (!d->create(size)
| 55-3465 | ||||||||||||
| 146 | return executed 55 times by 1 test: false;return false;Executed by:
executed 55 times by 1 test: return false;Executed by:
| 55 | ||||||||||||
| 147 | - | |||||||||||||
| 148 | return executed 3465 times by 2 tests: d->attach(mode);return d->attach(mode);Executed by:
executed 3465 times by 2 tests: return d->attach(mode);Executed by:
| 3465 | ||||||||||||
| 149 | } | - | ||||||||||||
| 150 | - | |||||||||||||
| 151 | - | |||||||||||||
| 152 | - | |||||||||||||
| 153 | - | |||||||||||||
| 154 | - | |||||||||||||
| 155 | - | |||||||||||||
| 156 | - | |||||||||||||
| 157 | int QSharedMemory::size() const | - | ||||||||||||
| 158 | { | - | ||||||||||||
| 159 | const QSharedMemoryPrivate * const d = d_func(); | - | ||||||||||||
| 160 | return executed 17 times by 1 test: d->size;return d->size;Executed by:
executed 17 times by 1 test: return d->size;Executed by:
| 17 | ||||||||||||
| 161 | } | - | ||||||||||||
| 162 | bool QSharedMemory::attach(AccessMode mode) | - | ||||||||||||
| 163 | { | - | ||||||||||||
| 164 | QSharedMemoryPrivate * const d = d_func(); | - | ||||||||||||
| 165 | - | |||||||||||||
| 166 | if (isAttached()
| 0-123 | ||||||||||||
| 167 | return executed 53 times by 1 test: false;return false;Executed by:
executed 53 times by 1 test: return false;Executed by:
| 53 | ||||||||||||
| 168 | - | |||||||||||||
| 169 | QSharedMemoryLocker lock(this); | - | ||||||||||||
| 170 | if (!d->key.isNull()
| 0-69 | ||||||||||||
| 171 | return never executed: false;return false;never executed: return false; | 0 | ||||||||||||
| 172 | - | |||||||||||||
| 173 | - | |||||||||||||
| 174 | if (isAttached()
| 0-70 | ||||||||||||
| 175 | return executed 3 times by 1 test: false;return false;Executed by:
executed 3 times by 1 test: return false;Executed by:
| 3 | ||||||||||||
| 176 | - | |||||||||||||
| 177 | return executed 67 times by 1 test: d->attach(mode);return d->attach(mode);Executed by:
executed 67 times by 1 test: return d->attach(mode);Executed by:
| 67 | ||||||||||||
| 178 | } | - | ||||||||||||
| 179 | - | |||||||||||||
| 180 | - | |||||||||||||
| 181 | - | |||||||||||||
| 182 | - | |||||||||||||
| 183 | - | |||||||||||||
| 184 | - | |||||||||||||
| 185 | - | |||||||||||||
| 186 | bool QSharedMemory::isAttached() const | - | ||||||||||||
| 187 | { | - | ||||||||||||
| 188 | const QSharedMemoryPrivate * const d = d_func(); | - | ||||||||||||
| 189 | return executed 11064 times by 2 tests: (0 != d->memory);return (0 != d->memory);Executed by:
executed 11064 times by 2 tests: return (0 != d->memory);Executed by:
| 11064 | ||||||||||||
| 190 | } | - | ||||||||||||
| 191 | bool QSharedMemory::detach() | - | ||||||||||||
| 192 | { | - | ||||||||||||
| 193 | QSharedMemoryPrivate * const d = d_func(); | - | ||||||||||||
| 194 | if (!isAttached()
| 64-3531 | ||||||||||||
| 195 | return executed 64 times by 1 test: false;return false;Executed by:
executed 64 times by 1 test: return false;Executed by:
| 64 | ||||||||||||
| 196 | - | |||||||||||||
| 197 | - | |||||||||||||
| 198 | QSharedMemoryLocker lock(this); | - | ||||||||||||
| 199 | if (!d->key.isNull()
| 0-3531 | ||||||||||||
| 200 | return never executed: false;return false;never executed: return false; | 0 | ||||||||||||
| 201 | - | |||||||||||||
| 202 | - | |||||||||||||
| 203 | return executed 3531 times by 1 test: d->detach();return d->detach();Executed by:
executed 3531 times by 1 test: return d->detach();Executed by:
| 3531 | ||||||||||||
| 204 | } | - | ||||||||||||
| 205 | void *QSharedMemory::data() | - | ||||||||||||
| 206 | { | - | ||||||||||||
| 207 | QSharedMemoryPrivate * const d = d_func(); | - | ||||||||||||
| 208 | return executed 106 times by 2 tests: d->memory;return d->memory;Executed by:
executed 106 times by 2 tests: return d->memory;Executed by:
| 106 | ||||||||||||
| 209 | } | - | ||||||||||||
| 210 | const void* QSharedMemory::constData() const | - | ||||||||||||
| 211 | { | - | ||||||||||||
| 212 | const QSharedMemoryPrivate * const d = d_func(); | - | ||||||||||||
| 213 | return never executed: d->memory;return d->memory;never executed: return d->memory; | 0 | ||||||||||||
| 214 | } | - | ||||||||||||
| 215 | - | |||||||||||||
| 216 | - | |||||||||||||
| 217 | - | |||||||||||||
| 218 | - | |||||||||||||
| 219 | const void *QSharedMemory::data() const | - | ||||||||||||
| 220 | { | - | ||||||||||||
| 221 | const QSharedMemoryPrivate * const d = d_func(); | - | ||||||||||||
| 222 | return never executed: d->memory;return d->memory;never executed: return d->memory; | 0 | ||||||||||||
| 223 | } | - | ||||||||||||
| 224 | bool QSharedMemory::lock() | - | ||||||||||||
| 225 | { | - | ||||||||||||
| 226 | QSharedMemoryPrivate * const d = d_func(); | - | ||||||||||||
| 227 | if (d->lockedByMe
| 2-7581 | ||||||||||||
| 228 | QMessageLogger(__FILE__, 507, __PRETTY_FUNCTION__).warning("QSharedMemory::lock: already locked"); | - | ||||||||||||
| 229 | return executed 2 times by 1 test: true;return true;Executed by:
executed 2 times by 1 test: return true;Executed by:
| 2 | ||||||||||||
| 230 | } | - | ||||||||||||
| 231 | if (d->systemSemaphore.acquire()
| 2-7579 | ||||||||||||
| 232 | d->lockedByMe = true; | - | ||||||||||||
| 233 | return executed 7579 times by 2 tests: true;return true;Executed by:
executed 7579 times by 2 tests: return true;Executed by:
| 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: false;return false;Executed by:
executed 2 times by 1 test: return false;Executed by:
| 2 | ||||||||||||
| 239 | } | - | ||||||||||||
| 240 | bool QSharedMemory::unlock() | - | ||||||||||||
| 241 | { | - | ||||||||||||
| 242 | QSharedMemoryPrivate * const d = d_func(); | - | ||||||||||||
| 243 | if (!d->lockedByMe
| 54-7578 | ||||||||||||
| 244 | return executed 54 times by 1 test: false;return false;Executed by:
executed 54 times by 1 test: return false;Executed by:
| 54 | ||||||||||||
| 245 | d->lockedByMe = false; | - | ||||||||||||
| 246 | if (d->systemSemaphore.release()
| 0-7578 | ||||||||||||
| 247 | return executed 7578 times by 2 tests: true;return true;Executed by:
executed 7578 times by 2 tests: return true;Executed by:
| 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: false;return false;never executed: return false; | 0 | ||||||||||||
| 252 | } | - | ||||||||||||
| 253 | QSharedMemory::SharedMemoryError QSharedMemory::error() const | - | ||||||||||||
| 254 | { | - | ||||||||||||
| 255 | const QSharedMemoryPrivate * const d = d_func(); | - | ||||||||||||
| 256 | return executed 23 times by 1 test: d->error;return d->error;Executed by:
executed 23 times by 1 test: return d->error;Executed by:
| 23 | ||||||||||||
| 257 | } | - | ||||||||||||
| 258 | QString QSharedMemory::errorString() const | - | ||||||||||||
| 259 | { | - | ||||||||||||
| 260 | const QSharedMemoryPrivate * const d = d_func(); | - | ||||||||||||
| 261 | return executed 18 times by 1 test: d->errorString;return d->errorString;Executed by:
executed 18 times by 1 test: return d->errorString;Executed by:
| 18 | ||||||||||||
| 262 | } | - | ||||||||||||
| 263 | - | |||||||||||||
| 264 | - | |||||||||||||
| 265 | - | |||||||||||||
| 266 | - | |||||||||||||
| Switch to Source code | Preprocessed file |