Changeset 498ced1 in mainline for uspace/lib/c/generic/async/client.c


Ignore:
Timestamp:
2018-08-11T02:43:32Z (7 years ago)
Author:
Jiří Zárevúcky <jiri.zarevucky@…>
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)
Message:

Unify reference counting and remove some unnecessary instances of <atomic.h>

File:
1 edited

Legend:

Unmodified
Added
Removed
  • uspace/lib/c/generic/async/client.c

    rb13d80b r498ced1  
    185185        list_initialize(&session_ns.exch_list);
    186186        fibril_mutex_initialize(&session_ns.mutex);
    187         atomic_set(&session_ns.refcnt, 0);
     187        session_ns.exchanges = 0;
    188188}
    189189
     
    605605        }
    606606
    607         async_sess_t *sess = (async_sess_t *) malloc(sizeof(async_sess_t));
     607        async_sess_t *sess = calloc(1, sizeof(async_sess_t));
    608608        if (sess == NULL) {
    609609                errno = ENOMEM;
     
    627627
    628628        fibril_mutex_initialize(&sess->remote_state_mtx);
    629         sess->remote_state_data = NULL;
    630 
    631629        list_initialize(&sess->exch_list);
    632630        fibril_mutex_initialize(&sess->mutex);
    633         atomic_set(&sess->refcnt, 0);
    634631
    635632        return sess;
     
    676673        }
    677674
    678         async_sess_t *sess = (async_sess_t *) malloc(sizeof(async_sess_t));
     675        async_sess_t *sess = calloc(1, sizeof(async_sess_t));
    679676        if (sess == NULL) {
    680677                errno = ENOMEM;
     
    698695
    699696        fibril_mutex_initialize(&sess->remote_state_mtx);
    700         sess->remote_state_data = NULL;
    701 
    702697        list_initialize(&sess->exch_list);
    703698        fibril_mutex_initialize(&sess->mutex);
    704         atomic_set(&sess->refcnt, 0);
    705699
    706700        return sess;
     
    712706async_sess_t *async_connect_kbox(task_id_t id)
    713707{
    714         async_sess_t *sess = (async_sess_t *) malloc(sizeof(async_sess_t));
     708        async_sess_t *sess = calloc(1, sizeof(async_sess_t));
    715709        if (sess == NULL) {
    716710                errno = ENOMEM;
     
    729723        sess->mgmt = EXCHANGE_ATOMIC;
    730724        sess->phone = phone;
    731         sess->arg1 = 0;
    732         sess->arg2 = 0;
    733         sess->arg3 = 0;
    734725
    735726        fibril_mutex_initialize(&sess->remote_state_mtx);
    736         sess->remote_state_data = NULL;
    737 
    738727        list_initialize(&sess->exch_list);
    739728        fibril_mutex_initialize(&sess->mutex);
    740         atomic_set(&sess->refcnt, 0);
    741729
    742730        return sess;
     
    761749        assert(sess);
    762750
    763         if (atomic_get(&sess->refcnt) > 0)
    764                 return EBUSY;
    765 
    766751        fibril_mutex_lock(&async_sess_mutex);
     752
     753        assert(sess->exchanges == 0);
    767754
    768755        errno_t rc = async_hangup_internal(sess->phone);
     
    874861        }
    875862
     863        if (exch != NULL)
     864                sess->exchanges++;
     865
    876866        fibril_mutex_unlock(&async_sess_mutex);
    877867
    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);
    884870
    885871        return exch;
     
    903889                mgmt = sess->iface & IFACE_EXCHANGE_MASK;
    904890
    905         atomic_dec(&sess->refcnt);
    906 
    907891        if (mgmt == EXCHANGE_SERIALIZE)
    908892                fibril_mutex_unlock(&sess->mutex);
    909893
    910894        fibril_mutex_lock(&async_sess_mutex);
     895
     896        sess->exchanges--;
    911897
    912898        list_append(&exch->sess_link, &sess->exch_list);
Note: See TracChangeset for help on using the changeset viewer.