Changeset 07b39338 in mainline for uspace/srv/loc/category.c


Ignore:
Timestamp:
2011-08-20T18:21:49Z (13 years ago)
Author:
Jiří Zárevúcky <zarevucky.jiri@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
6ab014d
Parents:
0cf27ee (diff), f00af83 (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 libposix.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • uspace/srv/loc/category.c

    r0cf27ee r07b39338  
    9393        cat->id = loc_create_id();
    9494        link_initialize(&cat->cat_list);
    95         list_initialize(&cat->services);
     95        list_initialize(&cat->svc_memb);
    9696}
    9797
     
    113113{
    114114        assert(fibril_mutex_is_locked(&cat->mutex));
     115        assert(fibril_mutex_is_locked(&services_list_mutex));
    115116
    116117        /* Verify that category does not contain this service yet. */
    117         list_foreach(cat->services, item) {
    118 
    119                 loc_service_t *csvc = list_get_instance(item, loc_service_t,
    120                     cat_services);
    121                 if (csvc == svc) {
     118        list_foreach(cat->svc_memb, item) {
     119                svc_categ_t *memb = list_get_instance(item, svc_categ_t,
     120                    cat_link);
     121                if (memb->svc == svc) {
    122122                        return EEXIST;
    123123                }
    124124        }
    125125
    126         list_append(&svc->cat_services, &cat->services);
     126        svc_categ_t *nmemb = malloc(sizeof(svc_categ_t));
     127        if (nmemb == NULL)
     128                return ENOMEM;
     129
     130        nmemb->svc = svc;
     131        nmemb->cat = cat;
     132
     133        list_append(&nmemb->cat_link, &cat->svc_memb);
     134        list_append(&nmemb->svc_link, &svc->cat_memb);
     135
    127136        return EOK;
     137}
     138
     139/** Remove service from category. */
     140void category_remove_service(svc_categ_t *memb)
     141{
     142        assert(fibril_mutex_is_locked(&memb->cat->mutex));
     143        assert(fibril_mutex_is_locked(&services_list_mutex));
     144
     145        list_remove(&memb->cat_link);
     146        list_remove(&memb->svc_link);
     147
     148        free(memb);
    128149}
    129150
     
    169190        buf_cnt = buf_size / sizeof(service_id_t);
    170191
    171         act_cnt = list_count(&cat->services);
     192        act_cnt = list_count(&cat->svc_memb);
    172193        *act_size = act_cnt * sizeof(service_id_t);
    173194
     
    176197
    177198        size_t pos = 0;
    178         list_foreach(cat->services, item) {
    179                 loc_service_t *svc =
    180                     list_get_instance(item, loc_service_t, cat_services);
     199        list_foreach(cat->svc_memb, item) {
     200                svc_categ_t *memb =
     201                    list_get_instance(item, svc_categ_t, cat_link);
    181202
    182203                if (pos < buf_cnt)
    183                         id_buf[pos] = svc->id;
     204                        id_buf[pos] = memb->svc->id;
    184205                pos++;
    185206        }
Note: See TracChangeset for help on using the changeset viewer.