Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
C
cython
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Labels
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Commits
Open sidebar
nexedi
cython
Commits
ed94b465
Commit
ed94b465
authored
Mar 31, 2020
by
da-woods
Committed by
GitHub
Mar 31, 2020
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Cython header file for C++ `std::atomic` type (GH-3469)
parent
9b4a68fc
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
148 additions
and
0 deletions
+148
-0
Cython/Includes/libcpp/atomic.pxd
Cython/Includes/libcpp/atomic.pxd
+60
-0
tests/run/cpp_stl_atomic.pyx
tests/run/cpp_stl_atomic.pyx
+85
-0
tests/run/libcpp_all.pyx
tests/run/libcpp_all.pyx
+3
-0
No files found.
Cython/Includes/libcpp/atomic.pxd
0 → 100644
View file @
ed94b465
cdef
extern
from
"<atomic>"
namespace
"std"
nogil
:
cdef
enum
memory_order
:
memory_order_relaxed
memory_order_consume
memory_order_acquire
memory_order_release
memory_order_acq_rel
memory_order_seq_cst
cdef
cppclass
atomic
[
T
]:
atomic
()
atomic
(
T
)
bint
is_lock_free
()
void
store
(
T
)
void
store
(
T
,
memory_order
)
T
load
()
T
load
(
memory_order
)
T
exchange
(
T
)
T
exchange
(
T
,
memory_order
)
bint
compare_exchange_weak
(
T
&
,
T
,
memory_order
,
memory_order
)
bint
compare_exchange_weak
(
T
&
,
T
,
memory_order
)
bint
compare_exchange_weak
(
T
&
,
T
)
bint
compare_exchange_strong
(
T
&
,
T
,
memory_order
,
memory_order
)
bint
compare_exchange_strong
(
T
&
,
T
,
memory_order
)
bint
compare_exchange_strong
(
T
&
,
T
)
T
fetch_add
(
T
,
memory_order
)
T
fetch_add
(
T
)
T
fetch_sub
(
T
,
memory_order
)
T
fetch_sub
(
T
)
T
fetch_and
(
T
,
memory_order
)
T
fetch_and
(
T
)
T
fetch_or
(
T
,
memory_order
)
T
fetch_or
(
T
)
T
fetch_xor
(
T
,
memory_order
)
T
fetch_xor
(
T
)
T
operator
++
()
T
operator
++
(
int
)
T
operator
--
()
T
operator
--
(
int
)
# modify-in-place operators not yet supported by Cython:
# T operator+=(T)
# T operator-=(T)
# T operator&=(T)
# T operator|=(T)
# T operator^=(T)
bint
operator
==
(
atomic
[
T
]
&
,
atomic
[
T
]
&
)
bint
operator
==
(
atomic
[
T
]
&
,
T
&
)
bint
operator
==
(
T
&
,
atomic
[
T
]
&
)
bint
operator
!=
(
atomic
[
T
]
&
,
atomic
[
T
]
&
)
bint
operator
!=
(
atomic
[
T
]
&
,
T
&
)
bint
operator
!=
(
T
&
,
atomic
[
T
]
&
)
tests/run/cpp_stl_atomic.pyx
0 → 100644
View file @
ed94b465
# mode: run
# tag: cpp, cpp11, werror
from
cython.operator
cimport
preincrement
as
incr
,
dereference
as
deref
from
libc.stdint
cimport
*
from
libcpp.atomic
cimport
atomic
def
int_test
(
int
x
):
"""
>>> int_test(55)
3
>>> int_test(42)
3
>>> int_test(100000)
3
"""
atom
=
new
atomic
[
int
](
x
)
try
:
atom
.
store
(
0
)
incr
(
deref
(
atom
))
incr
(
deref
(
atom
))
incr
(
deref
(
atom
))
return
atom
.
load
()
finally
:
del
atom
ctypedef
atomic
[
int32_t
]
atomint32_t
def
typedef_test
(
int
x
):
"""
>>> typedef_test(55)
3
>>> typedef_test(42)
3
>>> typedef_test(100000)
3
"""
atom
=
new
atomint32_t
(
x
)
try
:
atom
.
store
(
0
)
incr
(
deref
(
atom
))
incr
(
deref
(
atom
))
incr
(
deref
(
atom
))
return
atom
.
load
()
finally
:
del
atom
def
stack_allocation_test
(
int
x
):
"""
>>> stack_allocation_test(55)
3
>>> stack_allocation_test(42)
3
>>> stack_allocation_test(100000)
3
"""
cdef
atomint32_t
atom
atom
.
store
(
x
)
try
:
atom
.
store
(
0
)
incr
(
atom
)
incr
(
atom
)
incr
(
atom
)
return
atom
.
load
()
finally
:
pass
def
nogil_int_test
(
int
x
):
"""
>>> nogil_int_test(55)
55
>>> nogil_int_test(42)
42
>>> nogil_int_test(100000)
100000
"""
with
nogil
:
atom
=
new
atomic
[
int
](
0
)
try
:
with
nogil
:
atom
.
store
(
x
)
return
atom
.
load
()
finally
:
del
atom
tests/run/libcpp_all.pyx
View file @
ed94b465
...
@@ -4,6 +4,7 @@ import cython
...
@@ -4,6 +4,7 @@ import cython
cimport
libcpp
cimport
libcpp
# cimport libcpp.atomic
cimport
libcpp.deque
cimport
libcpp.deque
cimport
libcpp.list
cimport
libcpp.list
cimport
libcpp.map
cimport
libcpp.map
...
@@ -15,6 +16,7 @@ cimport libcpp.vector
...
@@ -15,6 +16,7 @@ cimport libcpp.vector
cimport
libcpp.complex
cimport
libcpp.complex
cimport
libcpp.limits
cimport
libcpp.limits
# from libcpp.atomic cimport *
from
libcpp.deque
cimport
*
from
libcpp.deque
cimport
*
from
libcpp.list
cimport
*
from
libcpp.list
cimport
*
from
libcpp.map
cimport
*
from
libcpp.map
cimport
*
...
@@ -26,6 +28,7 @@ from libcpp.vector cimport *
...
@@ -26,6 +28,7 @@ from libcpp.vector cimport *
from
libcpp.complex
cimport
*
from
libcpp.complex
cimport
*
from
libcpp.limits
cimport
*
from
libcpp.limits
cimport
*
# cdef libcpp.atomic.atomc[int] a1 = atomic[int]()
cdef
libcpp
.
deque
.
deque
[
int
]
d1
=
deque
[
int
]()
cdef
libcpp
.
deque
.
deque
[
int
]
d1
=
deque
[
int
]()
cdef
libcpp
.
list
.
list
[
int
]
l1
=
list
[
int
]()
cdef
libcpp
.
list
.
list
[
int
]
l1
=
list
[
int
]()
cdef
libcpp
.
map
.
map
[
int
,
int
]
m1
=
map
[
int
,
int
]()
cdef
libcpp
.
map
.
map
[
int
,
int
]
m1
=
map
[
int
,
int
]()
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment