bool ia_css_refcount_is_single(hrt_vaddress ptr) { struct ia_css_refcount_entry *entry; if (ptr == mmgr_NULL) return false; entry = refcount_find_entry(ptr, false); if (entry) return (entry->count == 1); return true; }
hrt_vaddress ia_css_refcount_increment(int32_t id, hrt_vaddress ptr) { struct ia_css_refcount_entry *entry; if (ptr == mmgr_NULL) return ptr; entry = refcount_find_entry(ptr, false); ia_css_debug_dtrace(IA_CSS_DEBUG_TRACE, "ia_css_refcount_increment(%x) 0x%x\n", id, ptr); if (!entry) { entry = refcount_find_entry(ptr, true); assert(entry != NULL); if (entry == NULL) return mmgr_NULL; entry->id = id; } if (entry->id != id) { ia_css_debug_dtrace(IA_CSS_DEBUG_ERROR, "ia_css_refcount_increment(): Ref count IDS do not match!\n"); return mmgr_NULL; } if (entry->data == ptr) entry->count += 1; else if (entry->data == mmgr_NULL) { entry->data = ptr; entry->count = 1; } else return mmgr_NULL; return ptr; }
bool ia_css_refcount_decrement(int32_t id, hrt_vaddress ptr) { struct ia_css_refcount_entry *entry; ia_css_debug_dtrace(IA_CSS_DEBUG_TRACE, "ia_css_refcount_decrement(%x) 0x%x\n", id, ptr); if (ptr == mmgr_NULL) return false; entry = refcount_find_entry(ptr, false); if (entry) { if (entry->id != id) { ia_css_debug_dtrace(IA_CSS_DEBUG_ERROR, "ia_css_refcount_decrement(): Ref count IDS do not match!\n"); return false; } if (entry->count > 0) { entry->count -= 1; if (entry->count == 0) { /* ia_css_debug_dtrace(IA_CSS_DBEUG_TRACE, "ia_css_refcount_decrement: freeing\n");*/ mmgr_free(ptr); entry->data = mmgr_NULL; entry->id = 0; } return true; } } /* SHOULD NOT HAPPEN: ptr not managed by refcount, or not valid anymore */ if (entry) IA_CSS_ERROR("id %x, ptr 0x%x entry %p entry->id %x entry->count %d\n", id, ptr, entry, entry->id, entry->count); else IA_CSS_ERROR("entry NULL for ptr 0x%x\n", ptr); /* assert(false); */ return false; }