/usr/lib/gcc/x86_64-linux-gnu/6/include/d/rt/critical_.d is in libgphobos-6-dev 6.4.0-17ubuntu1.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 | /**
* Implementation of support routines for synchronized blocks.
*
* Copyright: Copyright Digital Mars 2000 - 2011.
* License: $(WEB www.boost.org/LICENSE_1_0.txt, Boost License 1.0).
* Authors: Walter Bright, Sean Kelly
*/
/* Copyright Digital Mars 2000 - 2011.
* Distributed under the Boost Software License, Version 1.0.
* (See accompanying file LICENSE or copy at
* http://www.boost.org/LICENSE_1_0.txt)
*/
module rt.critical_;
nothrow:
import rt.monitor_, core.atomic;
extern (C) void _d_critical_init()
{
initMutex(cast(Mutex*)&gcs.mtx);
head = &gcs;
}
extern (C) void _d_critical_term()
{
for (auto p = head; p; p = p.next)
destroyMutex(cast(Mutex*)&p.mtx);
}
extern (C) void _d_criticalenter(D_CRITICAL_SECTION* cs)
{
ensureMutex(cast(shared(D_CRITICAL_SECTION*)) cs);
lockMutex(&cs.mtx);
}
extern (C) void _d_criticalexit(D_CRITICAL_SECTION* cs)
{
unlockMutex(&cs.mtx);
}
private:
shared D_CRITICAL_SECTION* head;
shared D_CRITICAL_SECTION gcs;
struct D_CRITICAL_SECTION
{
D_CRITICAL_SECTION* next;
Mutex mtx;
}
void ensureMutex(shared(D_CRITICAL_SECTION)* cs)
{
if (atomicLoad!(MemoryOrder.acq)(cs.next) is null)
{
lockMutex(cast(Mutex*)&gcs.mtx);
if (atomicLoad!(MemoryOrder.raw)(cs.next) is null)
{
initMutex(cast(Mutex*)&cs.mtx);
auto ohead = head;
head = cs;
atomicStore!(MemoryOrder.rel)(cs.next, ohead);
}
unlockMutex(cast(Mutex*)&gcs.mtx);
}
}
|