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
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Xavier Thompson
cython
Commits
ae8afa92
Commit
ae8afa92
authored
Nov 09, 2020
by
Xavier Thompson
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Integrate cypclass lock implementation directly into CyObject
parent
1b4106fa
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
22 additions
and
68 deletions
+22
-68
Cython/Utility/CyObjects.cpp
Cython/Utility/CyObjects.cpp
+22
-68
No files found.
Cython/Utility/CyObjects.cpp
View file @
ae8afa92
...
...
@@ -20,21 +20,26 @@
using
namespace
std
;
#define CyObject_ATOMIC_REFCOUNT_TYPE atomic_int
#define HAS_WRITER 0xffffffff
#define RETRY_THRESHOLD 100
struct
CyPyObject
{
PyObject_HEAD
};
class
CyLock
{
protected:
const
uint32_t
HAS_WRITER
=
0xffffffff
;
const
int
RETRY_THRESHOLD
=
100
;
std
::
atomic
<
uint32_t
>
_readers
;
class
CyObject
:
public
CyPyObject
{
private:
mutable
std
::
atomic_int
nogil_ob_refcnt
;
mutable
std
::
atomic
<
uint32_t
>
_readers
;
public:
CyLock
()
{
_readers
=
0
;
}
CyObject
()
:
nogil_ob_refcnt
(
1
),
_readers
(
0
)
{}
virtual
~
CyObject
()
{}
void
rlock
()
{
void
CyObject_INCREF
()
const
;
int
CyObject_DECREF
()
const
;
int
CyObject_GETREF
()
const
;
void
CyObject_RLOCK
()
const
{
int
retry
=
0
;
while
(
true
)
{
uint32_t
prev_readers
=
_readers
;
...
...
@@ -53,7 +58,7 @@
}
}
int
tryrlock
()
{
int
CyObject_TRYRLOCK
()
const
{
int
retry
=
0
;
while
(
true
)
{
uint32_t
prev_readers
=
_readers
;
...
...
@@ -73,7 +78,7 @@
}
}
void
unrlock
()
{
void
CyObject_UNRLOCK
()
const
{
int
retry
=
0
;
while
(
true
)
{
uint32_t
prev_readers
=
_readers
;
...
...
@@ -95,7 +100,7 @@
}
}
void
wlock
()
{
void
CyObject_WLOCK
()
const
{
int
retry
=
0
;
while
(
true
)
{
uint32_t
prev_readers
=
_readers
;
...
...
@@ -113,7 +118,7 @@
}
}
int
trywlock
()
{
int
CyObject_TRYWLOCK
()
const
{
uint32_t
prev_readers
=
_readers
;
if
(
prev_readers
==
0
)
{
return
_readers
.
compare_exchange_weak
(
prev_readers
,
HAS_WRITER
)
-
1
;
...
...
@@ -121,34 +126,12 @@
return
-
1
;
}
void
unwlock
()
{
uint32_t
prev_readers
=
HAS_WRITER
;
void
CyObject_UNWLOCK
()
const
{
uint32_t
prev_readers
=
HAS_WRITER
;
_readers
.
compare_exchange_weak
(
prev_readers
,
0
);
}
};
struct
CyPyObject
{
PyObject_HEAD
};
class
CyObject
:
public
CyPyObject
{
private:
mutable
CyObject_ATOMIC_REFCOUNT_TYPE
nogil_ob_refcnt
;
mutable
CyLock
ob_lock
;
public:
CyObject
()
:
nogil_ob_refcnt
(
1
)
{}
virtual
~
CyObject
()
{}
void
CyObject_INCREF
()
const
;
int
CyObject_DECREF
()
const
;
int
CyObject_GETREF
()
const
;
void
CyObject_RLOCK
()
const
;
void
CyObject_WLOCK
()
const
;
void
CyObject_UNRLOCK
()
const
;
void
CyObject_UNWLOCK
()
const
;
int
CyObject_TRYRLOCK
()
const
;
int
CyObject_TRYWLOCK
()
const
;
};
template
<
typename
T
,
typename
=
void
>
struct
Cy_has_equality
:
std
::
false_type
{};
...
...
@@ -616,35 +599,6 @@ int CyObject::CyObject_GETREF() const
return
this
->
nogil_ob_refcnt
;
}
void
CyObject
::
CyObject_RLOCK
()
const
{
this
->
ob_lock
.
rlock
();
}
void
CyObject
::
CyObject_WLOCK
()
const
{
this
->
ob_lock
.
wlock
();
}
int
CyObject
::
CyObject_TRYRLOCK
()
const
{
return
this
->
ob_lock
.
tryrlock
();
}
int
CyObject
::
CyObject_TRYWLOCK
()
const
{
return
this
->
ob_lock
.
trywlock
();
}
void
CyObject
::
CyObject_UNRLOCK
()
const
{
this
->
ob_lock
.
unrlock
();
}
void
CyObject
::
CyObject_UNWLOCK
()
const
{
this
->
ob_lock
.
unwlock
();
}
ActhonMessageInterface
::
ActhonMessageInterface
(
ActhonSyncInterface
*
sync_method
,
ActhonResultInterface
*
result_object
)
:
_sync_method
(
sync_method
),
_result
(
result_object
)
...
...
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