summaryrefslogtreecommitdiffstats
path: root/common/definitions.cpp
diff options
context:
space:
mode:
authorChristian Mollekopf <chrigi_1@fastmail.fm>2017-08-31 13:57:25 -0600
committerChristian Mollekopf <chrigi_1@fastmail.fm>2017-08-31 13:57:25 -0600
commit4a1bcc63cd2919f74f29b41c7b000f80da7449f4 (patch)
treecb213c45c610bff106761bbc0d4117ba6c0f8bd1 /common/definitions.cpp
parentbbf14304d1112882c20f4ad3818712cdfecdedaa (diff)
downloadsink-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.cpp18
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
42static QString sinkLocation(QStandardPaths::StandardLocation location)
43{
44 return QStandardPaths::writableLocation(location) + "/sink";
45}
46
42QString Sink::dataLocation() 47QString 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
52QString Sink::configLocation() 58QString 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
62QString Sink::temporaryFileLocation() 69QString 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);