|
@@ -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 (refcount.get() <= 1 /* higher is not relevant */) {
|
|
|
+ if (rc_val <= 1 /* higher is not relevant */) {
|
|
|
if (get_script_instance()) {
|
|
|
bool script_ret = get_script_instance()->refcount_decremented();
|
|
|
die = die && script_ret;
|