Backport SMP safe initialisation of QNetworkConfigurationManager
authorShane Kearns <shane.kearns@accenture.com>
Wed, 30 Nov 2011 13:39:23 +0000 (13:39 +0000)
committerShane Kearns <shane.kearns@accenture.com>
Wed, 30 Nov 2011 14:47:43 +0000 (14:47 +0000)
commit67d146092a6c11f1ca3c622ae0737202ca292a58
tree170825dfe25f77557e69b7f77ffba0a442260af4
parent951e46bc21168cb66780f932006ec41b7dfea234
Backport SMP safe initialisation of QNetworkConfigurationManager

The original commit in Qt5 uses new atomics API that is not
in Qt4. I have replaced with equivalent calls.

Also the init/cleanup functions are different, so those are renamed.

Reviewed-by: mread
Task-number: ou1cimx1#946677

Original commit message follows:

Author: Thiago Macieira <thiago@kde.org>
Date:   Wed Jul 6 00:06:15 2011 +0200

    Fix the QNetworkConnectionManagerPrivate initialisation code.

    The current code was meant to be a thread-safe initialisation that
    also ran a couple of extra steps. But it wasn't. While it's ok to call
    qAddPostRoutine(), the call to updateConfigurations() was
    thread-unsafe. It is possible that another thread got the pointer to
    the Private before updateConfigurations() finished.

    So instead protect the initialisation with a mutex.
    It's possible that the value of the pointer becomes visible to
    other processors before the other contained values, so use
    atomics here.

    To call qAddPostRoutine safely from the main thread, use the trick
    of deleteLater() (which is thread-safe) in another thread connecting
    to a slot.
src/network/bearer/qnetworkconfigmanager.cpp
src/network/bearer/qnetworkconfigmanager_p.h