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