Removed deadlock in signal proxy disconnect again

This commit is contained in:
ksuprynowicz 2023-02-26 13:55:22 +01:00
parent 4938a64b73
commit 2579433545
4 changed files with 18 additions and 13 deletions

View file

@ -408,7 +408,8 @@ ScriptEngineV8::ScriptEngineV8(ScriptManager* scriptManager) :
// --jitless - might improve debugging performance due to no JIT? // --jitless - might improve debugging performance due to no JIT?
// --assert-types // --assert-types
v8::V8::SetFlagsFromString("--stack-size=256 --verify-heap"); v8::V8::InitializeICU();
v8::V8::SetFlagsFromString("--stack-size=256 --verify-heap --assert-types");
//v8::V8::SetFlagsFromString("--stack-size=256 --single-threaded"); //v8::V8::SetFlagsFromString("--stack-size=256 --single-threaded");
v8::Platform* platform = getV8Platform(); v8::Platform* platform = getV8Platform();
v8::V8::InitializePlatform(platform); v8::V8::InitializePlatform(platform);

View file

@ -136,7 +136,7 @@ public: // ScriptEngine implementation
QString scriptValueDebugDetailsV8(const V8ScriptValue &value); QString scriptValueDebugDetailsV8(const V8ScriptValue &value);
virtual QString scriptValueDebugListMembers(const ScriptValue &value) override; virtual QString scriptValueDebugListMembers(const ScriptValue &value) override;
QString scriptValueDebugListMembersV8(const V8ScriptValue &v8Value); QString scriptValueDebugListMembersV8(const V8ScriptValue &v8Value);
virtual void logBacktrace(const QString &title) override; virtual void logBacktrace(const QString &title = QString("")) override;
// helper to detect and log warnings when other code invokes QScriptEngine/BaseScriptEngine in thread-unsafe ways // helper to detect and log warnings when other code invokes QScriptEngine/BaseScriptEngine in thread-unsafe ways
inline bool IS_THREADSAFE_INVOCATION(const QString& method) { return ScriptEngine::IS_THREADSAFE_INVOCATION(method); } inline bool IS_THREADSAFE_INVOCATION(const QString& method) { return ScriptEngine::IS_THREADSAFE_INVOCATION(method); }
@ -185,7 +185,9 @@ public: // not for public use, but I don't like how Qt strings this along with p
bool convertJSObjectToVariant(v8::Local<v8::Object> object, QVariant &dest); bool convertJSObjectToVariant(v8::Local<v8::Object> object, QVariant &dest);
V8ScriptValue castVariantToValue(const QVariant& val); V8ScriptValue castVariantToValue(const QVariant& val);
QString valueType(const V8ScriptValue& val); QString valueType(const V8ScriptValue& val);
v8::Isolate* getIsolate() {return _v8Isolate;} v8::Isolate* getIsolate() {
Q_ASSERT(_v8Isolate != nullptr);
return _v8Isolate;}
v8::Local<v8::Context> getContext(); v8::Local<v8::Context> getContext();
const v8::Local<v8::Context> getConstContext() const; const v8::Local<v8::Context> getConstContext() const;
QString formatErrorMessageFromTryCatch(v8::TryCatch &tryCatch); QString formatErrorMessageFromTryCatch(v8::TryCatch &tryCatch);

View file

