Changeset 786bd56 in mainline for uspace/lib/c/generic/loc.c


Ignore:
Timestamp:
2012-01-24T09:26:36Z (12 years ago)
Author:
Frantisek Princ <frantisek.princ@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
cd1cc4e6
Parents:
304faab (diff), 2df6f6fe (diff)
Note: this is a merge changeset, the changes displayed below correspond to the merge itself.
Use the (diff) links above to see all the changes relative to each parent.
Message:

Merge with mainline

File:
1 edited

Legend:

Unmodified
Added
Removed
  • uspace/lib/c/generic/loc.c

    r304faab r786bd56  
    4747static FIBRIL_MUTEX_INITIALIZE(loc_callback_mutex);
    4848static bool loc_callback_created = false;
     49static loc_cat_change_cb_t cat_change_cb = NULL;
    4950
    5051static async_sess_t *loc_supp_block_sess = NULL;
     
    5455static async_sess_t *loc_consumer_sess = NULL;
    5556
    56 static loc_cat_change_cb_t cat_change_cb = NULL;
    57 
    5857static void loc_cb_conn(ipc_callid_t iid, ipc_call_t *icall, void *arg)
    5958{
    60         loc_cat_change_cb_t cb_fun;
    61        
    6259        while (true) {
    6360                ipc_call_t call;
     
    6966                }
    7067               
    71                 int retval;
    72                
    7368                switch (IPC_GET_IMETHOD(call)) {
    7469                case LOC_EVENT_CAT_CHANGE:
    7570                        fibril_mutex_lock(&loc_callback_mutex);
    76                         cb_fun = cat_change_cb;
    77                         if (cb_fun != NULL) {
     71                        loc_cat_change_cb_t cb_fun = cat_change_cb;
     72                        fibril_mutex_unlock(&loc_callback_mutex);
     73                       
     74                        async_answer_0(callid, EOK);
     75                       
     76                        if (cb_fun != NULL)
    7877                                (*cb_fun)();
    79                         }
    80                         fibril_mutex_unlock(&loc_callback_mutex);
    81                         retval = 0;
     78                       
    8279                        break;
    8380                default:
    84                         retval = ENOTSUP;
     81                        async_answer_0(callid, ENOTSUP);
    8582                }
    86                
    87                 async_answer_0(callid, retval);
    8883        }
    8984}
     
    10196}
    10297
     98/** Create callback
     99 *
     100 * Must be called with loc_callback_mutex locked.
     101 *
     102 * @return EOK on success.
     103 *
     104 */
    103105static int loc_callback_create(void)
    104106{
    105         async_exch_t *exch;
    106         sysarg_t retval;
    107         int rc = EOK;
    108 
    109         fibril_mutex_lock(&loc_callback_mutex);
    110        
    111107        if (!loc_callback_created) {
    112                 exch = loc_exchange_begin_blocking(LOC_PORT_CONSUMER);
     108                async_exch_t *exch =
     109                    loc_exchange_begin_blocking(LOC_PORT_CONSUMER);
    113110               
    114111                ipc_call_t answer;
    115112                aid_t req = async_send_0(exch, LOC_CALLBACK_CREATE, &answer);
    116                 async_connect_to_me(exch, 0, 0, 0, loc_cb_conn, NULL);
     113                int rc = async_connect_to_me(exch, 0, 0, 0, loc_cb_conn, NULL);
    117114                loc_exchange_end(exch);
    118115               
     116                if (rc != EOK)
     117                        return rc;
     118               
     119                sysarg_t retval;
    119120                async_wait_for(req, &retval);
    120                 if (rc != EOK)
    121                         goto done;
    122                
    123                 if (retval != EOK) {
    124                         rc = retval;
    125                         goto done;
    126                 }
     121                if (retval != EOK)
     122                        return retval;
    127123               
    128124                loc_callback_created = true;
    129125        }
    130126       
    131         rc = EOK;
    132 done:
    133         fibril_mutex_unlock(&loc_callback_mutex);
    134         return rc;
     127        return EOK;
    135128}
    136129
     
    795788    sysarg_t **data, size_t *count)
    796789{
    797         service_id_t *ids;
    798         size_t act_size;
    799         size_t alloc_size;
    800         int rc;
    801 
    802790        *data = NULL;
    803         act_size = 0;   /* silence warning */
    804 
    805         rc = loc_category_get_ids_once(method, arg1, NULL, 0,
     791        *count = 0;
     792       
     793        size_t act_size = 0;
     794        int rc = loc_category_get_ids_once(method, arg1, NULL, 0,
    806795            &act_size);
    807796        if (rc != EOK)
    808797                return rc;
    809 
    810         alloc_size = act_size;
    811         ids = malloc(alloc_size);
     798       
     799        size_t alloc_size = act_size;
     800        service_id_t *ids = malloc(alloc_size);
    812801        if (ids == NULL)
    813802                return ENOMEM;
    814 
     803       
    815804        while (true) {
    816805                rc = loc_category_get_ids_once(method, arg1, ids, alloc_size,
     
    818807                if (rc != EOK)
    819808                        return rc;
    820 
     809               
    821810                if (act_size <= alloc_size)
    822811                        break;
    823 
    824                 alloc_size *= 2;
    825                 free(ids);
    826 
    827                 ids = malloc(alloc_size);
     812               
     813                alloc_size = act_size;
     814                ids = realloc(ids, alloc_size);
    828815                if (ids == NULL)
    829816                        return ENOMEM;
    830817        }
    831 
     818       
    832819        *count = act_size / sizeof(category_id_t);
    833820        *data = ids;
     
    867854int loc_register_cat_change_cb(loc_cat_change_cb_t cb_fun)
    868855{
    869         if (loc_callback_create() != EOK)
     856        fibril_mutex_lock(&loc_callback_mutex);
     857        if (loc_callback_create() != EOK) {
     858                fibril_mutex_unlock(&loc_callback_mutex);
    870859                return EIO;
    871 
     860        }
     861       
    872862        cat_change_cb = cb_fun;
     863        fibril_mutex_unlock(&loc_callback_mutex);
     864       
    873865        return EOK;
    874866}
Note: See TracChangeset for help on using the changeset viewer.