History

Replaced regular mutex with a read write one to improve performance

ksuprynowicz committed 4 years ago

Commit 5a9b0cc1 parent ad57a5e2 files · +11 −6Browse files

Showing the changes to libraries/script-engine/src/qtscript/ScriptEngineQtScript_cast.cpp (1 of 2 files). Show all

Unified · Split

libraries/script-engine/src/qtscript/ScriptEngineQtScript_cast.cpp+10−5
@@ -27,8 +27,9 @@ void ScriptEngineQtScript::setDefaultPrototype(int metaTypeId, const ScriptValue · 26 unmodified lines
2727 ScriptValueQtWrapper* unwrappedPrototype = ScriptValueQtWrapper::unwrap(prototype);
2828 if (unwrappedPrototype) {
2929 const QScriptValue& scriptPrototype = unwrappedPrototype->toQtValue();
30− QMutexLocker guard(&_customTypeProtect);
30+ _customTypeProtect.lockForWrite();
3131 _customPrototypes.insert(metaTypeId, scriptPrototype);
32+ _customTypeProtect.unlock();
3233 }
3334 }
3435
@@ -36,12 +37,13 @@ void ScriptEngineQtScript::registerCustomType(int type, · 1 unmodified line
3637 ScriptEngine::MarshalFunction marshalFunc,
3738 ScriptEngine::DemarshalFunction demarshalFunc)
3839 {
39− QMutexLocker guard(&_customTypeProtect);
40+ _customTypeProtect.lockForWrite();
4041
4142 // storing it in a map for our own benefit
4243 CustomMarshal& customType = _customTypes.insert(type, CustomMarshal()).value();
4344 customType.demarshalFunc = demarshalFunc;
4445 customType.marshalFunc = marshalFunc;
46+ _customTypeProtect.unlock();
4547 }
4648
4749 Q_DECLARE_METATYPE(ScriptValue);
@@ -225,11 +227,12 @@ bool ScriptEngineQtScript::castValueToVariant(const QScriptValue& val, QVariant& · 177 unmodified lines
225227 // do we have a registered handler for this type?
226228 ScriptEngine::DemarshalFunction demarshalFunc = nullptr;
227229 {
228− QMutexLocker guard(&_customTypeProtect);
230+ _customTypeProtect.lockForRead();
229231 CustomMarshalMap::const_iterator lookup = _customTypes.find(destTypeId);
230232 if (lookup != _customTypes.cend()) {
231233 demarshalFunc = lookup.value().demarshalFunc;
232234 }
235+ _customTypeProtect.unlock();
233236 }
234237 if (demarshalFunc) {
235238 dest = QVariant(destTypeId, static_cast<void*>(NULL));
@@ -400,11 +403,12 @@ QScriptValue ScriptEngineQtScript::castVariantToValue(const QVariant& val) { · 164 unmodified lines
400403 // do we have a registered handler for this type?
401404 ScriptEngine::MarshalFunction marshalFunc = nullptr;
402405 {
403− QMutexLocker guard(&_customTypeProtect);
406+ _customTypeProtect.lockForRead();
404407 CustomMarshalMap::const_iterator lookup = _customTypes.find(valTypeId);
405408 if (lookup != _customTypes.cend()) {
406409 marshalFunc = lookup.value().marshalFunc;
407410 }
411+ _customTypeProtect.unlock();
408412 }
409413 if (marshalFunc) {
410414 ScriptValue wrappedVal = marshalFunc(this, val.constData());
@@ -455,11 +459,12 @@ QScriptValue ScriptEngineQtScript::castVariantToValue(const QVariant& val) { · 44 unmodified lines
455459 }
456460 // have we set a prototype'd variant?
457461 {
458− QMutexLocker guard(&_customTypeProtect);
462+ _customTypeProtect.lockForRead();
459463 CustomPrototypeMap::const_iterator lookup = _customPrototypes.find(valTypeId);
460464 if (lookup != _customPrototypes.cend()) {
461465 return ScriptVariantQtProxy::newVariant(this, val, lookup.value());
462466 }
467+ _customTypeProtect.unlock();
463468 }
464469 // just do a generic variant
465470 return QScriptEngine::newVariant(val);

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t