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


1121                 }
1122                 break;
1123 
1124         case DDI_INFO_DEVT2INSTANCE:
1125                 *result = (void *)0;
1126                 retcode = DDI_SUCCESS;
1127                 break;
1128 
1129         default:
1130                 break;
1131         }
1132         return (retcode);
1133 }
1134 
1135 /*
1136  * Endpoint reference management.
1137  */
1138 static void
1139 tl_refhold(tl_endpt_t *tep)
1140 {
1141         atomic_add_32(&tep->te_refcnt, 1);
1142 }
1143 
1144 static void
1145 tl_refrele(tl_endpt_t *tep)
1146 {
1147         ASSERT(tep->te_refcnt != 0);
1148 
1149         if (atomic_add_32_nv(&tep->te_refcnt, -1) == 0)
1150                 tl_free(tep);
1151 }
1152 
1153 /*ARGSUSED*/
1154 static int
1155 tl_constructor(void *buf, void *cdrarg, int kmflags)
1156 {
1157         tl_endpt_t *tep = buf;
1158 
1159         bzero(tep, sizeof (tl_endpt_t));
1160         mutex_init(&tep->te_closelock, NULL, MUTEX_DEFAULT, NULL);
1161         cv_init(&tep->te_closecv, NULL, CV_DEFAULT, NULL);
1162         mutex_init(&tep->te_srv_lock, NULL, MUTEX_DEFAULT, NULL);
1163         cv_init(&tep->te_srv_cv, NULL, CV_DEFAULT, NULL);
1164         mutex_init(&tep->te_ser_lock, NULL, MUTEX_DEFAULT, NULL);
1165 
1166         return (0);
1167 }
1168 
1169 /*ARGSUSED*/


1247         serializer_t *ser;
1248 
1249         if (s == NULL)
1250                 return (NULL);
1251 
1252         ser = serializer_create(flags);
1253 
1254         if (ser == NULL) {
1255                 kmem_free(s, sizeof (tl_serializer_t));
1256                 return (NULL);
1257         }
1258 
1259         s->ts_refcnt = 1;
1260         s->ts_serializer = ser;
1261         return (s);
1262 }
1263 
1264 static void
1265 tl_serializer_refhold(tl_serializer_t *s)
1266 {
1267         atomic_add_32(&s->ts_refcnt, 1);
1268 }
1269 
1270 static void
1271 tl_serializer_refrele(tl_serializer_t *s)
1272 {
1273         if (atomic_add_32_nv(&s->ts_refcnt, -1) == 0) {
1274                 serializer_destroy(s->ts_serializer);
1275                 kmem_free(s, sizeof (tl_serializer_t));
1276         }
1277 }
1278 
1279 /*
1280  * Post a request on the endpoint serializer. For COTS transports keep track of
1281  * the number of pending requests.
1282  */
1283 static void
1284 tl_serializer_enter(tl_endpt_t *tep, tlproc_t tlproc, mblk_t *mp)
1285 {
1286         if (IS_COTS(tep)) {
1287                 mutex_enter(&tep->te_ser_lock);
1288                 tep->te_ser_count++;
1289                 mutex_exit(&tep->te_ser_lock);
1290         }
1291         serializer_enter(tep->te_serializer, (srproc_t *)tlproc, mp, tep);
1292 }
1293 


