Lines Matching refs:avl

1196 smb_avl_create(smb_avl_t *avl, size_t size, size_t offset,
1199 ASSERT(avl);
1202 rw_init(&avl->avl_lock, NULL, RW_DEFAULT, NULL);
1203 mutex_init(&avl->avl_mutex, NULL, MUTEX_DEFAULT, NULL);
1205 avl->avl_nops = ops;
1206 avl->avl_state = SMB_AVL_STATE_READY;
1207 avl->avl_refcnt = 0;
1208 (void) random_get_pseudo_bytes((uint8_t *)&avl->avl_sequence,
1211 avl_create(&avl->avl_tree, ops->avln_cmp, size, offset);
1220 smb_avl_destroy(smb_avl_t *avl)
1225 ASSERT(avl);
1227 mutex_enter(&avl->avl_mutex);
1228 if (avl->avl_state != SMB_AVL_STATE_READY) {
1229 mutex_exit(&avl->avl_mutex);
1233 avl->avl_state = SMB_AVL_STATE_DESTROYING;
1235 while (avl->avl_refcnt > 0)
1236 (void) cv_wait(&avl->avl_cv, &avl->avl_mutex);
1237 mutex_exit(&avl->avl_mutex);
1239 rw_enter(&avl->avl_lock, RW_WRITER);
1240 while ((node = avl_destroy_nodes(&avl->avl_tree, &cookie)) != NULL)
1241 avl->avl_nops->avln_destroy(node);
1243 avl_destroy(&avl->avl_tree);
1244 rw_exit(&avl->avl_lock);
1246 rw_destroy(&avl->avl_lock);
1248 mutex_destroy(&avl->avl_mutex);
1249 bzero(avl, sizeof (smb_avl_t));
1262 smb_avl_add(smb_avl_t *avl, void *item)
1266 ASSERT(avl);
1269 if (!smb_avl_hold(avl))
1272 rw_enter(&avl->avl_lock, RW_WRITER);
1273 if (avl_find(&avl->avl_tree, item, &where) != NULL) {
1274 rw_exit(&avl->avl_lock);
1275 smb_avl_rele(avl);
1279 avl_insert(&avl->avl_tree, item, where);
1280 avl->avl_sequence++;
1281 rw_exit(&avl->avl_lock);
1283 smb_avl_rele(avl);
1294 smb_avl_remove(smb_avl_t *avl, void *item)
1299 ASSERT(avl);
1302 if (!smb_avl_hold(avl))
1305 rw_enter(&avl->avl_lock, RW_WRITER);
1306 if ((rm_item = avl_find(&avl->avl_tree, item, &where)) == NULL) {
1307 rw_exit(&avl->avl_lock);
1308 smb_avl_rele(avl);
1312 avl_remove(&avl->avl_tree, rm_item);
1313 if (avl->avl_nops->avln_rele(rm_item))
1314 avl->avl_nops->avln_destroy(rm_item);
1315 avl->avl_sequence++;
1316 rw_exit(&avl->avl_lock);
1318 smb_avl_rele(avl);
1331 smb_avl_lookup(smb_avl_t *avl, void *item)
1335 ASSERT(avl);
1338 if (!smb_avl_hold(avl))
1341 rw_enter(&avl->avl_lock, RW_READER);
1342 node = avl_find(&avl->avl_tree, item, NULL);
1344 avl->avl_nops->avln_hold(node);
1345 rw_exit(&avl->avl_lock);
1348 smb_avl_rele(avl);
1363 smb_avl_release(smb_avl_t *avl, void *item)
1365 ASSERT(avl);
1368 if (avl->avl_nops->avln_rele(item))
1369 avl->avl_nops->avln_destroy(item);
1371 smb_avl_rele(avl);
1379 smb_avl_iterinit(smb_avl_t *avl, smb_avl_cursor_t *cursor)
1381 ASSERT(avl);
1385 cursor->avlc_sequence = avl->avl_sequence;
1402 smb_avl_iterate(smb_avl_t *avl, smb_avl_cursor_t *cursor)
1406 ASSERT(avl);
1409 if (!smb_avl_hold(avl))
1412 rw_enter(&avl->avl_lock, RW_READER);
1413 if (cursor->avlc_sequence != avl->avl_sequence) {
1414 rw_exit(&avl->avl_lock);
1415 smb_avl_rele(avl);
1420 node = avl_first(&avl->avl_tree);
1422 node = AVL_NEXT(&avl->avl_tree, cursor->avlc_next);
1425 avl->avl_nops->avln_hold(node);
1428 rw_exit(&avl->avl_lock);
1431 smb_avl_rele(avl);
1438 * prevent the avl from being destroyed while it's
1442 smb_avl_hold(smb_avl_t *avl)
1444 mutex_enter(&avl->avl_mutex);
1445 if (avl->avl_state != SMB_AVL_STATE_READY) {
1446 mutex_exit(&avl->avl_mutex);
1449 avl->avl_refcnt++;
1450 mutex_exit(&avl->avl_mutex);
1462 smb_avl_rele(smb_avl_t *avl)
1464 mutex_enter(&avl->avl_mutex);
1465 ASSERT(avl->avl_refcnt > 0);
1466 avl->avl_refcnt--;
1467 if (avl->avl_state == SMB_AVL_STATE_DESTROYING)
1468 cv_broadcast(&avl->avl_cv);
1469 mutex_exit(&avl->avl_mutex);