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
643363d5
Commit
643363d5
authored
Sep 23, 2021
by
Stefane Fermigier
Browse files
Options
Browse Files
Download
Plain Diff
Merge branch '3.0a6-cypclass' of
https://lab.nexedi.com/nexedi/cython
into 3.0a6-cypclass
parents
49a8d8be
0071c4e2
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
34 additions
and
98 deletions
+34
-98
Cython/Includes/libcythonplus/dict.pxd
Cython/Includes/libcythonplus/dict.pxd
+1
-1
Cython/Utility/CyObjects.cpp
Cython/Utility/CyObjects.cpp
+0
-97
tests/run/cypclass_builtin_dict.pyx
tests/run/cypclass_builtin_dict.pyx
+33
-0
No files found.
Cython/Includes/libcythonplus/dict.pxd
View file @
643363d5
...
@@ -167,7 +167,7 @@ cdef cypclass cypdict[K, V]:
...
@@ -167,7 +167,7 @@ cdef cypclass cypdict[K, V]:
index
=
dereference
(
it
).
second
index
=
dereference
(
it
).
second
self
.
_indices
.
erase
(
it
)
self
.
_indices
.
erase
(
it
)
if
index
<
self
.
_items
.
size
()
-
1
:
if
index
<
self
.
_items
.
size
()
-
1
:
self
.
_items
[
index
]
=
self
.
_items
[
self
.
_i
ndice
s
.
size
()
-
1
]
self
.
_items
[
index
]
=
self
.
_items
[
self
.
_i
tem
s
.
size
()
-
1
]
self
.
_items
.
pop_back
()
self
.
_items
.
pop_back
()
void
update
(
self
,
const
cypdict
[
K
,
V
]
other
)
except
~
:
void
update
(
self
,
const
cypdict
[
K
,
V
]
other
)
except
~
:
...
...
Cython/Utility/CyObjects.cpp
View file @
643363d5
...
@@ -19,8 +19,6 @@
...
@@ -19,8 +19,6 @@
#define CyObject_CONTENDING_WRITER_FLAG (1 << 0)
#define CyObject_CONTENDING_WRITER_FLAG (1 << 0)
#define CyObject_CONTENDING_READER_FLAG (1 << 1)
#define CyObject_CONTENDING_READER_FLAG (1 << 1)
#define CyObject_RAISE_ON_CONTENTION 0
#include <atomic>
#include <atomic>
#include <pthread.h>
#include <pthread.h>
...
@@ -37,7 +35,6 @@
...
@@ -37,7 +35,6 @@
#include <type_traits>
#include <type_traits>
class
CyLock
{
class
CyLock
{
static
pthread_mutex_t
log_guard
;
protected:
protected:
pthread_mutex_t
guard
;
pthread_mutex_t
guard
;
pthread_cond_t
readers_have_left
;
pthread_cond_t
readers_have_left
;
...
@@ -67,9 +64,6 @@
...
@@ -67,9 +64,6 @@
int
tryrlock
();
int
tryrlock
();
int
trywlock
();
int
trywlock
();
};
};
#if CyObject_RAISE_ON_CONTENTION == 0
pthread_mutex_t
CyLock
::
log_guard
=
PTHREAD_MUTEX_INITIALIZER
;
#endif
struct
CyPyObject
{
struct
CyPyObject
{
PyObject_HEAD
PyObject_HEAD
...
@@ -724,37 +718,6 @@ void CyLock::rlock(const char *context) {
...
@@ -724,37 +718,6 @@ void CyLock::rlock(const char *context) {
pthread_mutex_lock
(
&
this
->
guard
);
pthread_mutex_lock
(
&
this
->
guard
);
if
(
this
->
write_count
>
0
)
{
#if CyObject_RAISE_ON_CONTENTION
pid_t
owner_id
=
this
->
owner_id
;
std
::
ostringstream
msg
;
msg
<<
"Data Race between [this] reader #"
<<
caller_id
<<
" and [other] writer #"
<<
owner_id
<<
" on lock "
<<
this
;
if
(
context
!=
NULL
)
{
msg
<<
std
::
endl
<<
"In [this] context: "
<<
context
;
}
if
(
this
->
owner_context
!=
NULL
)
{
msg
<<
std
::
endl
<<
"In [other] context: "
<<
this
->
owner_context
;
}
throw
std
::
runtime_error
(
msg
.
str
());
#else
pid_t
owner_id
=
this
->
owner_id
;
pthread_mutex_lock
(
&
(
CyLock
::
log_guard
));
std
::
cerr
<<
"Data Race between [this] reader #"
<<
caller_id
<<
" and [other] writer #"
<<
owner_id
<<
" on lock "
<<
this
<<
std
::
endl
;
if
(
context
!=
NULL
)
{
std
::
cerr
<<
"In [this] context: "
<<
context
<<
std
::
endl
;
}
if
(
this
->
owner_context
!=
NULL
)
{
std
::
cerr
<<
"In [other] context: "
<<
this
->
owner_context
<<
std
::
endl
;
}
pthread_mutex_unlock
(
&
(
CyLock
::
log_guard
));
#endif
}
while
(
this
->
write_count
>
0
)
{
while
(
this
->
write_count
>
0
)
{
pthread_cond_wait
(
&
this
->
writer_has_left
,
&
this
->
guard
);
pthread_cond_wait
(
&
this
->
writer_has_left
,
&
this
->
guard
);
}
}
...
@@ -824,70 +787,10 @@ void CyLock::wlock(const char *context) {
...
@@ -824,70 +787,10 @@ void CyLock::wlock(const char *context) {
// Since we use a reader-preferring approach, we wait first for all readers to leave, and then all writers.
// Since we use a reader-preferring approach, we wait first for all readers to leave, and then all writers.
// The other way around could result in several writers acquiring the lock.
// The other way around could result in several writers acquiring the lock.
if
(
this
->
readers_nb
>
0
)
{
#if CyObject_RAISE_ON_CONTENTION
pid_t
owner_id
=
this
->
owner_id
;
std
::
ostringstream
msg
;
msg
<<
"Data Race between [this] writer #"
<<
caller_id
<<
" and [other] reader #"
<<
owner_id
<<
" on lock "
<<
this
;
if
(
context
!=
NULL
)
{
msg
<<
std
::
endl
<<
"In [this] context: "
<<
context
;
}
if
(
this
->
owner_context
!=
NULL
)
{
msg
<<
std
::
endl
<<
"In [other] context: "
<<
this
->
owner_context
;
}
throw
std
::
runtime_error
(
msg
.
str
());
#else
pthread_mutex_lock
(
&
(
CyLock
::
log_guard
));
std
::
cerr
<<
"Data Race between [this] writer #"
<<
caller_id
<<
" and [other] reader #"
<<
owner_id
<<
" on lock "
<<
this
<<
std
::
endl
;
if
(
context
!=
NULL
)
{
std
::
cerr
<<
"In [this] context: "
<<
context
<<
std
::
endl
;
}
if
(
this
->
owner_context
!=
NULL
)
{
std
::
cerr
<<
"In [other] context: "
<<
this
->
owner_context
<<
std
::
endl
;
}
pthread_mutex_unlock
(
&
(
CyLock
::
log_guard
));
#endif
}
while
(
this
->
readers_nb
>
0
)
{
while
(
this
->
readers_nb
>
0
)
{
pthread_cond_wait
(
&
this
->
readers_have_left
,
&
this
->
guard
);
pthread_cond_wait
(
&
this
->
readers_have_left
,
&
this
->
guard
);
}
}
if
(
this
->
write_count
>
0
)
{
#if CyObject_RAISE_ON_CONTENTION
pid_t
owner_id
=
this
->
owner_id
;
std
::
ostringstream
msg
;
msg
<<
"Data Race between [this] writer #"
<<
caller_id
<<
" and [other] writer #"
<<
owner_id
<<
" on lock "
<<
this
;
if
(
context
!=
NULL
)
{
msg
<<
std
::
endl
<<
"In [this] context: "
<<
context
;
}
if
(
this
->
owner_context
!=
NULL
)
{
msg
<<
std
::
endl
<<
"In [other] context: "
<<
this
->
owner_context
;
}
throw
std
::
runtime_error
(
msg
.
str
());
#else
pthread_mutex_lock
(
&
(
CyLock
::
log_guard
));
std
::
cerr
<<
"Data Race between [this] writer #"
<<
caller_id
<<
" and [other] writer #"
<<
owner_id
<<
" on lock "
<<
this
<<
std
::
endl
;
if
(
context
!=
NULL
)
{
std
::
cerr
<<
"In [this] context: "
<<
context
<<
std
::
endl
;
}
if
(
this
->
owner_context
!=
NULL
)
{
std
::
cerr
<<
"In [other] context: "
<<
this
->
owner_context
<<
std
::
endl
;
}
pthread_mutex_unlock
(
&
(
CyLock
::
log_guard
));
#endif
}
while
(
this
->
write_count
>
0
)
{
while
(
this
->
write_count
>
0
)
{
pthread_cond_wait
(
&
this
->
writer_has_left
,
&
this
->
guard
);
pthread_cond_wait
(
&
this
->
writer_has_left
,
&
this
->
guard
);
}
}
...
...
tests/run/cypclass_builtin_dict.pyx
View file @
643363d5
...
@@ -147,6 +147,39 @@ def test_len():
...
@@ -147,6 +147,39 @@ def test_len():
return
-
2
return
-
2
return
0
return
0
def
test_delitem
():
"""
>>> test_delitem()
(1, 10)
(2, 20)
(3, 30)
(4, 40)
(5, 50)
-------
(1, 10)
(2, 20)
(5, 50)
(4, 40)
-------
(4, 40)
(2, 20)
(5, 50)
"""
d
=
cypdict
[
int
,
int
]()
for
i
in
range
(
1
,
7
):
d
[
i
]
=
i
*
10
del
d
[
6
]
for
item
in
d
.
items
():
print
(
item
)
print
(
"-------"
)
del
d
[
3
]
for
item
in
d
.
items
():
print
(
item
)
print
(
"-------"
)
del
d
[
1
]
for
item
in
d
.
items
():
print
(
item
)
def
test_clear
():
def
test_clear
():
"""
"""
>>> test_clear()
>>> test_clear()
...
...
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