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

Commit 70e0ad3

Browse files
authored
Merge pull request #2773 from ErnyTech/master
Fix Issue 13826 - Move volatileLoad/Store to core.volatile when the volatile keyword is removed merged-on-behalf-of: Petar Kirov <ZombineDev@users.noreply.github.com>
2 parents 4b1c5bd + bc1ef74 commit 70e0ad3

File tree

6 files changed

+79
-49
lines changed

6 files changed

+79
-49
lines changed

mak/COPY

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ COPY=\
2020
$(IMPDIR)\core\thread.d \
2121
$(IMPDIR)\core\time.d \
2222
$(IMPDIR)\core\vararg.d \
23+
$(IMPDIR)\core\volatile.d \
2324
\
2425
$(IMPDIR)\core\internal\abort.d \
2526
$(IMPDIR)\core\internal\atomic.d \

mak/DOCS

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ DOCS=\
1515
$(DOCDIR)\core_thread.html \
1616
$(DOCDIR)\core_time.html \
1717
$(DOCDIR)\core_vararg.html \
18+
$(DOCDIR)\core_volatile.html \
1819
\
1920
$(DOCDIR)\core_gc_config.html \
2021
$(DOCDIR)\core_gc_gcinterface.html \

mak/SRCS

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ SRCS=\
1616
src\core\thread.d \
1717
src\core\time.d \
1818
src\core\vararg.d \
19+
src\core\volatile.d \
1920
\
2021
src\core\gc\config.d \
2122
src\core\gc\gcinterface.d \

mak/WINDOWS

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,9 @@ $(IMPDIR)\core\time.d : src\core\time.d
108108
$(IMPDIR)\core\vararg.d : src\core\vararg.d
109109
copy $** $@
110110

111+
$(IMPDIR)\core\volatile.d : src\core\volatile.d
112+
copy $** $@
113+
111114
$(IMPDIR)\core\gc\config.d : src\core\gc\config.d
112115
copy $** $@
113116

src/core/bitop.d

Lines changed: 6 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -722,57 +722,14 @@ version (DigitalMars) version (AnyX86)
722722
}
723723

724724

725-
/*************************************
726-
* Read/write value from/to the memory location indicated by ptr.
727-
*
728-
* These functions are recognized by the compiler, and calls to them are guaranteed
729-
* to not be removed (as dead assignment elimination or presumed to have no effect)
730-
* or reordered in the same thread.
731-
*
732-
* These reordering guarantees are only made with regards to other
733-
* operations done through these functions; the compiler is free to reorder regular
734-
* loads/stores with regards to loads/stores done through these functions.
735-
*
736-
* This is useful when dealing with memory-mapped I/O (MMIO) where a store can
737-
* have an effect other than just writing a value, or where sequential loads
738-
* with no intervening stores can retrieve
739-
* different values from the same location due to external stores to the location.
740-
*
741-
* These functions will, when possible, do the load/store as a single operation. In
742-
* general, this is possible when the size of the operation is less than or equal to
743-
* $(D (void*).sizeof), although some targets may support larger operations. If the
744-
* load/store cannot be done as a single operation, multiple smaller operations will be used.
745-
*
746-
* These are not to be conflated with atomic operations. They do not guarantee any
747-
* atomicity. This may be provided by coincidence as a result of the instructions
748-
* used on the target, but this should not be relied on for portable programs.
749-
* Further, no memory fences are implied by these functions.
750-
* They should not be used for communication between threads.
751-
* They may be used to guarantee a write or read cycle occurs at a specified address.
752-
*/
753-
754-
ubyte volatileLoad(ubyte * ptr);
755-
ushort volatileLoad(ushort* ptr); /// ditto
756-
uint volatileLoad(uint * ptr); /// ditto
757-
ulong volatileLoad(ulong * ptr); /// ditto
758-
759-
void volatileStore(ubyte * ptr, ubyte value); /// ditto
760-
void volatileStore(ushort* ptr, ushort value); /// ditto
761-
void volatileStore(uint * ptr, uint value); /// ditto
762-
void volatileStore(ulong * ptr, ulong value); /// ditto
763-
764-
@system unittest
725+
deprecated("volatileLoad has been moved to core.volatile. Use core.volatile.volatileLoad instead.")
765726
{
766-
alias TT(T...) = T;
727+
public import core.volatile : volatileLoad;
728+
}
767729

