Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 7 additions & 5 deletions Objects/cownobject.c
Original file line number Diff line number Diff line change
Expand Up @@ -618,7 +618,7 @@ int _PyCown_AcquireGC(_PyCownObject *self, Py_region_t *region) {

// The cown was snatched up by something else. This is fine for
// the GC
if (res != COWN_ACQUIRE_FAIL) {
if (res == COWN_ACQUIRE_FAIL) {
return 0;
}
assert(res == COWN_ACQUIRE_SUCCESS);
Expand All @@ -633,7 +633,7 @@ int _PyCown_SwitchFromGcToIp(_PyCownObject *self) {

_PyCown_ipid_t ipid = _PyCown_ThisInterpreterId();
_PyCown_ipid_t gcid = GC_IPID;
if (_Py_atomic_compare_exchange_uint64(&self->owning_ip, &gcid, ipid)) {
if (!_Py_atomic_compare_exchange_uint64(&self->owning_ip, &gcid, ipid)) {
return -1;
}

Expand All @@ -653,12 +653,12 @@ int _PyCown_SwitchFromIpToGc(_PyCownObject *self, Py_region_t *contained_region)
BAIL_UNLESS_OWNED_BY(self, ipid, -1);

PyObject *value = self->value;
Py_region_t value_region = _PyRegion_Get(value);
*contained_region = value_region;

// Cowns holding cowns or immutable objects can be released without any
// restrictions
Py_region_t value_region = _PyRegion_Get(value);
if (value_region == _Py_COWN_REGION || value_region == _Py_IMMUTABLE_REGION) {
*contained_region = value_region;
return cown_release_unchecked(self, ipid);
}

Expand All @@ -675,10 +675,12 @@ int _PyCown_SwitchFromIpToGc(_PyCownObject *self, Py_region_t *contained_region)

// A closed region is safe to release
if (_PyRegion_IsOpen(_PyRegion_Get(self->value))) {
*contained_region = NULL_REGION;
return 1;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
return 1;
*contained_region = NULL_REGION;
return 1;

}

if (_Py_atomic_compare_exchange_uint64(&self->owning_ip, &ipid, GC_IPID)) {
if (!_Py_atomic_compare_exchange_uint64(&self->owning_ip, &ipid, GC_IPID)) {
*contained_region = NULL_REGION;
return -1;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
return -1;
*contained_region = NULL_REGION;
return -1;

}
return 0;
Expand Down
Loading