Changeset 498ced1 in mainline for uspace/lib/c/generic/async/server.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/server.c

    rb13d80b r498ced1  
    129129
    130130        task_id_t in_task_id;
    131         atomic_t refcnt;
     131        int refcnt;
    132132        void *data;
    133133} client_t;
     
    327327        if (link) {
    328328                client = hash_table_get_inst(link, client_t, link);
    329                 atomic_inc(&client->refcnt);
     329                client->refcnt++;
    330330        } else if (create) {
    331331                // TODO: move the malloc out of critical section
     
    336336                        client->data = async_client_data_create();
    337337
    338                         atomic_set(&client->refcnt, 1);
     338                        client->refcnt = 1;
    339339                        hash_table_insert(&client_hash_table, &client->link);
    340340                }
     
    351351        fibril_rmutex_lock(&client_mutex);
    352352
    353         if (atomic_predec(&client->refcnt) == 0) {
     353        if (--client->refcnt == 0) {
    354354                hash_table_remove(&client_hash_table, &client->in_task_id);
    355355                destroy = true;
     
    15741574        }
    15751575
    1576         async_sess_t *sess = (async_sess_t *) malloc(sizeof(async_sess_t));
     1576        async_sess_t *sess = calloc(1, sizeof(async_sess_t));
    15771577        if (sess == NULL) {
    15781578                async_answer_0(&call, ENOMEM);
     
    15831583        sess->mgmt = mgmt;
    15841584        sess->phone = phandle;
    1585         sess->arg1 = 0;
    1586         sess->arg2 = 0;
    1587         sess->arg3 = 0;
    15881585
    15891586        fibril_mutex_initialize(&sess->remote_state_mtx);
    1590         sess->remote_state_data = NULL;
    1591 
    15921587        list_initialize(&sess->exch_list);
    15931588        fibril_mutex_initialize(&sess->mutex);
    1594         atomic_set(&sess->refcnt, 0);
    15951589
    15961590        /* Acknowledge the connected phone */
     
    16221616                return NULL;
    16231617
    1624         async_sess_t *sess = (async_sess_t *) malloc(sizeof(async_sess_t));
     1618        async_sess_t *sess = calloc(1, sizeof(async_sess_t));
    16251619        if (sess == NULL)
    16261620                return NULL;
     
    16291623        sess->mgmt = mgmt;
    16301624        sess->phone = phandle;
    1631         sess->arg1 = 0;
    1632         sess->arg2 = 0;
    1633         sess->arg3 = 0;
    16341625
    16351626        fibril_mutex_initialize(&sess->remote_state_mtx);
    1636         sess->remote_state_data = NULL;
    1637 
    16381627        list_initialize(&sess->exch_list);
    16391628        fibril_mutex_initialize(&sess->mutex);
    1640         atomic_set(&sess->refcnt, 0);
    16411629
    16421630        return sess;
Note: See TracChangeset for help on using the changeset viewer.