QGeoAreaMonitorPolling: fix connection check logic


QGeoAreaMonitorPolling class overrides QObject::connectNotify() and
QObject::disconnectNotify() to check, if it has any connected objects
and decide, if it needs to start/stop position monitoring.

Previously it used QObject::isSignalConnected() to perform the check.
However this method locks a QObject's mutex, so it's not safe to call
it from QObject::disconnectNotify(), because the latter is called
from a QObject's destructor, which is also locking a QObject's mutex.

Both locks use signalSlotLock static method from qobject.cpp to
determine, which mutex to lock. The selection is made based on the
object's address. At some rare case this can lead to selecting the
same mutex. And as a result we get a deadlock, when trying to lock
the same mutex for the second time.

This patch updates the logic of the overridden methods in
QGeoAreaMonitorPolling. They do not use the
QObject::isSignalConnected() method, but implement a custom solution
to track the number of connections. This solution requires
synchronization, because connectNotify() and disconnectNotify() can
be triggered from different threads.

Fixes: QTBUG-93420
Fixes: QTBUG-91434
Change-Id: I45ba03e238edc136f1bb42ca6b11a528ab5c22e8
Reviewed-by: Alex Blasche <alexander.blasche@qt.io>
commit6cc553b1579f6448e2a2734bbb4348e30b6ff09e
parent668fb8be4396b944e6b0425f8ccbb5e284944c34
authorIvan Solovev <ivan.solovev@qt.io>
committerIvan Solovev <ivan.solovev@qt.io>
commit timeThu, 20 May 2021 13:06:24 +0200