Release a reference and free if this is the last holder. * set *ref to NULL so it can no longer access this obj */
| 95 | * set *ref to NULL so it can no longer access this obj |
| 96 | */ |
| 97 | void put_ref(struct string_ref **ref_p) |
| 98 | { |
| 99 | struct string_ref *ref = *ref_p; |
| 100 | if (ref == NULL) |
| 101 | return; // nothing to do |
| 102 | |
| 103 | int cnt = ATOMIC_ADD32(ref->cnt, -1); |
| 104 | if (cnt < 0) |
| 105 | abort(); |
| 106 | |
| 107 | if (cnt == 0) { |
| 108 | #ifdef TRACK_REFERENCES |
| 109 | Pthread_mutex_lock(&srh_mtx); |
| 110 | int rc = hash_del(sr_hash, ref); |
| 111 | if (rc != 0) { |
| 112 | abort(); |
| 113 | } |
| 114 | gbl_creation_count -= 1; |
| 115 | Pthread_mutex_unlock(&srh_mtx); |
| 116 | #else |
| 117 | ATOMIC_ADD32(gbl_creation_count, -1); |
| 118 | #endif |
| 119 | free(ref); |
| 120 | } |
| 121 | *ref_p = NULL; |
| 122 | } |
| 123 | |
| 124 | |
| 125 | /* Transfer ownership of the reference from pointer 'from' to 'to' |
no test coverage detected