5409          * First try minor number then try default addresses.
5410          */
5411         bcopy(&tep->te_minor, tep->te_abuf, sizeof (uint32_t));
5412 
5413         for (loopcnt = 0; loopcnt < UINT32_MAX; loopcnt++) {
5414                 if (mod_hash_insert_reserve(tep->te_addrhash,
5415                     (mod_hash_key_t)&tep->te_ap, (mod_hash_val_t)tep,
5416                     tep->te_hash_hndl) == 0) {
5417                         /*
5418                          * found free address
5419                          */
5420                         tep->te_flag |= TL_ADDRHASHED;
5421                         tep->te_hash_hndl = NULL;
5422 
5423                         return (B_TRUE); /* successful return */
5424                 }
5425                 /*
5426                  * Use default address.
5427                  */
5428                 bcopy(&tep->te_defaddr, tep->te_abuf, sizeof (uint32_t));
5429                 atomic_add_32(&tep->te_defaddr, 1);
5430         }
5431 
5432         /*
5433          * Failed to find anything.
5434          */
5435         (void) (STRLOG(TL_ID, -1, 1, SL_ERROR,
5436             "tl_get_any_addr:looped 2^32 times"));
5437         return (B_FALSE);
5438 }
5439 
5440 /*
5441  * reallocb + set r/w ptrs to reflect size.
5442  */
5443 static mblk_t *
5444 tl_resizemp(mblk_t *mp, ssize_t new_size)
5445 {
5446         if ((mp = reallocb(mp, new_size, 0)) == NULL)
5447                 return (NULL);
5448 
5449         mp->b_rptr = DB_BASE(mp);




1121                 }
1122                 break;
1123 
1124         case DDI_INFO_DEVT2INSTANCE:
1125                 *result = (void *)0;
1126                 retcode = DDI_SUCCESS;
1127                 break;
1128 
1129         default:
1130                 break;
1131         }
1132         return (retcode);
1133 }
1134 
1135 /*
1136  * Endpoint reference management.
1137  */
1138 static void
1139 tl_refhold(tl_endpt_t *tep)
1140 {
1141         atomic_inc_32(&tep->te_refcnt);
1142 }
1143 
1144 static void
1145 tl_refrele(tl_endpt_t *tep)
1146 {
1147         ASSERT(tep->te_refcnt != 0);
1148 
1149         if (atomic_dec_32_nv(&tep->te_refcnt) == 0)
1150                 tl_free(tep);
1151 }
1152 
1153 /*ARGSUSED*/
1154 static int
1155 tl_constructor(void *buf, void *cdrarg, int kmflags)
1156 {
1157         tl_endpt_t *tep = buf;
1158 
1159         bzero(tep, sizeof (tl_endpt_t));
1160         mutex_init(&tep->te_closelock, NULL, MUTEX_DEFAULT, NULL);
1161         cv_init(&tep->te_closecv, NULL, CV_DEFAULT, NULL);
1162         mutex_init(&tep->te_srv_lock, NULL, MUTEX_DEFAULT, NULL);
1163         cv_init(&tep->te_srv_cv, NULL, CV_DEFAULT, NULL);
1164         mutex_init(&tep->te_ser_lock, NULL, MUTEX_DEFAULT, NULL);
1165 
1166         return (0);
1167 }
1168 
1169 /*ARGSUSED*/


1247         serializer_t *ser;
1248 
1249         if (s == NULL)
1250                 return (NULL);
1251 
1252         ser = serializer_create(flags);
1253 
1254         if (ser == NULL) {
1255                 kmem_free(s, sizeof (tl_serializer_t));
1256                 return (NULL);
1257         }
1258 
1259         s->ts_refcnt = 1;
1260         s->ts_serializer = ser;
1261         return (s);
1262 }
1263 
1264 static void
1265 tl_serializer_refhold(tl_serializer_t *s)
1266 {
1267         atomic_inc_32(&s->ts_refcnt);
1268 }
1269 
1270 static void
1271 tl_serializer_refrele(tl_serializer_t *s)
1272 {
1273         if (atomic_dec_32_nv(&s->ts_refcnt) == 0) {
1274                 serializer_destroy(s->ts_serializer);
1275                 kmem_free(s, sizeof (tl_serializer_t));
1276         }
1277 }
1278 
1279 /*
1280  * Post a request on the endpoint serializer. For COTS transports keep track of
1281  * the number of pending requests.
1282  */
1283 static void
1284 tl_serializer_enter(tl_endpt_t *tep, tlproc_t tlproc, mblk_t *mp)
1285 {
1286         if (IS_COTS(tep)) {
1287                 mutex_enter(&tep->te_ser_lock);
1288                 tep->te_ser_count++;
1289                 mutex_exit(&tep->te_ser_lock);
1290         }
1291         serializer_enter(tep->te_serializer, (srproc_t *)tlproc, mp, tep);
1292 }
1293 


5409          * First try minor number then try default addresses.
5410          */
5411         bcopy(&tep->te_minor, tep->te_abuf, sizeof (uint32_t));
5412 
5413         for (loopcnt = 0; loopcnt < UINT32_MAX; loopcnt++) {
5414                 if (mod_hash_insert_reserve(tep->te_addrhash,
5415                     (mod_hash_key_t)&tep->te_ap, (mod_hash_val_t)tep,
5416                     tep->te_hash_hndl) == 0) {
5417                         /*
5418                          * found free address
5419                          */
5420                         tep->te_flag |= TL_ADDRHASHED;
5421                         tep->te_hash_hndl = NULL;
5422 
5423                         return (B_TRUE); /* successful return */
5424                 }
5425                 /*
5426                  * Use default address.
5427                  */
5428                 bcopy(&tep->te_defaddr, tep->te_abuf, sizeof (uint32_t));
5429                 atomic_inc_32(&tep->te_defaddr);
5430         }
5431 
5432         /*
5433          * Failed to find anything.
5434          */
5435         (void) (STRLOG(TL_ID, -1, 1, SL_ERROR,
5436             "tl_get_any_addr:looped 2^32 times"));
5437         return (B_FALSE);
5438 }
5439 
5440 /*
5441  * reallocb + set r/w ptrs to reflect size.
5442  */
5443 static mblk_t *
5444 tl_resizemp(mblk_t *mp, ssize_t new_size)
5445 {
5446         if ((mp = reallocb(mp, new_size, 0)) == NULL)
5447                 return (NULL);
5448 
5449         mp->b_rptr = DB_BASE(mp);