diff options
author | Christian Mollekopf <chrigi_1@fastmail.fm> | 2017-08-31 13:57:25 -0600 |
---|---|---|
committer | Christian Mollekopf <chrigi_1@fastmail.fm> | 2017-08-31 13:57:25 -0600 |
commit | 4a1bcc63cd2919f74f29b41c7b000f80da7449f4 (patch) | |
tree | cb213c45c610bff106761bbc0d4117ba6c0f8bd1 /common/definitions.cpp | |
parent | bbf14304d1112882c20f4ad3818712cdfecdedaa (diff) | |
download | sink-4a1bcc63cd2919f74f29b41c7b000f80da7449f4.tar.gz sink-4a1bcc63cd2919f74f29b41c7b000f80da7449f4.zip |
Avoid non threadsafe initialization.
local static initialization is only threadsafe if initialized on
construction. The other codepath is not threadsafe, but is only used in
testcode.
Diffstat (limited to 'common/definitions.cpp')
-rw-r--r-- | common/definitions.cpp | 18 |
1 files changed, 13 insertions, 5 deletions
diff --git a/common/definitions.cpp b/common/definitions.cpp index 17977bc..ee18d52 100644 --- a/common/definitions.cpp +++ b/common/definitions.cpp | |||
@@ -39,11 +39,17 @@ QString Sink::storageLocation() | |||
39 | return dataLocation() + "/storage"; | 39 | return dataLocation() + "/storage"; |
40 | } | 40 | } |
41 | 41 | ||
42 | static QString sinkLocation(QStandardPaths::StandardLocation location) | ||
43 | { | ||
44 | return QStandardPaths::writableLocation(location) + "/sink"; | ||
45 | } | ||
46 | |||
42 | QString Sink::dataLocation() | 47 | QString Sink::dataLocation() |
43 | { | 48 | { |
44 | static QString location; | 49 | static QString location = sinkLocation(QStandardPaths::GenericDataLocation); |
50 | //Warning: This is not threadsafe, but clearLocationCache is only ever used in testcode. The initialization above is required to make at least the initialization threadsafe (relies on C++11 threadsafe initialization). | ||
45 | if (rereadDataLocation) { | 51 | if (rereadDataLocation) { |
46 | location = QStandardPaths::writableLocation(QStandardPaths::GenericDataLocation) + "/sink"; | 52 | location = sinkLocation(QStandardPaths::GenericDataLocation); |
47 | rereadDataLocation = false; | 53 | rereadDataLocation = false; |
48 | } | 54 | } |
49 | return location; | 55 | return location; |
@@ -51,9 +57,10 @@ QString Sink::dataLocation() | |||
51 | 57 | ||
52 | QString Sink::configLocation() | 58 | QString Sink::configLocation() |
53 | { | 59 | { |
54 | static QString location; | 60 | static QString location = sinkLocation(QStandardPaths::GenericConfigLocation); |
61 | //Warning: This is not threadsafe, but clearLocationCache is only ever used in testcode. The initialization above is required to make at least the initialization threadsafe (relies on C++11 threadsafe initialization). | ||
55 | if (rereadConfigLocation) { | 62 | if (rereadConfigLocation) { |
56 | location = QStandardPaths::writableLocation(QStandardPaths::GenericConfigLocation) + "/sink"; | 63 | location = sinkLocation(QStandardPaths::GenericConfigLocation); |
57 | rereadConfigLocation = false; | 64 | rereadConfigLocation = false; |
58 | } | 65 | } |
59 | return location; | 66 | return location; |
@@ -61,8 +68,9 @@ QString Sink::configLocation() | |||
61 | 68 | ||
62 | QString Sink::temporaryFileLocation() | 69 | QString Sink::temporaryFileLocation() |
63 | { | 70 | { |
64 | static QString location; | 71 | static QString location = dataLocation() + "/temporaryFiles"; |
65 | static bool dirCreated = false; | 72 | static bool dirCreated = false; |
73 | //Warning: This is not threadsafe, but clearLocationCache is only ever used in testcode. The initialization above is required to make at least the initialization threadsafe (relies on C++11 threadsafe initialization). | ||
66 | if (rereadTemporaryFileLocation) { | 74 | if (rereadTemporaryFileLocation) { |
67 | location = dataLocation() + "/temporaryFiles"; | 75 | location = dataLocation() + "/temporaryFiles"; |
68 | dirCreated = QDir{}.mkpath(location); | 76 | dirCreated = QDir{}.mkpath(location); |