Skip to content

Commit

Permalink
runtime: optimize reference counting
Browse files Browse the repository at this point in the history
  • Loading branch information
mertcandav committed Jan 3, 2025
1 parent 49369ea commit ff92c40
Showing 1 changed file with 3 additions and 6 deletions.
9 changes: 3 additions & 6 deletions std/runtime/rc.jule
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,6 @@ type _RCPtr = *_RCType
// per each reference counting operation.
const RCDelta = 1

// Atomic memory ordering for reference counting data.
const _RCMo = atomicSeqCst

// Returns new initialized ready-to-use reference counting data allocation pointer.
#export "__jule_RCNew"
fn _RCNew(): _RCPtr {
Expand Down Expand Up @@ -44,7 +41,7 @@ unsafe fn _RCLoad(p: _RCPtr): _RCType {
// Same as _RCLoad but have thread-safe implementation.
#export "__jule_RCLoadAtomic"
unsafe fn _RCLoadAtomic(p: _RCPtr): _RCType {
ret atomicLoad[_RCType](*p, _RCMo)
ret atomicLoad[_RCType](*p, atomicAcquire)
}

// Adds strong reference to reference pointer.
Expand All @@ -61,7 +58,7 @@ unsafe fn _RCAdd(mut p: _RCPtr) {
// Same as _RCAdd but have thread-safe implementation.
#export "__jule_RCAddAtomic"
unsafe fn _RCAddAtomic(mut p: _RCPtr) {
atomicAdd[_RCType](*p, RCDelta, _RCMo)
atomicAdd[_RCType](*p, RCDelta, atomicRelaxed)
}

// Drops strong reference from reference pointer.
Expand All @@ -83,7 +80,7 @@ unsafe fn _RCDrop(mut p: _RCPtr): bool {
unsafe fn _RCDropAtomic(mut p: _RCPtr): bool {
// The atomicAdd function returns new data of pointer.
// So if new data equals to zero, means references zeroed.
ret atomicAdd[_RCType](*p, -RCDelta, _RCMo) >= RCDelta
ret atomicAdd[_RCType](*p, -RCDelta, atomicAcqRel) >= RCDelta
}

// Deallocates reference counting data allocation.
Expand Down

0 comments on commit ff92c40

Please sign in to comment.