Changeset 498ced1 in mainline for uspace/lib/c/generic/async
- Timestamp:
- 2018-08-11T02:43:32Z (7 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- 05882233
- Parents:
- b13d80b
- git-author:
- Jiří Zárevúcky <jiri.zarevucky@…> (2018-08-11 02:29:02)
- git-committer:
- Jiří Zárevúcky <jiri.zarevucky@…> (2018-08-11 02:43:32)
- Location:
- uspace/lib/c/generic/async
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/lib/c/generic/async/client.c
rb13d80b r498ced1 185 185 list_initialize(&session_ns.exch_list); 186 186 fibril_mutex_initialize(&session_ns.mutex); 187 atomic_set(&session_ns.refcnt, 0);187 session_ns.exchanges = 0; 188 188 } 189 189 … … 605 605 } 606 606 607 async_sess_t *sess = (async_sess_t *) malloc(sizeof(async_sess_t));607 async_sess_t *sess = calloc(1, sizeof(async_sess_t)); 608 608 if (sess == NULL) { 609 609 errno = ENOMEM; … … 627 627 628 628 fibril_mutex_initialize(&sess->remote_state_mtx); 629 sess->remote_state_data = NULL;630 631 629 list_initialize(&sess->exch_list); 632 630 fibril_mutex_initialize(&sess->mutex); 633 atomic_set(&sess->refcnt, 0);634 631 635 632 return sess; … … 676 673 } 677 674 678 async_sess_t *sess = (async_sess_t *) malloc(sizeof(async_sess_t));675 async_sess_t *sess = calloc(1, sizeof(async_sess_t)); 679 676 if (sess == NULL) { 680 677 errno = ENOMEM; … … 698 695 699 696 fibril_mutex_initialize(&sess->remote_state_mtx); 700 sess->remote_state_data = NULL;701 702 697 list_initialize(&sess->exch_list); 703 698 fibril_mutex_initialize(&sess->mutex); 704 atomic_set(&sess->refcnt, 0);705 699 706 700 return sess; … … 712 706 async_sess_t *async_connect_kbox(task_id_t id) 713 707 { 714 async_sess_t *sess = (async_sess_t *) malloc(sizeof(async_sess_t));708 async_sess_t *sess = calloc(1, sizeof(async_sess_t)); 715 709 if (sess == NULL) { 716 710 errno = ENOMEM; … … 729 723 sess->mgmt = EXCHANGE_ATOMIC; 730 724 sess->phone = phone; 731 sess->arg1 = 0;732 sess->arg2 = 0;733 sess->arg3 = 0;734 725 735 726 fibril_mutex_initialize(&sess->remote_state_mtx); 736 sess->remote_state_data = NULL;737 738 727 list_initialize(&sess->exch_list); 739 728 fibril_mutex_initialize(&sess->mutex); 740 atomic_set(&sess->refcnt, 0);741 729 742 730 return sess; … … 761 749 assert(sess); 762 750 763 if (atomic_get(&sess->refcnt) > 0)764 return EBUSY;765 766 751 fibril_mutex_lock(&async_sess_mutex); 752 753 assert(sess->exchanges == 0); 767 754 768 755 errno_t rc = async_hangup_internal(sess->phone); … … 874 861 } 875 862 863 if (exch != NULL) 864 sess->exchanges++; 865 876 866 fibril_mutex_unlock(&async_sess_mutex); 877 867 878 if (exch != NULL) { 879 atomic_inc(&sess->refcnt); 880 881 if (mgmt == EXCHANGE_SERIALIZE) 882 fibril_mutex_lock(&sess->mutex); 883 } 868 if (exch != NULL && mgmt == EXCHANGE_SERIALIZE) 869 fibril_mutex_lock(&sess->mutex); 884 870 885 871 return exch; … … 903 889 mgmt = sess->iface & IFACE_EXCHANGE_MASK; 904 890 905 atomic_dec(&sess->refcnt);906 907 891 if (mgmt == EXCHANGE_SERIALIZE) 908 892 fibril_mutex_unlock(&sess->mutex); 909 893 910 894 fibril_mutex_lock(&async_sess_mutex); 895 896 sess->exchanges--; 911 897 912 898 list_append(&exch->sess_link, &sess->exch_list); -
uspace/lib/c/generic/async/server.c
rb13d80b r498ced1 129 129 130 130 task_id_t in_task_id; 131 atomic_t refcnt;131 int refcnt; 132 132 void *data; 133 133 } client_t; … … 327 327 if (link) { 328 328 client = hash_table_get_inst(link, client_t, link); 329 atomic_inc(&client->refcnt);329 client->refcnt++; 330 330 } else if (create) { 331 331 // TODO: move the malloc out of critical section … … 336 336 client->data = async_client_data_create(); 337 337 338 atomic_set(&client->refcnt, 1);338 client->refcnt = 1; 339 339 hash_table_insert(&client_hash_table, &client->link); 340 340 } … … 351 351 fibril_rmutex_lock(&client_mutex); 352 352 353 if ( atomic_predec(&client->refcnt)== 0) {353 if (--client->refcnt == 0) { 354 354 hash_table_remove(&client_hash_table, &client->in_task_id); 355 355 destroy = true; … … 1574 1574 } 1575 1575 1576 async_sess_t *sess = (async_sess_t *) malloc(sizeof(async_sess_t));1576 async_sess_t *sess = calloc(1, sizeof(async_sess_t)); 1577 1577 if (sess == NULL) { 1578 1578 async_answer_0(&call, ENOMEM); … … 1583 1583 sess->mgmt = mgmt; 1584 1584 sess->phone = phandle; 1585 sess->arg1 = 0;1586 sess->arg2 = 0;1587 sess->arg3 = 0;1588 1585 1589 1586 fibril_mutex_initialize(&sess->remote_state_mtx); 1590 sess->remote_state_data = NULL;1591 1592 1587 list_initialize(&sess->exch_list); 1593 1588 fibril_mutex_initialize(&sess->mutex); 1594 atomic_set(&sess->refcnt, 0);1595 1589 1596 1590 /* Acknowledge the connected phone */ … … 1622 1616 return NULL; 1623 1617 1624 async_sess_t *sess = (async_sess_t *) malloc(sizeof(async_sess_t));1618 async_sess_t *sess = calloc(1, sizeof(async_sess_t)); 1625 1619 if (sess == NULL) 1626 1620 return NULL; … … 1629 1623 sess->mgmt = mgmt; 1630 1624 sess->phone = phandle; 1631 sess->arg1 = 0;1632 sess->arg2 = 0;1633 sess->arg3 = 0;1634 1625 1635 1626 fibril_mutex_initialize(&sess->remote_state_mtx); 1636 sess->remote_state_data = NULL;1637 1638 1627 list_initialize(&sess->exch_list); 1639 1628 fibril_mutex_initialize(&sess->mutex); 1640 atomic_set(&sess->refcnt, 0);1641 1629 1642 1630 return sess;
Note:
See TracChangeset
for help on using the changeset viewer.