Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
godot
Project
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
community
godot
Commits
124e51fd
Commit
124e51fd
authored
Sep 04, 2019
by
huisedenanhai
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
make core/Reference thread safe
parent
5323d24f
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
16 additions
and
13 deletions
+16
-13
reference.cpp
core/reference.cpp
+8
-10
reference.h
core/reference.h
+1
-1
safe_refcount.h
core/safe_refcount.h
+7
-2
No files found.
core/reference.cpp
View file @
124e51fd
...
...
@@ -36,12 +36,7 @@ bool Reference::init_ref() {
if
(
reference
())
{
// this may fail in the scenario of two threads assigning the pointer for the FIRST TIME
// at the same time, which is never likely to happen (would be crazy to do)
// so don't do it.
if
(
refcount_init
.
get
()
>
0
)
{
refcount_init
.
unref
();
if
(
!
is_referenced
()
&&
refcount_init
.
unref
())
{
unreference
();
// first referencing is already 1, so compensate for the ref above
}
...
...
@@ -64,9 +59,11 @@ int Reference::reference_get_count() const {
}
bool
Reference
::
reference
()
{
bool
success
=
refcount
.
ref
();
if
(
success
&&
refcount
.
get
()
<=
2
/* higher is not relevant */
)
{
uint32_t
rc_val
=
refcount
.
refval
();
bool
success
=
rc_val
!=
0
;
if
(
success
&&
rc_val
<=
2
/* higher is not relevant */
)
{
if
(
get_script_instance
())
{
get_script_instance
()
->
refcount_incremented
();
}
...
...
@@ -84,9 +81,10 @@ bool Reference::reference() {
bool
Reference
::
unreference
()
{
bool
die
=
refcount
.
unref
();
uint32_t
rc_val
=
refcount
.
unrefval
();
bool
die
=
rc_val
==
0
;
if
(
r
efcount
.
get
()
<=
1
/* higher is not relevant */
)
{
if
(
r
c_val
<=
1
/* higher is not relevant */
)
{
if
(
get_script_instance
())
{
bool
script_ret
=
get_script_instance
()
->
refcount_decremented
();
die
=
die
&&
script_ret
;
...
...
core/reference.h
View file @
124e51fd
...
...
@@ -47,7 +47,7 @@ protected:
static
void
_bind_methods
();
public
:
_FORCE_INLINE_
bool
is_referenced
()
const
{
return
refcount_init
.
get
()
<
1
;
}
_FORCE_INLINE_
bool
is_referenced
()
const
{
return
refcount_init
.
get
()
!=
1
;
}
bool
init_ref
();
bool
reference
();
// returns false if refcount is at zero and didn't get increased
bool
unreference
();
...
...
core/safe_refcount.h
View file @
124e51fd
...
...
@@ -177,12 +177,12 @@ struct SafeRefCount {
public
:
// destroy() is called when weak_count_ drops to zero.
_ALWAYS_INLINE_
bool
ref
()
{
//true on success
_ALWAYS_INLINE_
bool
ref
()
{
//
true on success
return
atomic_conditional_increment
(
&
count
)
!=
0
;
}
_ALWAYS_INLINE_
uint32_t
refval
()
{
//
true
on success
_ALWAYS_INLINE_
uint32_t
refval
()
{
//
none-zero
on success
return
atomic_conditional_increment
(
&
count
);
}
...
...
@@ -192,6 +192,11 @@ public:
return
atomic_decrement
(
&
count
)
==
0
;
}
_ALWAYS_INLINE_
uint32_t
unrefval
()
{
// 0 if must be disposed of
return
atomic_decrement
(
&
count
);
}
_ALWAYS_INLINE_
uint32_t
get
()
const
{
// nothrow
return
count
;
...
...
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