Commit 084320d256b3a7c600c3635d1c1f3b7cbcd0710a

Authored by Josh Klontz
1 parent 4fe4b46a

Fixed and documented the use of DownloadTransform::nam

Showing 1 changed file with 8 additions and 1 deletions
openbr/plugins/misc.cpp
... ... @@ -106,7 +106,13 @@ public:
106 106 private:
107 107 BR_PROPERTY(Mode, mode, Encoded)
108 108  
109   - mutable QThreadStorage<QNetworkAccessManager*> nam;
  109 + // The reasons for this data structure are as follows:
  110 + // 1) The QNetworkAccessManager must be used in the thread that _created_ it,
  111 + // hence the use of `QThreadStorage`.
  112 + // 2) The QThreadStorage must be deleted _after_ the threads that added QNetworkAccessManager
  113 + // to it are deleted, hence the `static` ensuring that `nam` is deleted at program termination,
  114 + // long after the threads that created QNetworkAccessManager are deleted.
  115 + static QThreadStorage<QNetworkAccessManager*> nam;
110 116  
111 117 void project(const Template &src, Template &dst) const
112 118 {
... ... @@ -165,6 +171,7 @@ private:
165 171 }
166 172 }
167 173 };
  174 +QThreadStorage<QNetworkAccessManager*> DownloadTransform::nam;
168 175  
169 176 BR_REGISTER(Transform, DownloadTransform)
170 177  
... ...