Changeset 4359 for pjproject/trunk/pjlib/src/pj/ioqueue_common_abs.c
- Timestamp:
- Feb 21, 2013 11:18:36 AM (11 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
pjproject/trunk/pjlib/src/pj/ioqueue_common_abs.c
r3666 r4359 71 71 pj_ioqueue_key_t *key, 72 72 pj_sock_t sock, 73 pj_grp_lock_t *grp_lock, 73 74 void *user_data, 74 75 const pj_ioqueue_callback *cb) … … 115 116 /* Create mutex for the key. */ 116 117 #if !PJ_IOQUEUE_HAS_SAFE_UNREG 117 rc = pj_ mutex_create_simple(pool, NULL, &key->mutex);118 rc = pj_lock_create_simple_mutex(poll, NULL, &key->lock); 118 119 #endif 120 if (rc != PJ_SUCCESS) 121 return rc; 122 123 /* Group lock */ 124 key->grp_lock = grp_lock; 125 if (key->grp_lock) { 126 pj_grp_lock_add_ref_dbg(key->grp_lock, "ioqueue", 0); 127 } 119 128 120 return rc;129 return PJ_SUCCESS; 121 130 } 122 131 … … 190 199 { 191 200 /* Lock the key. */ 192 pj_ mutex_lock(h->mutex);201 pj_ioqueue_lock_key(h); 193 202 194 203 if (IS_CLOSING(h)) { 195 pj_ mutex_unlock(h->mutex);204 pj_ioqueue_unlock_key(h); 196 205 return; 197 206 } … … 262 271 */ 263 272 has_lock = PJ_FALSE; 264 pj_ mutex_unlock(h->mutex);273 pj_ioqueue_unlock_key(h); 265 274 } else { 266 275 has_lock = PJ_TRUE; … … 273 282 /* Unlock if we still hold the lock */ 274 283 if (has_lock) { 275 pj_ mutex_unlock(h->mutex);284 pj_ioqueue_unlock_key(h); 276 285 } 277 286 … … 380 389 */ 381 390 has_lock = PJ_FALSE; 382 pj_mutex_unlock(h->mutex); 391 pj_ioqueue_unlock_key(h); 392 PJ_RACE_ME(5); 383 393 } else { 384 394 has_lock = PJ_TRUE; … … 393 403 394 404 if (has_lock) { 395 pj_ mutex_unlock(h->mutex);405 pj_ioqueue_unlock_key(h); 396 406 } 397 407 398 408 } else { 399 pj_ mutex_unlock(h->mutex);409 pj_ioqueue_unlock_key(h); 400 410 } 401 411 … … 407 417 * able to process the event. 408 418 */ 409 pj_mutex_unlock(h->mutex);419 pj_ioqueue_unlock_key(h); 410 420 } 411 421 } … … 416 426 417 427 /* Lock the key. */ 418 pj_ mutex_lock(h->mutex);428 pj_ioqueue_lock_key(h); 419 429 420 430 if (IS_CLOSING(h)) { 421 pj_ mutex_unlock(h->mutex);431 pj_ioqueue_unlock_key(h); 422 432 return; 423 433 } … … 454 464 */ 455 465 has_lock = PJ_FALSE; 456 pj_mutex_unlock(h->mutex); 466 pj_ioqueue_unlock_key(h); 467 PJ_RACE_ME(5); 457 468 } else { 458 469 has_lock = PJ_TRUE; … … 467 478 468 479 if (has_lock) { 469 pj_ mutex_unlock(h->mutex);480 pj_ioqueue_unlock_key(h); 470 481 } 471 482 } … … 568 579 */ 569 580 has_lock = PJ_FALSE; 570 pj_mutex_unlock(h->mutex); 581 pj_ioqueue_unlock_key(h); 582 PJ_RACE_ME(5); 571 583 } else { 572 584 has_lock = PJ_TRUE; … … 581 593 582 594 if (has_lock) { 583 pj_ mutex_unlock(h->mutex);595 pj_ioqueue_unlock_key(h); 584 596 } 585 597 … … 590 602 * able to process the event. 591 603 */ 592 pj_mutex_unlock(h->mutex);604 pj_ioqueue_unlock_key(h); 593 605 } 594 606 } … … 600 612 pj_bool_t has_lock; 601 613 602 pj_ mutex_lock(h->mutex);614 pj_ioqueue_lock_key(h); 603 615 604 616 if (!h->connecting) { … … 607 619 * it has been processed by other thread. 608 620 */ 609 pj_mutex_unlock(h->mutex);621 pj_ioqueue_unlock_key(h); 610 622 return; 611 623 } 612 624 613 625 if (IS_CLOSING(h)) { 614 pj_ mutex_unlock(h->mutex);626 pj_ioqueue_unlock_key(h); 615 627 return; 616 628 } … … 630 642 */ 631 643 has_lock = PJ_FALSE; 632 pj_mutex_unlock(h->mutex); 644 pj_ioqueue_unlock_key(h); 645 PJ_RACE_ME(5); 633 646 } else { 634 647 has_lock = PJ_TRUE; … … 652 665 653 666 if (has_lock) { 654 pj_ mutex_unlock(h->mutex);667 pj_ioqueue_unlock_key(h); 655 668 } 656 669 } … … 714 727 read_op->flags = flags; 715 728 716 pj_ mutex_lock(key->mutex);729 pj_ioqueue_lock_key(key); 717 730 /* Check again. Handle may have been closed after the previous check 718 731 * in multithreaded app. If we add bad handle to the set it will … … 720 733 */ 721 734 if (IS_CLOSING(key)) { 722 pj_ mutex_unlock(key->mutex);735 pj_ioqueue_unlock_key(key); 723 736 return PJ_ECANCELLED; 724 737 } 725 738 pj_list_insert_before(&key->read_list, read_op); 726 739 ioqueue_add_to_set(key->ioqueue, key, READABLE_EVENT); 727 pj_ mutex_unlock(key->mutex);740 pj_ioqueue_unlock_key(key); 728 741 729 742 return PJ_EPENDING; … … 790 803 read_op->rmt_addrlen = addrlen; 791 804 792 pj_ mutex_lock(key->mutex);805 pj_ioqueue_lock_key(key); 793 806 /* Check again. Handle may have been closed after the previous check 794 807 * in multithreaded app. If we add bad handle to the set it will … … 796 809 */ 797 810 if (IS_CLOSING(key)) { 798 pj_ mutex_unlock(key->mutex);811 pj_ioqueue_unlock_key(key); 799 812 return PJ_ECANCELLED; 800 813 } 801 814 pj_list_insert_before(&key->read_list, read_op); 802 815 ioqueue_add_to_set(key->ioqueue, key, READABLE_EVENT); 803 pj_ mutex_unlock(key->mutex);816 pj_ioqueue_unlock_key(key); 804 817 805 818 return PJ_EPENDING; … … 904 917 write_op->flags = flags; 905 918 906 pj_ mutex_lock(key->mutex);919 pj_ioqueue_lock_key(key); 907 920 /* Check again. Handle may have been closed after the previous check 908 921 * in multithreaded app. If we add bad handle to the set it will … … 910 923 */ 911 924 if (IS_CLOSING(key)) { 912 pj_ mutex_unlock(key->mutex);925 pj_ioqueue_unlock_key(key); 913 926 return PJ_ECANCELLED; 914 927 } 915 928 pj_list_insert_before(&key->write_list, write_op); 916 929 ioqueue_add_to_set(key->ioqueue, key, WRITEABLE_EVENT); 917 pj_ mutex_unlock(key->mutex);930 pj_ioqueue_unlock_key(key); 918 931 919 932 return PJ_EPENDING; … … 1051 1064 write_op->rmt_addrlen = addrlen; 1052 1065 1053 pj_ mutex_lock(key->mutex);1066 pj_ioqueue_lock_key(key); 1054 1067 /* Check again. Handle may have been closed after the previous check 1055 1068 * in multithreaded app. If we add bad handle to the set it will … … 1057 1070 */ 1058 1071 if (IS_CLOSING(key)) { 1059 pj_ mutex_unlock(key->mutex);1072 pj_ioqueue_unlock_key(key); 1060 1073 return PJ_ECANCELLED; 1061 1074 } 1062 1075 pj_list_insert_before(&key->write_list, write_op); 1063 1076 ioqueue_add_to_set(key->ioqueue, key, WRITEABLE_EVENT); 1064 pj_ mutex_unlock(key->mutex);1077 pj_ioqueue_unlock_key(key); 1065 1078 1066 1079 return PJ_EPENDING; … … 1128 1141 accept_op->local_addr = local; 1129 1142 1130 pj_ mutex_lock(key->mutex);1143 pj_ioqueue_lock_key(key); 1131 1144 /* Check again. Handle may have been closed after the previous check 1132 1145 * in multithreaded app. If we add bad handle to the set it will … … 1134 1147 */ 1135 1148 if (IS_CLOSING(key)) { 1136 pj_ mutex_unlock(key->mutex);1149 pj_ioqueue_unlock_key(key); 1137 1150 return PJ_ECANCELLED; 1138 1151 } 1139 1152 pj_list_insert_before(&key->accept_list, accept_op); 1140 1153 ioqueue_add_to_set(key->ioqueue, key, READABLE_EVENT); 1141 pj_ mutex_unlock(key->mutex);1154 pj_ioqueue_unlock_key(key); 1142 1155 1143 1156 return PJ_EPENDING; … … 1172 1185 if (status == PJ_STATUS_FROM_OS(PJ_BLOCKING_CONNECT_ERROR_VAL)) { 1173 1186 /* Pending! */ 1174 pj_mutex_lock(key->mutex);1187 pj_ioqueue_lock_key(key); 1175 1188 /* Check again. Handle may have been closed after the previous 1176 1189 * check in multithreaded app. See #913 1177 1190 */ 1178 1191 if (IS_CLOSING(key)) { 1179 pj_ mutex_unlock(key->mutex);1192 pj_ioqueue_unlock_key(key); 1180 1193 return PJ_ECANCELLED; 1181 1194 } … … 1183 1196 ioqueue_add_to_set(key->ioqueue, key, WRITEABLE_EVENT); 1184 1197 ioqueue_add_to_set(key->ioqueue, key, EXCEPTION_EVENT); 1185 pj_ mutex_unlock(key->mutex);1198 pj_ioqueue_unlock_key(key); 1186 1199 return PJ_EPENDING; 1187 1200 } else { … … 1229 1242 * really make sure that it's still there; then call the callback. 1230 1243 */ 1231 pj_ mutex_lock(key->mutex);1244 pj_ioqueue_lock_key(key); 1232 1245 1233 1246 /* Find the operation in the pending read list. */ … … 1237 1250 pj_list_erase(op_rec); 1238 1251 op_rec->op = PJ_IOQUEUE_OP_NONE; 1239 pj_ mutex_unlock(key->mutex);1252 pj_ioqueue_unlock_key(key); 1240 1253 1241 1254 (*key->cb.on_read_complete)(key, op_key, bytes_status); … … 1251 1264 pj_list_erase(op_rec); 1252 1265 op_rec->op = PJ_IOQUEUE_OP_NONE; 1253 pj_ mutex_unlock(key->mutex);1266 pj_ioqueue_unlock_key(key); 1254 1267 1255 1268 (*key->cb.on_write_complete)(key, op_key, bytes_status); … … 1265 1278 pj_list_erase(op_rec); 1266 1279 op_rec->op = PJ_IOQUEUE_OP_NONE; 1267 pj_ mutex_unlock(key->mutex);1280 pj_ioqueue_unlock_key(key); 1268 1281 1269 1282 (*key->cb.on_accept_complete)(key, op_key, … … 1275 1288 } 1276 1289 1277 pj_ mutex_unlock(key->mutex);1290 pj_ioqueue_unlock_key(key); 1278 1291 1279 1292 return PJ_EINVALIDOP; … … 1305 1318 PJ_DEF(pj_status_t) pj_ioqueue_lock_key(pj_ioqueue_key_t *key) 1306 1319 { 1307 return pj_mutex_lock(key->mutex); 1320 if (key->grp_lock) 1321 return pj_grp_lock_acquire(key->grp_lock); 1322 else 1323 return pj_lock_acquire(key->lock); 1308 1324 } 1309 1325 1310 1326 PJ_DEF(pj_status_t) pj_ioqueue_unlock_key(pj_ioqueue_key_t *key) 1311 1327 { 1312 return pj_mutex_unlock(key->mutex); 1313 } 1314 1328 if (key->grp_lock) 1329 return pj_grp_lock_release(key->grp_lock); 1330 else 1331 return pj_lock_release(key->lock); 1332 } 1333 1334
Note: See TracChangeset
for help on using the changeset viewer.