Print this page
5045 use atomic_{inc,dec}_* instead of atomic_add_*


 391         mutex_init(lhp->lh_lock, NULL, MUTEX_DEFAULT, NULL);
 392 #endif
 393 
 394         /* set the device type for this handle */
 395         lhp->lh_type = 0;
 396         if (vp->v_stream) {
 397                 ASSERT(vp->v_type == VCHR);
 398                 lhp->lh_type |= LH_STREAM;
 399         } else {
 400                 lhp->lh_type |= LH_CBDEV;
 401         }
 402 
 403         /* get holds on other objects */
 404         ident_hold(ident);
 405         ASSERT(vp->v_count >= 1);
 406         VN_HOLD(vp);
 407 
 408         /* add it to the handle hash */
 409         lhp->lh_next = ldi_handle_hash[index];
 410         ldi_handle_hash[index] = lhp;
 411         atomic_add_long(&ldi_handle_hash_count, 1);
 412 
 413         LDI_ALLOCFREE((CE_WARN, "ldi handle alloc: new "
 414             "lh=0x%p, ident=0x%p, vp=0x%p, drv=%s, minor=0x%x",
 415             (void *)lhp, (void *)ident, (void *)vp,
 416             mod_major_to_name(getmajor(vp->v_rdev)),
 417             getminor(vp->v_rdev)));
 418 
 419         mutex_exit(&ldi_handle_hash_lock[index]);
 420         return (lhp);
 421 }
 422 
 423 static void
 424 handle_release(struct ldi_handle *lhp)
 425 {
 426         struct ldi_handle       **lhpp;
 427         uint_t                  index;
 428 
 429         ASSERT(lhp != NULL);
 430 
 431         index = LH_HASH(lhp->lh_vp);
 432         mutex_enter(&ldi_handle_hash_lock[index]);
 433 
 434         LDI_ALLOCFREE((CE_WARN, "ldi handle release: "
 435             "lh=0x%p, ident=0x%p, vp=0x%p, drv=%s, minor=0x%x",
 436             (void *)lhp, (void *)lhp->lh_ident, (void *)lhp->lh_vp,
 437             mod_major_to_name(getmajor(lhp->lh_vp->v_rdev)),
 438             getminor(lhp->lh_vp->v_rdev)));
 439 
 440         ASSERT(lhp->lh_ref > 0);
 441         if (--lhp->lh_ref > 0) {
 442                 /* there are more references to this handle */
 443                 mutex_exit(&ldi_handle_hash_lock[index]);
 444                 return;
 445         }
 446 
 447         /* this was the last reference/open for this handle.  free it. */
 448         lhpp = handle_find_ref_nolock(lhp->lh_vp, lhp->lh_ident);
 449         ASSERT((lhpp != NULL) && (*lhpp != NULL));
 450         *lhpp = lhp->lh_next;
 451         atomic_add_long(&ldi_handle_hash_count, -1);
 452         mutex_exit(&ldi_handle_hash_lock[index]);
 453 
 454         VN_RELE(lhp->lh_vp);
 455         ident_release(lhp->lh_ident);
 456 #ifdef  LDI_OBSOLETE_EVENT
 457         mutex_destroy(lhp->lh_lock);
 458 #endif
 459         kmem_free(lhp, sizeof (struct ldi_handle));
 460 }
 461 
 462 #ifdef  LDI_OBSOLETE_EVENT
 463 /*
 464  * LDI event manipulation functions
 465  */
 466 static void
 467 handle_event_add(ldi_event_t *lep)
 468 {
 469         struct ldi_handle *lhp = lep->le_lhp;
 470 
 471         ASSERT(lhp != NULL);




 391         mutex_init(lhp->lh_lock, NULL, MUTEX_DEFAULT, NULL);
 392 #endif
 393 
 394         /* set the device type for this handle */
 395         lhp->lh_type = 0;
 396         if (vp->v_stream) {
 397                 ASSERT(vp->v_type == VCHR);
 398                 lhp->lh_type |= LH_STREAM;
 399         } else {
 400                 lhp->lh_type |= LH_CBDEV;
 401         }
 402 
 403         /* get holds on other objects */
 404         ident_hold(ident);
 405         ASSERT(vp->v_count >= 1);
 406         VN_HOLD(vp);
 407 
 408         /* add it to the handle hash */
 409         lhp->lh_next = ldi_handle_hash[index];
 410         ldi_handle_hash[index] = lhp;
 411         atomic_inc_ulong(&ldi_handle_hash_count);
 412 
 413         LDI_ALLOCFREE((CE_WARN, "ldi handle alloc: new "
 414             "lh=0x%p, ident=0x%p, vp=0x%p, drv=%s, minor=0x%x",
 415             (void *)lhp, (void *)ident, (void *)vp,
 416             mod_major_to_name(getmajor(vp->v_rdev)),
 417             getminor(vp->v_rdev)));
 418 
 419         mutex_exit(&ldi_handle_hash_lock[index]);
 420         return (lhp);
 421 }
 422 
 423 static void
 424 handle_release(struct ldi_handle *lhp)
 425 {
 426         struct ldi_handle       **lhpp;
 427         uint_t                  index;
 428 
 429         ASSERT(lhp != NULL);
 430 
 431         index = LH_HASH(lhp->lh_vp);
 432         mutex_enter(&ldi_handle_hash_lock[index]);
 433 
 434         LDI_ALLOCFREE((CE_WARN, "ldi handle release: "
 435             "lh=0x%p, ident=0x%p, vp=0x%p, drv=%s, minor=0x%x",
 436             (void *)lhp, (void *)lhp->lh_ident, (void *)lhp->lh_vp,
 437             mod_major_to_name(getmajor(lhp->lh_vp->v_rdev)),
 438             getminor(lhp->lh_vp->v_rdev)));
 439 
 440         ASSERT(lhp->lh_ref > 0);
 441         if (--lhp->lh_ref > 0) {
 442                 /* there are more references to this handle */
 443                 mutex_exit(&ldi_handle_hash_lock[index]);
 444                 return;
 445         }
 446 
 447         /* this was the last reference/open for this handle.  free it. */
 448         lhpp = handle_find_ref_nolock(lhp->lh_vp, lhp->lh_ident);
 449         ASSERT((lhpp != NULL) && (*lhpp != NULL));
 450         *lhpp = lhp->lh_next;
 451         atomic_dec_ulong(&ldi_handle_hash_count);
 452         mutex_exit(&ldi_handle_hash_lock[index]);
 453 
 454         VN_RELE(lhp->lh_vp);
 455         ident_release(lhp->lh_ident);
 456 #ifdef  LDI_OBSOLETE_EVENT
 457         mutex_destroy(lhp->lh_lock);
 458 #endif
 459         kmem_free(lhp, sizeof (struct ldi_handle));
 460 }
 461 
 462 #ifdef  LDI_OBSOLETE_EVENT
 463 /*
 464  * LDI event manipulation functions
 465  */
 466 static void
 467 handle_event_add(ldi_event_t *lep)
 468 {
 469         struct ldi_handle *lhp = lep->le_lhp;
 470 
 471         ASSERT(lhp != NULL);