* fix #12726 Cannot take the compile-time sizeof Atomic types * fix for arch 32
This commit is contained in:
parent
a81434a890
commit
826e62953f
2 changed files with 26 additions and 7 deletions
|
|
@ -51,10 +51,11 @@ when defined(cpp) or defined(nimdoc):
|
||||||
## with other moSequentiallyConsistent operations.
|
## with other moSequentiallyConsistent operations.
|
||||||
|
|
||||||
type
|
type
|
||||||
Atomic* {.importcpp: "std::atomic".} [T] = object
|
Atomic*[T] {.importcpp: "std::atomic", completeStruct.} = object
|
||||||
## An atomic object with underlying type `T`.
|
## An atomic object with underlying type `T`.
|
||||||
|
raw: T
|
||||||
|
|
||||||
AtomicFlag* {.importcpp: "std::atomic_flag".} = object
|
AtomicFlag* {.importcpp: "std::atomic_flag", size: 1.} = object
|
||||||
## An atomic boolean state.
|
## An atomic boolean state.
|
||||||
|
|
||||||
# Access operations
|
# Access operations
|
||||||
|
|
@ -249,10 +250,10 @@ else:
|
||||||
type
|
type
|
||||||
# Atomic* {.importcpp: "_Atomic('0)".} [T] = object
|
# Atomic* {.importcpp: "_Atomic('0)".} [T] = object
|
||||||
|
|
||||||
AtomicInt8 {.importc: "_Atomic NI8".} = object
|
AtomicInt8 {.importc: "_Atomic NI8", size: 1.} = object
|
||||||
AtomicInt16 {.importc: "_Atomic NI16".} = object
|
AtomicInt16 {.importc: "_Atomic NI16", size: 2.} = object
|
||||||
AtomicInt32 {.importc: "_Atomic NI32".} = object
|
AtomicInt32 {.importc: "_Atomic NI32", size: 4.} = object
|
||||||
AtomicInt64 {.importc: "_Atomic NI64".} = object
|
AtomicInt64 {.importc: "_Atomic NI64", size: 8.} = object
|
||||||
|
|
||||||
template atomicType*(T: typedesc[Trivial]): untyped =
|
template atomicType*(T: typedesc[Trivial]): untyped =
|
||||||
# Maps the size of a trivial type to it's internal atomic type
|
# Maps the size of a trivial type to it's internal atomic type
|
||||||
|
|
@ -262,7 +263,7 @@ else:
|
||||||
elif sizeof(T) == 8: AtomicInt64
|
elif sizeof(T) == 8: AtomicInt64
|
||||||
|
|
||||||
type
|
type
|
||||||
AtomicFlag* {.importc: "atomic_flag".} = object
|
AtomicFlag* {.importc: "atomic_flag", size: 1.} = object
|
||||||
|
|
||||||
Atomic*[T] = object
|
Atomic*[T] = object
|
||||||
when T is Trivial:
|
when T is Trivial:
|
||||||
|
|
|
||||||
18
tests/stdlib/concurrency/tatomics_size.nim
Normal file
18
tests/stdlib/concurrency/tatomics_size.nim
Normal file
|
|
@ -0,0 +1,18 @@
|
||||||
|
discard """
|
||||||
|
targets: "c cpp"
|
||||||
|
"""
|
||||||
|
import std/atomics
|
||||||
|
|
||||||
|
block testSize: # issue 12726
|
||||||
|
type
|
||||||
|
Node = ptr object
|
||||||
|
# works
|
||||||
|
next: Atomic[pointer]
|
||||||
|
f:AtomicFlag
|
||||||
|
MyChannel = object
|
||||||
|
# type not defined completely
|
||||||
|
back: Atomic[ptr int]
|
||||||
|
f: AtomicFlag
|
||||||
|
static:
|
||||||
|
doAssert sizeof(Node) == sizeof(pointer)
|
||||||
|
doAssert sizeof(MyChannel) == sizeof(pointer) * 2
|
||||||
Loading…
Add table
Add a link
Reference in a new issue