Commit 42630e4
committed
Use chrono to detect local timezone thread-safely
As discussed in PR #44, the 'time' crate fails timezone detection
in the presence of multiple threads, because the underlying
POSIX function localtime_r is not thread safe.
In order to avoid these thread-safety issues, we use the chrono crate.
It avoids system libraries and reimplements timezone detection from scratch.
Thanks to @yaozongyou for suggesting this fix.
There are two improvements that could be made to reduce dependency bloat:
- Only enable this on unix systems
- Switch to chono entirely.
However, this fix is sufficient to avoid the bug and that is the priority.
It is possible that the optimizer is smart enough to remove all chrono code
except the localtime detection functionality.
In that case, switching from time to chrono could increase bloat
by pulling in two copies of time formatting code.
Tests/benchmarks are needed to determine the best approach.1 parent 8eb6e56 commit 42630e4
3 files changed
+90
-5
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
7 | 7 | | |
8 | 8 | | |
9 | 9 | | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
10 | 15 | | |
11 | 16 | | |
12 | 17 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
31 | 31 | | |
32 | 32 | | |
33 | 33 | | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
34 | 46 | | |
35 | 47 | | |
36 | 48 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1091 | 1091 | | |
1092 | 1092 | | |
1093 | 1093 | | |
| 1094 | + | |
| 1095 | + | |
| 1096 | + | |
| 1097 | + | |
| 1098 | + | |
| 1099 | + | |
| 1100 | + | |
| 1101 | + | |
| 1102 | + | |
| 1103 | + | |
| 1104 | + | |
| 1105 | + | |
| 1106 | + | |
| 1107 | + | |
| 1108 | + | |
| 1109 | + | |
| 1110 | + | |
| 1111 | + | |
| 1112 | + | |
| 1113 | + | |
| 1114 | + | |
| 1115 | + | |
| 1116 | + | |
| 1117 | + | |
| 1118 | + | |
| 1119 | + | |
| 1120 | + | |
1094 | 1121 | | |
1095 | 1122 | | |
1096 | 1123 | | |
| 1124 | + | |
| 1125 | + | |
| 1126 | + | |
| 1127 | + | |
1097 | 1128 | | |
1098 | | - | |
| 1129 | + | |
1099 | 1130 | | |
1100 | 1131 | | |
1101 | 1132 | | |
1102 | 1133 | | |
1103 | | - | |
| 1134 | + | |
1104 | 1135 | | |
1105 | 1136 | | |
1106 | 1137 | | |
| |||
1113 | 1144 | | |
1114 | 1145 | | |
1115 | 1146 | | |
1116 | | - | |
| 1147 | + | |
1117 | 1148 | | |
1118 | 1149 | | |
1119 | | - | |
1120 | | - | |
| 1150 | + | |
| 1151 | + | |
| 1152 | + | |
| 1153 | + | |
| 1154 | + | |
| 1155 | + | |
| 1156 | + | |
| 1157 | + | |
| 1158 | + | |
| 1159 | + | |
| 1160 | + | |
| 1161 | + | |
| 1162 | + | |
| 1163 | + | |
| 1164 | + | |
| 1165 | + | |
| 1166 | + | |
| 1167 | + | |
| 1168 | + | |
| 1169 | + | |
| 1170 | + | |
| 1171 | + | |
| 1172 | + | |
| 1173 | + | |
| 1174 | + | |
| 1175 | + | |
| 1176 | + | |
| 1177 | + | |
| 1178 | + | |
| 1179 | + | |
| 1180 | + | |
| 1181 | + | |
| 1182 | + | |
| 1183 | + | |
| 1184 | + | |
| 1185 | + | |
| 1186 | + | |
| 1187 | + | |
| 1188 | + | |
1121 | 1189 | | |
1122 | 1190 | | |
1123 | 1191 | | |
| |||
0 commit comments