Commit 53d4641c05893ca205e409dcf121160335c8fc06
Merge pull request #263 from biometrics/download_nam_fix
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,7 +106,13 @@ public: | ||
| 106 | private: | 106 | private: |
| 107 | BR_PROPERTY(Mode, mode, Encoded) | 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 | void project(const Template &src, Template &dst) const | 117 | void project(const Template &src, Template &dst) const |
| 112 | { | 118 | { |
| @@ -165,6 +171,7 @@ private: | @@ -165,6 +171,7 @@ private: | ||
| 165 | } | 171 | } |
| 166 | } | 172 | } |
| 167 | }; | 173 | }; |
| 174 | +QThreadStorage<QNetworkAccessManager*> DownloadTransform::nam; | ||
| 168 | 175 | ||
| 169 | BR_REGISTER(Transform, DownloadTransform) | 176 | BR_REGISTER(Transform, DownloadTransform) |
| 170 | 177 |