Lines Matching defs:refcnt
2106 idm_refcnt_init(idm_refcnt_t *refcnt, void *referenced_obj)
2108 bzero(refcnt, sizeof (*refcnt));
2109 idm_refcnt_reset(refcnt);
2110 refcnt->ir_referenced_obj = referenced_obj;
2111 bzero(&refcnt->ir_audit_buf, sizeof (refcnt_audit_buf_t));
2112 refcnt->ir_audit_buf.anb_max_index = REFCNT_AUDIT_BUF_MAX_REC - 1;
2113 mutex_init(&refcnt->ir_mutex, NULL, MUTEX_DEFAULT, NULL);
2114 cv_init(&refcnt->ir_cv, NULL, CV_DEFAULT, NULL);
2118 idm_refcnt_destroy(idm_refcnt_t *refcnt)
2123 * the refcnt goes to zero if ir_waiting == REF_WAIT_ASYNC)
2125 mutex_enter(&refcnt->ir_mutex);
2126 ASSERT(refcnt->ir_refcnt == 0);
2127 cv_destroy(&refcnt->ir_cv);
2128 mutex_destroy(&refcnt->ir_mutex);
2132 idm_refcnt_reset(idm_refcnt_t *refcnt)
2134 refcnt->ir_waiting = REF_NOWAIT;
2135 refcnt->ir_refcnt = 0;
2139 idm_refcnt_hold(idm_refcnt_t *refcnt)
2145 ASSERT(refcnt->ir_waiting == REF_NOWAIT);
2147 mutex_enter(&refcnt->ir_mutex);
2148 refcnt->ir_refcnt++;
2149 REFCNT_AUDIT(refcnt);
2150 mutex_exit(&refcnt->ir_mutex);
2156 idm_refcnt_t *refcnt = refcnt_void;
2158 REFCNT_AUDIT(refcnt);
2159 (*refcnt->ir_cb)(refcnt->ir_referenced_obj);
2163 idm_refcnt_rele(idm_refcnt_t *refcnt)
2165 mutex_enter(&refcnt->ir_mutex);
2166 ASSERT(refcnt->ir_refcnt > 0);
2167 refcnt->ir_refcnt--;
2168 REFCNT_AUDIT(refcnt);
2169 if (refcnt->ir_waiting == REF_NOWAIT) {
2171 mutex_exit(&refcnt->ir_mutex);
2177 * refcnt is 0. Waiting on an object then later grabbing another
2180 if (refcnt->ir_refcnt == 0) {
2181 if (refcnt->ir_waiting == REF_WAIT_ASYNC) {
2183 &idm_refcnt_unref_task, refcnt, TQ_SLEEP) == NULL) {
2187 } else if (refcnt->ir_waiting == REF_WAIT_SYNC) {
2188 cv_signal(&refcnt->ir_cv);
2191 mutex_exit(&refcnt->ir_mutex);
2195 idm_refcnt_rele_and_destroy(idm_refcnt_t *refcnt, idm_refcnt_cb_t *cb_func)
2197 mutex_enter(&refcnt->ir_mutex);
2198 ASSERT(refcnt->ir_refcnt > 0);
2199 refcnt->ir_refcnt--;
2200 REFCNT_AUDIT(refcnt);
2204 * refcnt is 0. Waiting on an object then later grabbing another
2207 if (refcnt->ir_refcnt == 0) {
2208 refcnt->ir_cb = cb_func;
2209 refcnt->ir_waiting = REF_WAIT_ASYNC;
2211 &idm_refcnt_unref_task, refcnt, TQ_SLEEP) == NULL) {
2216 mutex_exit(&refcnt->ir_mutex);
2220 idm_refcnt_wait_ref(idm_refcnt_t *refcnt)
2222 mutex_enter(&refcnt->ir_mutex);
2223 refcnt->ir_waiting = REF_WAIT_SYNC;
2224 REFCNT_AUDIT(refcnt);
2225 while (refcnt->ir_refcnt != 0)
2226 cv_wait(&refcnt->ir_cv, &refcnt->ir_mutex);
2227 mutex_exit(&refcnt->ir_mutex);
2231 idm_refcnt_async_wait_ref(idm_refcnt_t *refcnt, idm_refcnt_cb_t *cb_func)
2233 mutex_enter(&refcnt->ir_mutex);
2234 refcnt->ir_waiting = REF_WAIT_ASYNC;
2235 refcnt->ir_cb = cb_func;
2236 REFCNT_AUDIT(refcnt);
2242 if (refcnt->ir_refcnt == 0) {
2244 &idm_refcnt_unref_task, refcnt, TQ_SLEEP) == NULL) {
2250 mutex_exit(&refcnt->ir_mutex);
2254 idm_refcnt_destroy_unref_obj(idm_refcnt_t *refcnt,
2257 mutex_enter(&refcnt->ir_mutex);
2258 if (refcnt->ir_refcnt == 0) {
2259 mutex_exit(&refcnt->ir_mutex);
2260 (*cb_func)(refcnt->ir_referenced_obj);
2263 mutex_exit(&refcnt->ir_mutex);