diff options
author | Gabriel de Dietrich <gabriel.dedietrich@qt.io> | 2016-11-22 18:43:28 -0800 |
---|---|---|
committer | Gabriel de Dietrich <gabriel.dedietrich@qt.io> | 2016-12-21 19:15:41 +0000 |
commit | e1113cae9865850bd8f5bc7f1331027e07ce1e49 (patch) | |
tree | f6f6135931ee3541626da59061d5a6502b43bd95 /src/gui/image/qimagewriter.cpp | |
parent | 39e64e798fdf5f6476b4fe863d017ca1b9ff582f (diff) |
QWindowsTheme: Run dedicated SHGetFileInfo() thread
The changes are motivated by the following reasons:
1. SHGetFileInfo() needs to be COM-intialized per thread.
Microsoft's documentation for CoInitalizeEx() is quite
unambiguous about this.
2. Following point 1, using a thread from the global thread
pool means we would taint every such thread with the
COM-initialization state. This may result in unexpected
behavior in other parts of the application. Moreover,
systematic COM-uninitialization can be expensive and
can't be recommended in this case.
3. Even though the timeout duration is pretty generous, the
logic is wrong and could lead to serious errors should
the call to SHGetFileInfo() actually take too long. This
is because we let the thread run with references to the
main thread's stack, namely a reference to the file name
string, and pointers to the result variable and SHFILEINFO
struct.
Running a dedicated thread allows us to ensure points 1
and 2. Point 3 is ensured by making a local copy of the
file name and using local instances for the info struct
and the result. Then, provided the thread has not been
cancelled, we can copy the info and result values back
into the main thread's stack referenced memory areas.
This also removes all need for QWindowsThreadPoolRunner
which will remain in the code base nonetheless.
Change-Id: Ic9c2d6204ac015aa409db2b57a09837361203291
Reviewed-by: Friedemann Kleint <Friedemann.Kleint@qt.io>
Reviewed-by: Andy Shaw <andy.shaw@qt.io>
Diffstat (limited to 'src/gui/image/qimagewriter.cpp')
0 files changed, 0 insertions, 0 deletions