Print this page
5047 don't use atomic_*_nv if you discard the return value


1403         while (refcnt != 0) {
1404                 if (atomic_cas_32(refcntp, refcnt, refcnt + 1) == refcnt)
1405                         return (1);
1406                 refcnt = *refcntp;
1407         }
1408 
1409         /*
1410          * Somebody dropped the reference count to 0 after our initial
1411          * check.
1412          */
1413         return (0);
1414 }
1415 
1416 
1417 void
1418 cmi_hdl_rele(cmi_hdl_t ophdl)
1419 {
1420         cmi_hdl_impl_t *hdl = IMPLHDL(ophdl);
1421 
1422         ASSERT(*hdl->cmih_refcntp > 0);
1423         (void) atomic_dec_32_nv(hdl->cmih_refcntp);
1424 }
1425 
1426 void
1427 cmi_hdl_destroy(cmi_hdl_t ophdl)
1428 {
1429         cmi_hdl_impl_t *hdl = IMPLHDL(ophdl);
1430         cmi_hdl_ent_t *ent;
1431 
1432         /* Release the reference count held by cmi_hdl_create(). */
1433         ASSERT(*hdl->cmih_refcntp > 0);
1434         (void) atomic_dec_32_nv(hdl->cmih_refcntp);
1435         hdl->cmih_flags |= CMIH_F_DEAD;
1436 
1437         ent = cmi_hdl_ent_lookup(hdl->cmih_chipid, hdl->cmih_coreid,
1438             hdl->cmih_strandid);
1439         /*
1440          * Use busy polling instead of condition variable here because
1441          * cmi_hdl_rele() may be called from #MC handler.
1442          */
1443         while (cmi_hdl_canref(ent)) {
1444                 cmi_hdl_rele(ophdl);
1445                 delay(1);
1446         }
1447         ent->cmae_hdlp = NULL;
1448 
1449         kmem_free(hdl, sizeof (*hdl));
1450 }
1451 
1452 void
1453 cmi_hdl_setspecific(cmi_hdl_t ophdl, void *arg)
1454 {




1403         while (refcnt != 0) {
1404                 if (atomic_cas_32(refcntp, refcnt, refcnt + 1) == refcnt)
1405                         return (1);
1406                 refcnt = *refcntp;
1407         }
1408 
1409         /*
1410          * Somebody dropped the reference count to 0 after our initial
1411          * check.
1412          */
1413         return (0);
1414 }
1415 
1416 
1417 void
1418 cmi_hdl_rele(cmi_hdl_t ophdl)
1419 {
1420         cmi_hdl_impl_t *hdl = IMPLHDL(ophdl);
1421 
1422         ASSERT(*hdl->cmih_refcntp > 0);
1423         atomic_dec_32(hdl->cmih_refcntp);
1424 }
1425 
1426 void
1427 cmi_hdl_destroy(cmi_hdl_t ophdl)
1428 {
1429         cmi_hdl_impl_t *hdl = IMPLHDL(ophdl);
1430         cmi_hdl_ent_t *ent;
1431 
1432         /* Release the reference count held by cmi_hdl_create(). */
1433         ASSERT(*hdl->cmih_refcntp > 0);
1434         atomic_dec_32(hdl->cmih_refcntp);
1435         hdl->cmih_flags |= CMIH_F_DEAD;
1436 
1437         ent = cmi_hdl_ent_lookup(hdl->cmih_chipid, hdl->cmih_coreid,
1438             hdl->cmih_strandid);
1439         /*
1440          * Use busy polling instead of condition variable here because
1441          * cmi_hdl_rele() may be called from #MC handler.
1442          */
1443         while (cmi_hdl_canref(ent)) {
1444                 cmi_hdl_rele(ophdl);
1445                 delay(1);
1446         }
1447         ent->cmae_hdlp = NULL;
1448 
1449         kmem_free(hdl, sizeof (*hdl));
1450 }
1451 
1452 void
1453 cmi_hdl_setspecific(cmi_hdl_t ophdl, void *arg)
1454 {