@ -1186,14 +1186,15 @@ int ScriptSignalV8Proxy::qt_metacall(QMetaObject::Call call, int id, void** argu
args[arg] = _engine->castVariantToValue(argValue).get(); args[arg] = _engine->castVariantToValue(argValue).get();
}*/ }*/
/*QList<Connection> connections; QList<Connection> connections;
withReadLock([&]{ withReadLock([&]{
connections = _connections; connections = _connections;
});*/ });
// V8TODO: this may cause deadlocks on connect/disconnect, so the connect/disconnect procedure needs to be reworked. // V8TODO: this may cause deadlocks on connect/disconnect, so the connect/disconnect procedure needs to be reworked.
// It should probably add events to a separate list that would be processed before and after all the events for the signal. // It should probably add events to a separate list that would be processed before and after all the events for the signal.
withReadLock([&]{ //withReadLock([&]{
{
// V8TODO: check all other lambda functions to make sure they have handle scope - could they cause crashes otherwise? // V8TODO: check all other lambda functions to make sure they have handle scope - could they cause crashes otherwise?
v8::HandleScope handleScope(isolate); v8::HandleScope handleScope(isolate);
// V8TODO: should we use function creation context, or context in which connect happened? // V8TODO: should we use function creation context, or context in which connect happened?
@ -1201,14 +1202,14 @@ int ScriptSignalV8Proxy::qt_metacall(QMetaObject::Call call, int id, void** argu
v8::Context::Scope contextScope(context); v8::Context::Scope contextScope(context);
v8::Local<v8::Value> args[Q_METAMETHOD_INVOKE_MAX_ARGS]; v8::Local<v8::Value> args[Q_METAMETHOD_INVOKE_MAX_ARGS];
int numArgs = _meta.parameterCount(); int numArgs = _meta.parameterCount();
//for (ConnectionList::iterator iter = connections.begin(); iter != connections.end(); ++iter) {
for (int arg = 0; arg < numArgs; ++arg) { for (int arg = 0; arg < numArgs; ++arg) {
int methodArgTypeId = _meta.parameterType(arg); int methodArgTypeId = _meta.parameterType(arg);
Q_ASSERT(methodArgTypeId != QMetaType::UnknownType); Q_ASSERT(methodArgTypeId != QMetaType::UnknownType);
QVariant argValue(methodArgTypeId, arguments[arg+1]); QVariant argValue(methodArgTypeId, arguments[arg + 1]);
args[arg] = _engine->castVariantToValue(argValue).get(); args[arg] = _engine->castVariantToValue(argValue).get();
} }
for (ConnectionList::iterator iter = _connections.begin(); iter != _connections.end(); ++iter) { //for (ConnectionList::iterator iter = _connections.begin(); iter != _connections.end(); ++iter) {
for (ConnectionList::iterator iter = connections.begin(); iter != connections.end(); ++iter) {
Connection& conn = *iter; Connection& conn = *iter;
{ {
/*if (!conn.callback.get()->IsFunction()) { /*if (!conn.callback.get()->IsFunction()) {
@ -1228,7 +1229,7 @@ int ScriptSignalV8Proxy::qt_metacall(QMetaObject::Call call, int id, void** argu
Q_ASSERT(!conn.callback.get().IsEmpty()); Q_ASSERT(!conn.callback.get().IsEmpty());
Q_ASSERT(!conn.callback.get()->IsUndefined()); Q_ASSERT(!conn.callback.get()->IsUndefined());
if(conn.callback.get()->IsNull()) { if (conn.callback.get()->IsNull()) {
qDebug() << "ScriptSignalV8Proxy::qt_metacall: Connection callback is Null"; qDebug() << "ScriptSignalV8Proxy::qt_metacall: Connection callback is Null";
_engine->popContext(); _engine->popContext();
continue; continue;
@ -1258,7 +1259,8 @@ int ScriptSignalV8Proxy::qt_metacall(QMetaObject::Call call, int id, void** argu
//_engine->popContext(); //_engine->popContext();
} }
} }
}); }
//});
_totalCallTime_s += callTimer.elapsed() / 1000.0; _totalCallTime_s += callTimer.elapsed() / 1000.0;

View file

@ -259,7 +259,7 @@ Script.include("/~/system/libraries/controllerDispatcherUtils.js");
// find 3d overlays near each hand // find 3d overlays near each hand
var nearbyOverlayIDs = []; var nearbyOverlayIDs = [];
var h; var h;
for (h = LEFT_HAND; h <= RIGHT_HAND; h++) { /*for (h = LEFT_HAND; h <= RIGHT_HAND; h++) {
if (controllerLocations[h].valid) { if (controllerLocations[h].valid) {
var nearbyOverlays = var nearbyOverlays =
Overlays.findOverlays(controllerLocations[h].position, NEAR_MAX_RADIUS * sensorScaleFactor); Overlays.findOverlays(controllerLocations[h].position, NEAR_MAX_RADIUS * sensorScaleFactor);
@ -293,7 +293,7 @@ Script.include("/~/system/libraries/controllerDispatcherUtils.js");
} else { } else {
nearbyOverlayIDs.push([]); nearbyOverlayIDs.push([]);
} }
} }*/
// find entities near each hand // find entities near each hand
var nearbyEntityProperties = [[], []]; var nearbyEntityProperties = [[], []];