Skip to content
This repository was archived by the owner on Oct 12, 2022. It is now read-only.

Commit ad35c91

Browse files
Fix some usages of shared. (#2664)
1 parent 0cbfdbb commit ad35c91

File tree

2 files changed

+6
-3
lines changed

2 files changed

+6
-3
lines changed

src/rt/critical_.d

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,10 @@ extern (C) void _d_critical_init()
2525

2626
extern (C) void _d_critical_term()
2727
{
28-
for (auto p = head; p; p = p.next)
28+
// This function is only ever called by the runtime shutdown code
29+
// and therefore is single threaded so the following cast is fine.
30+
auto h = cast()head;
31+
for (auto p = h; p; p = p.next)
2932
destroyMutex(cast(Mutex*)&p.mtx);
3033
}
3134

src/rt/dmain2.d

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -210,7 +210,7 @@ extern (C) int rt_init()
210210
}
211211
catch (Throwable t)
212212
{
213-
_initCount = 0;
213+
atomicStore!(MemoryOrder.raw)(_initCount, 0);
214214
_d_print_throwable(t);
215215
}
216216
_d_critical_term();
@@ -223,7 +223,7 @@ extern (C) int rt_init()
223223
*/
224224
extern (C) int rt_term()
225225
{
226-
if (!_initCount) return 0; // was never initialized
226+
if (atomicLoad!(MemoryOrder.raw)(_initCount) == 0) return 0; // was never initialized
227227
if (atomicOp!"-="(_initCount, 1)) return 1;
228228

229229
try

0 commit comments

Comments
 (0)