Showing the changes to libraries/script-engine/src/qtscript/ScriptEngineQtScript_cast.cpp (1 of 2 files). Show all
Unified · Split
| @@ -27,8 +27,9 @@ void ScriptEngineQtScript::setDefaultPrototype(int metaTypeId, const ScriptValue · 26 unmodified lines | ||
| 27 | 27 | ScriptValueQtWrapper* unwrappedPrototype = ScriptValueQtWrapper::unwrap(prototype); |
| 28 | 28 | if (unwrappedPrototype) { |
| 29 | 29 | const QScriptValue& scriptPrototype = unwrappedPrototype->toQtValue(); |
| 30 | − QMutexLocker guard(&_customTypeProtect); | |
| 30 | + _customTypeProtect.lockForWrite(); | |
| 31 | 31 | _customPrototypes.insert(metaTypeId, scriptPrototype); |
| 32 | + _customTypeProtect.unlock(); | |
| 32 | 33 | } |
| 33 | 34 | } |
| 34 | 35 | |
| @@ -36,12 +37,13 @@ void ScriptEngineQtScript::registerCustomType(int type, · 1 unmodified line | ||
| 36 | 37 | ScriptEngine::MarshalFunction marshalFunc, |
| 37 | 38 | ScriptEngine::DemarshalFunction demarshalFunc) |
| 38 | 39 | { |
| 39 | − QMutexLocker guard(&_customTypeProtect); | |
| 40 | + _customTypeProtect.lockForWrite(); | |
| 40 | 41 | |
| 41 | 42 | // storing it in a map for our own benefit |
| 42 | 43 | CustomMarshal& customType = _customTypes.insert(type, CustomMarshal()).value(); |
| 43 | 44 | customType.demarshalFunc = demarshalFunc; |
| 44 | 45 | customType.marshalFunc = marshalFunc; |
| 46 | + _customTypeProtect.unlock(); | |
| 45 | 47 | } |
| 46 | 48 | |
| 47 | 49 | Q_DECLARE_METATYPE(ScriptValue); |
| @@ -225,11 +227,12 @@ bool ScriptEngineQtScript::castValueToVariant(const QScriptValue& val, QVariant& · 177 unmodified lines | ||
| 225 | 227 | // do we have a registered handler for this type? |
| 226 | 228 | ScriptEngine::DemarshalFunction demarshalFunc = nullptr; |
| 227 | 229 | { |
| 228 | − QMutexLocker guard(&_customTypeProtect); | |
| 230 | + _customTypeProtect.lockForRead(); | |
| 229 | 231 | CustomMarshalMap::const_iterator lookup = _customTypes.find(destTypeId); |
| 230 | 232 | if (lookup != _customTypes.cend()) { |
| 231 | 233 | demarshalFunc = lookup.value().demarshalFunc; |
| 232 | 234 | } |
| 235 | + _customTypeProtect.unlock(); | |
| 233 | 236 | } |
| 234 | 237 | if (demarshalFunc) { |
| 235 | 238 | dest = QVariant(destTypeId, static_cast<void*>(NULL)); |
| @@ -400,11 +403,12 @@ QScriptValue ScriptEngineQtScript::castVariantToValue(const QVariant& val) { · 164 unmodified lines | ||
| 400 | 403 | // do we have a registered handler for this type? |
| 401 | 404 | ScriptEngine::MarshalFunction marshalFunc = nullptr; |
| 402 | 405 | { |
| 403 | − QMutexLocker guard(&_customTypeProtect); | |
| 406 | + _customTypeProtect.lockForRead(); | |
| 404 | 407 | CustomMarshalMap::const_iterator lookup = _customTypes.find(valTypeId); |
| 405 | 408 | if (lookup != _customTypes.cend()) { |
| 406 | 409 | marshalFunc = lookup.value().marshalFunc; |
| 407 | 410 | } |
| 411 | + _customTypeProtect.unlock(); | |
| 408 | 412 | } |
| 409 | 413 | if (marshalFunc) { |
| 410 | 414 | ScriptValue wrappedVal = marshalFunc(this, val.constData()); |
| @@ -455,11 +459,12 @@ QScriptValue ScriptEngineQtScript::castVariantToValue(const QVariant& val) { · 44 unmodified lines | ||
| 455 | 459 | } |
| 456 | 460 | // have we set a prototype'd variant? |
| 457 | 461 | { |
| 458 | − QMutexLocker guard(&_customTypeProtect); | |
| 462 | + _customTypeProtect.lockForRead(); | |
| 459 | 463 | CustomPrototypeMap::const_iterator lookup = _customPrototypes.find(valTypeId); |
| 460 | 464 | if (lookup != _customPrototypes.cend()) { |
| 461 | 465 | return ScriptVariantQtProxy::newVariant(this, val, lookup.value()); |
| 462 | 466 | } |
| 467 | + _customTypeProtect.unlock(); | |
| 463 | 468 | } |
| 464 | 469 | // just do a generic variant |
| 465 | 470 | return QScriptEngine::newVariant(val); |