Commit ddbf3004 authored by Xavier Thompson's avatar Xavier Thompson

Improve implementation of cypclass atomic reference counting

parent c1b544f5
...@@ -554,15 +554,19 @@ void LogLock::wlock() { ...@@ -554,15 +554,19 @@ void LogLock::wlock() {
pthread_mutex_unlock(&this->guard); pthread_mutex_unlock(&this->guard);
} }
/*
* Atomic counter increment and decrement implementation based on
* @source: https://www.boost.org/doc/libs/1_73_0/doc/html/atomic/usage_examples.html
*/
void CyObject::CyObject_INCREF() void CyObject::CyObject_INCREF()
{ {
atomic_fetch_add(&(this->nogil_ob_refcnt), 1); this->nogil_ob_refcnt.fetch_add(1, std::memory_order_relaxed);
} }
int CyObject::CyObject_DECREF() int CyObject::CyObject_DECREF()
{ {
if (atomic_fetch_sub(&(this->nogil_ob_refcnt), 1) == 1) { if (this->nogil_ob_refcnt.fetch_sub(1, std::memory_order_release) == 1) {
std::atomic_thread_fence(std::memory_order_acquire);
delete this; delete this;
return 1; return 1;
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment