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
10d4601e
Commit
10d4601e
authored
Sep 10, 2020
by
Xavier Thompson
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Allow refcounting and lock operations to occur on const Cybjects
parent
5326aee8
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
24 additions
and
24 deletions
+24
-24
Cython/Utility/CyObjects.cpp
Cython/Utility/CyObjects.cpp
+24
-24
No files found.
Cython/Utility/CyObjects.cpp
View file @
10d4601e
...
@@ -76,20 +76,20 @@
...
@@ -76,20 +76,20 @@
class
CyObject
:
public
CyPyObject
{
class
CyObject
:
public
CyPyObject
{
private:
private:
CyObject_ATOMIC_REFCOUNT_TYPE
nogil_ob_refcnt
;
mutable
CyObject_ATOMIC_REFCOUNT_TYPE
nogil_ob_refcnt
;
CyLock
ob_lock
;
mutable
CyLock
ob_lock
;
public:
public:
CyObject
()
:
nogil_ob_refcnt
(
1
)
{}
CyObject
()
:
nogil_ob_refcnt
(
1
)
{}
virtual
~
CyObject
()
{}
virtual
~
CyObject
()
{}
void
CyObject_INCREF
();
void
CyObject_INCREF
()
const
;
int
CyObject_DECREF
();
int
CyObject_DECREF
()
const
;
int
CyObject_GETREF
();
int
CyObject_GETREF
()
const
;
void
CyObject_RLOCK
(
const
char
*
context
);
void
CyObject_RLOCK
(
const
char
*
context
)
const
;
void
CyObject_WLOCK
(
const
char
*
context
);
void
CyObject_WLOCK
(
const
char
*
context
)
const
;
void
CyObject_UNRLOCK
();
void
CyObject_UNRLOCK
()
const
;
void
CyObject_UNWLOCK
();
void
CyObject_UNWLOCK
()
const
;
int
CyObject_TRYRLOCK
();
int
CyObject_TRYRLOCK
()
const
;
int
CyObject_TRYWLOCK
();
int
CyObject_TRYWLOCK
()
const
;
};
};
template
<
typename
T
,
typename
=
void
>
template
<
typename
T
,
typename
=
void
>
...
@@ -291,9 +291,9 @@
...
@@ -291,9 +291,9 @@
using
Cy_Raw
=
typename
Cy_Raw_t
<
T
>::
type
;
using
Cy_Raw
=
typename
Cy_Raw_t
<
T
>::
type
;
class
Cy_rlock_guard
{
class
Cy_rlock_guard
{
CyObject
*
o
;
const
CyObject
*
o
;
public:
public:
Cy_rlock_guard
(
CyObject
*
o
,
const
char
*
context
)
:
o
(
o
)
{
Cy_rlock_guard
(
const
CyObject
*
o
,
const
char
*
context
)
:
o
(
o
)
{
if
(
o
!=
NULL
)
{
if
(
o
!=
NULL
)
{
o
->
CyObject_RLOCK
(
context
);
o
->
CyObject_RLOCK
(
context
);
}
}
...
@@ -312,9 +312,9 @@
...
@@ -312,9 +312,9 @@
};
};
class
Cy_wlock_guard
{
class
Cy_wlock_guard
{
CyObject
*
o
;
const
CyObject
*
o
;
public:
public:
Cy_wlock_guard
(
CyObject
*
o
,
const
char
*
context
)
:
o
(
o
)
{
Cy_wlock_guard
(
const
CyObject
*
o
,
const
char
*
context
)
:
o
(
o
)
{
if
(
o
!=
NULL
)
{
if
(
o
!=
NULL
)
{
o
->
CyObject_WLOCK
(
context
);
o
->
CyObject_WLOCK
(
context
);
}
}
...
@@ -786,12 +786,12 @@ void CyLock::unwlock() {
...
@@ -786,12 +786,12 @@ void CyLock::unwlock() {
* Atomic counter increment and decrement implementation based on
* Atomic counter increment and decrement implementation based on
* @source: https://www.boost.org/doc/libs/1_73_0/doc/html/atomic/usage_examples.html
* @source: https://www.boost.org/doc/libs/1_73_0/doc/html/atomic/usage_examples.html
*/
*/
void
CyObject
::
CyObject_INCREF
()
void
CyObject
::
CyObject_INCREF
()
const
{
{
this
->
nogil_ob_refcnt
.
fetch_add
(
1
,
std
::
memory_order_relaxed
);
this
->
nogil_ob_refcnt
.
fetch_add
(
1
,
std
::
memory_order_relaxed
);
}
}
int
CyObject
::
CyObject_DECREF
()
int
CyObject
::
CyObject_DECREF
()
const
{
{
if
(
this
->
nogil_ob_refcnt
.
fetch_sub
(
1
,
std
::
memory_order_release
)
==
1
)
{
if
(
this
->
nogil_ob_refcnt
.
fetch_sub
(
1
,
std
::
memory_order_release
)
==
1
)
{
std
::
atomic_thread_fence
(
std
::
memory_order_acquire
);
std
::
atomic_thread_fence
(
std
::
memory_order_acquire
);
...
@@ -801,36 +801,36 @@ int CyObject::CyObject_DECREF()
...
@@ -801,36 +801,36 @@ int CyObject::CyObject_DECREF()
return
0
;
return
0
;
}
}
int
CyObject
::
CyObject_GETREF
()
int
CyObject
::
CyObject_GETREF
()
const
{
{
return
this
->
nogil_ob_refcnt
;
return
this
->
nogil_ob_refcnt
;
}
}
void
CyObject
::
CyObject_RLOCK
(
const
char
*
context
)
void
CyObject
::
CyObject_RLOCK
(
const
char
*
context
)
const
{
{
this
->
ob_lock
.
rlock
(
context
);
this
->
ob_lock
.
rlock
(
context
);
}
}
void
CyObject
::
CyObject_WLOCK
(
const
char
*
context
)
void
CyObject
::
CyObject_WLOCK
(
const
char
*
context
)
const
{
{
this
->
ob_lock
.
wlock
(
context
);
this
->
ob_lock
.
wlock
(
context
);
}
}
int
CyObject
::
CyObject_TRYRLOCK
()
int
CyObject
::
CyObject_TRYRLOCK
()
const
{
{
return
this
->
ob_lock
.
tryrlock
();
return
this
->
ob_lock
.
tryrlock
();
}
}
int
CyObject
::
CyObject_TRYWLOCK
()
int
CyObject
::
CyObject_TRYWLOCK
()
const
{
{
return
this
->
ob_lock
.
trywlock
();
return
this
->
ob_lock
.
trywlock
();
}
}
void
CyObject
::
CyObject_UNRLOCK
()
void
CyObject
::
CyObject_UNRLOCK
()
const
{
{
this
->
ob_lock
.
unrlock
();
this
->
ob_lock
.
unrlock
();
}
}
void
CyObject
::
CyObject_UNWLOCK
()
void
CyObject
::
CyObject_UNWLOCK
()
const
{
{
this
->
ob_lock
.
unwlock
();
this
->
ob_lock
.
unwlock
();
}
}
...
...
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