MCPcopy Create free account
hub / github.com/bloomberg/comdb2 / put_ref

Function put_ref

util/string_ref.c:97–122  ·  view source on GitHub ↗

Release a reference and free if this is the last holder. * set *ref to NULL so it can no longer access this obj */

Source from the content-addressed store, hash-verified

95 * set *ref to NULL so it can no longer access this obj
96 */
97void 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'

Callers 12

enqueue_workFunction · 0.85
get_work_llFunction · 0.85
thdpool_thdFunction · 0.85
dohsql_distributeFunction · 0.85
reqlog_free_allFunction · 0.85
reqlog_set_sqlFunction · 0.85
reqlog_long_running_clntFunction · 0.85
sql_statement_doneFunction · 0.85
clear_sqlhistFunction · 0.85
sqlengine_work_appsockFunction · 0.85
enqueue_sql_queryFunction · 0.85
cleanup_clntFunction · 0.85

Calls 2

hash_delFunction · 0.85
freeFunction · 0.85

Tested by

no test coverage detected