| ... | @@ -1531,9 +1531,9 @@ pub fn ConfigurableTrace(comptime size: usize, comptime stack_frame_count: usize | ... | @@ -1531,9 +1531,9 @@ pub fn ConfigurableTrace(comptime size: usize, comptime stack_frame_count: usize |
| 1531 | } | 1531 | } |
| 1532 | | 1532 | |
| 1533 | pub const SafetyLock = struct { | 1533 | pub const SafetyLock = struct { |
| 1534 | state: State = .unlocked, | 1534 | state: State = if (runtime_safety) .unlocked else .unknown, |
| 1535 | | 1535 | |
| 1536 | pub const State = if (runtime_safety) enum { unlocked, locked } else enum { unlocked }; | 1536 | pub const State = if (runtime_safety) enum { unlocked, locked } else enum { unknown }; |
| 1537 | | 1537 | |
| 1538 | pub fn lock(l: *SafetyLock) void { | 1538 | pub fn lock(l: *SafetyLock) void { |
| 1539 | if (!runtime_safety) return; | 1539 | if (!runtime_safety) return; |
| ... | @@ -1551,8 +1551,22 @@ pub const SafetyLock = struct { | ... | @@ -1551,8 +1551,22 @@ pub const SafetyLock = struct { |
| 1551 | if (!runtime_safety) return; | 1551 | if (!runtime_safety) return; |
| 1552 | assert(l.state == .unlocked); | 1552 | assert(l.state == .unlocked); |
| 1553 | } | 1553 | } |
| | 1554 | |
| | 1555 | pub fn assertLocked(l: SafetyLock) void { |
| | 1556 | if (!runtime_safety) return; |
| | 1557 | assert(l.state == .locked); |
| | 1558 | } |
| 1554 | }; | 1559 | }; |
| 1555 | | 1560 | |
| | 1561 | test SafetyLock { |
| | 1562 | var safety_lock: SafetyLock = .{}; |
| | 1563 | safety_lock.assertUnlocked(); |
| | 1564 | safety_lock.lock(); |
| | 1565 | safety_lock.assertLocked(); |
| | 1566 | safety_lock.unlock(); |
| | 1567 | safety_lock.assertUnlocked(); |
| | 1568 | } |
| | 1569 | |
| 1556 | /// Detect whether the program is being executed in the Valgrind virtual machine. | 1570 | /// Detect whether the program is being executed in the Valgrind virtual machine. |
| 1557 | /// | 1571 | /// |
| 1558 | /// When Valgrind integrations are disabled, this returns comptime-known false. | 1572 | /// When Valgrind integrations are disabled, this returns comptime-known false. |