768-
foreach (T; TT!(ubyte, ushort, uint, ulong))
769-
{
770-
T u;
771-
T* p = &u;
772-
volatileStore(p, 1);
773-
T r = volatileLoad(p);
774-
assert(r == u);
775-
}
730+
deprecated("volatileStore has been moved to core.volatile. Use core.volatile.volatileStore instead.")
731+
{
732+
public import core.volatile : volatileStore;
776733
}
777734

778735

src/core/volatile.d

Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
/**
2+
* This module declares intrinsics for volatile operations.
3+
*
4+
* Copyright: Copyright © 2019, The D Language Foundation
5+
* License: $(LINK2 http://www.boost.org/LICENSE_1_0.txt, Boost License 1.0)
6+
* Authors: Walter Bright, Ernesto Castellotti
7+
* Source: $(DRUNTIMESRC core/volatile.d)
8+
*/
9+
10+
module core.volatile;
11+
12+
nothrow:
13+
@safe:
14+
@nogc:
15+
16+
/*************************************
17+
* Read/write value from/to the memory location indicated by ptr.
18+
*
19+
* These functions are recognized by the compiler, and calls to them are guaranteed
20+
* to not be removed (as dead assignment elimination or presumed to have no effect)
21+
* or reordered in the same thread.
22+
*
23+
* These reordering guarantees are only made with regards to other
24+
* operations done through these functions; the compiler is free to reorder regular
25+
* loads/stores with regards to loads/stores done through these functions.
26+
*
27+
* This is useful when dealing with memory-mapped I/O (MMIO) where a store can
28+
* have an effect other than just writing a value, or where sequential loads
29+
* with no intervening stores can retrieve
30+
* different values from the same location due to external stores to the location.
31+
*
32+
* These functions will, when possible, do the load/store as a single operation. In
33+
* general, this is possible when the size of the operation is less than or equal to
34+
* $(D (void*).sizeof), although some targets may support larger operations. If the
35+
* load/store cannot be done as a single operation, multiple smaller operations will be used.
36+
*
37+
* These are not to be conflated with atomic operations. They do not guarantee any
38+
* atomicity. This may be provided by coincidence as a result of the instructions
39+
* used on the target, but this should not be relied on for portable programs.
40+
* Further, no memory fences are implied by these functions.
41+
* They should not be used for communication between threads.
42+
* They may be used to guarantee a write or read cycle occurs at a specified address.
43+
*/
44+
45+
ubyte volatileLoad(ubyte * ptr);
46+
ushort volatileLoad(ushort* ptr); /// ditto
47+
uint volatileLoad(uint * ptr); /// ditto
48+
ulong volatileLoad(ulong * ptr); /// ditto
49+
50+
void volatileStore(ubyte * ptr, ubyte value); /// ditto
51+
void volatileStore(ushort* ptr, ushort value); /// ditto
52+
void volatileStore(uint * ptr, uint value); /// ditto
53+
void volatileStore(ulong * ptr, ulong value); /// ditto
54+
55+
@system unittest
56+
{
57+
alias TT(T...) = T;
58+
59+
foreach (T; TT!(ubyte, ushort, uint, ulong))
60+
{
61+
T u;
62+
T* p = &u;
63+
volatileStore(p, 1);
64+
T r = volatileLoad(p);
65+
assert(r == u);
66+
}
67+
}

0 commit comments

Comments
 (0)