Changeset b72efe8 in mainline for uspace/lib/c/generic
- Timestamp:
- 2011-06-19T14:38:59Z (14 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- 74464e8
- Parents:
- 1d1bb0f
- Location:
- uspace/lib/c/generic
- Files:
-
- 9 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/lib/c/generic/adt/hash_table.c
r1d1bb0f rb72efe8 61 61 assert(max_keys > 0); 62 62 63 h->entry = malloc(m * sizeof(li nk_t));63 h->entry = malloc(m * sizeof(list_t)); 64 64 if (!h->entry) 65 65 return false; 66 66 67 memset((void *) h->entry, 0, m * sizeof(li nk_t));67 memset((void *) h->entry, 0, m * sizeof(list_t)); 68 68 69 69 hash_count_t i; … … 123 123 assert(chain < h->entries); 124 124 125 link_t *cur; 126 for (cur = h->entry[chain].next; cur != &h->entry[chain]; 127 cur = cur->next) { 125 list_foreach(h->entry[chain], cur) { 128 126 if (h->op->compare(key, h->max_keys, cur)) { 129 127 /* … … 153 151 assert(keys <= h->max_keys); 154 152 155 link_t *cur;156 157 153 if (keys == h->max_keys) { 154 link_t *cur; 155 158 156 /* 159 157 * All keys are known, hash_table_find() can be used to find the … … 176 174 hash_index_t chain; 177 175 for (chain = 0; chain < h->entries; chain++) { 178 for (cur = h->entry[chain].next; cur != &h->entry[chain]; 176 link_t *cur; 177 178 for (cur = h->entry[chain].head.next; cur != &h->entry[chain].head; 179 179 cur = cur->next) { 180 180 if (h->op->compare(key, keys, cur)) { … … 203 203 { 204 204 hash_index_t bucket; 205 link_t *cur;206 205 207 206 for (bucket = 0; bucket < h->entries; bucket++) { 208 for (cur = h->entry[bucket].next; cur != &h->entry[bucket]; 209 cur = cur->next) { 207 list_foreach(h->entry[bucket], cur) { 210 208 f(cur, arg); 211 209 } -
uspace/lib/c/generic/adt/list.c
r1d1bb0f rb72efe8 30 30 * @{ 31 31 */ 32 /** @file 32 33 /** 34 * @file 35 * @brief Functions completing doubly linked circular list implementaion. 36 * 37 * This file contains some of the functions implementing doubly linked circular lists. 38 * However, this ADT is mostly implemented in @ref list.h. 33 39 */ 34 40 35 41 #include <adt/list.h> 36 42 #include <bool.h> 37 43 38 44 /** Check for membership 39 45 * 40 * Check whether link is contained in the list head.41 * The membership is defined as pointer equivalence.46 * Check whether link is contained in a list. 47 * Membership is defined as pointer equivalence. 42 48 * 43 * @param link 44 * @param headList to look in.49 * @param link Item to look for. 50 * @param list List to look in. 45 51 * 46 52 * @return true if link is contained in head, false otherwise. 47 53 * 48 54 */ 49 int list_member(const link_t *link, const li nk_t *head)55 int list_member(const link_t *link, const list_t *list) 50 56 { 51 int found = 0;52 link_t *hlp = head->next;57 bool found = false; 58 link_t *hlp = list->head.next; 53 59 54 while (hlp != head) {60 while (hlp != &list->head) { 55 61 if (hlp == link) { 56 found = 1;62 found = true; 57 63 break; 58 64 } … … 63 69 } 64 70 65 66 71 /** Concatenate two lists 67 72 * 68 * Concatenate lists head1 and head2, producing a single69 * list head1 containing items from both (in head1, head270 * order) and empty list head2.73 * Concatenate lists @a list1 and @a list2, producing a single 74 * list @a list1 containing items from both (in @a list1, @a list2 75 * order) and empty list @a list2. 71 76 * 72 * @param head1First list and concatenated output73 * @param head2Second list and empty output.77 * @param list1 First list and concatenated output 78 * @param list2 Second list and empty output. 74 79 * 75 80 */ 76 void list_concat(li nk_t *head1, link_t *head2)81 void list_concat(list_t *list1, list_t *list2) 77 82 { 78 if (list_empty( head2))83 if (list_empty(list2)) 79 84 return; 80 81 head2->next->prev = head1->prev;82 head2->prev->next = head1;83 head1->prev->next = head2->next;84 head1->prev = head2->prev;85 list_initialize( head2);85 86 list2->head.next->prev = list1->head.prev; 87 list2->head.prev->next = &list1->head; 88 list1->head.prev->next = list2->head.next; 89 list1->head.prev = list2->head.prev; 90 list_initialize(list2); 86 91 } 87 88 92 89 93 /** Count list items … … 91 95 * Return the number of items in the list. 92 96 * 93 * @param link List to count. 94 * 95 * @return Number of items in the list. 96 * 97 * @param list List to count. 98 * @return Number of items in the list. 97 99 */ 98 unsigned int list_count(const li nk_t *link)100 unsigned int list_count(const list_t *list) 99 101 { 100 102 unsigned int count = 0; 101 link_t *hlp = link->next;102 103 103 while (hlp !=link) {104 list_foreach(*list, link) { 104 105 count++; 105 hlp = hlp->next;106 106 } 107 107 -
uspace/lib/c/generic/adt/prodcons.c
r1d1bb0f rb72efe8 61 61 fibril_condvar_wait(&pc->cv, &pc->mtx); 62 62 63 link_t *head = pc->list.next;63 link_t *head = list_first(&pc->list); 64 64 list_remove(head); 65 65 -
uspace/lib/c/generic/async.c
r1d1bb0f rb72efe8 160 160 161 161 /** Messages that should be delivered to this fibril. */ 162 li nk_t msg_queue;162 list_t msg_queue; 163 163 164 164 /** Identification of the opening call. */ … … 361 361 wd->to_event.inlist = true; 362 362 363 link_t *tmp = timeout_list. next;364 while (tmp != &timeout_list ) {363 link_t *tmp = timeout_list.head.next; 364 while (tmp != &timeout_list.head) { 365 365 awaiter_t *cur 366 366 = list_get_instance(tmp, awaiter_t, to_event.link); … … 372 372 } 373 373 374 list_ append(&wd->to_event.link, tmp);374 list_insert_before(&wd->to_event.link, tmp); 375 375 } 376 376 … … 569 569 } 570 570 571 msg_t *msg = list_get_instance( conn->msg_queue.next, msg_t, link);571 msg_t *msg = list_get_instance(list_first(&conn->msg_queue), msg_t, link); 572 572 list_remove(&msg->link); 573 573 … … 675 675 while (!list_empty(&fibril_connection->msg_queue)) { 676 676 msg_t *msg = 677 list_get_instance( fibril_connection->msg_queue.next, msg_t,678 link);677 list_get_instance(list_first(&fibril_connection->msg_queue), 678 msg_t, link); 679 679 680 680 list_remove(&msg->link); … … 806 806 futex_down(&async_futex); 807 807 808 link_t *cur = timeout_list.next;809 while (cur != &timeout_list) {808 link_t *cur = list_first(&timeout_list); 809 while (cur != NULL) { 810 810 awaiter_t *waiter = 811 811 list_get_instance(cur, awaiter_t, to_event.link); … … 813 813 if (tv_gt(&waiter->to_event.expires, &tv)) 814 814 break; 815 816 cur = cur->next;817 815 818 816 list_remove(&waiter->to_event.link); … … 828 826 fibril_add_ready(waiter->fid); 829 827 } 828 829 cur = list_first(&timeout_list); 830 830 } 831 831 … … 854 854 suseconds_t timeout; 855 855 if (!list_empty(&timeout_list)) { 856 awaiter_t *waiter = list_get_instance( timeout_list.next,857 awaiter_t, to_event.link);856 awaiter_t *waiter = list_get_instance( 857 list_first(&timeout_list), awaiter_t, to_event.link); 858 858 859 859 struct timeval tv; … … 1731 1731 */ 1732 1732 exch = (async_exch_t *) 1733 list_get_instance(sess->exch_list.next, async_exch_t, sess_link); 1733 list_get_instance(list_first(&sess->exch_list), 1734 async_exch_t, sess_link); 1735 1734 1736 list_remove(&exch->sess_link); 1735 1737 list_remove(&exch->global_link); … … 1743 1745 exch = (async_exch_t *) malloc(sizeof(async_exch_t)); 1744 1746 if (exch != NULL) { 1745 li st_initialize(&exch->sess_link);1746 li st_initialize(&exch->global_link);1747 link_initialize(&exch->sess_link); 1748 link_initialize(&exch->global_link); 1747 1749 exch->sess = sess; 1748 1750 exch->phone = sess->phone; … … 1761 1763 exch = (async_exch_t *) malloc(sizeof(async_exch_t)); 1762 1764 if (exch != NULL) { 1763 li st_initialize(&exch->sess_link);1764 li st_initialize(&exch->global_link);1765 link_initialize(&exch->sess_link); 1766 link_initialize(&exch->global_link); 1765 1767 exch->sess = sess; 1766 1768 exch->phone = phone; … … 1774 1776 */ 1775 1777 exch = (async_exch_t *) 1776 list_get_instance(inactive_exch_list.next, async_exch_t, 1777 global_link); 1778 list_get_instance(list_first(&inactive_exch_list), 1779 async_exch_t, global_link); 1780 1778 1781 list_remove(&exch->sess_link); 1779 1782 list_remove(&exch->global_link); -
uspace/lib/c/generic/devman.c
r1d1bb0f rb72efe8 35 35 */ 36 36 37 #include <adt/list.h> 37 38 #include <str.h> 38 39 #include <ipc/services.h> … … 231 232 } 232 233 233 link_t *link = match_ids->ids.next;234 234 match_id_t *match_id = NULL; 235 235 236 while (link != &match_ids->ids) {236 list_foreach(match_ids->ids, link) { 237 237 match_id = list_get_instance(link, match_id_t, link); 238 238 … … 255 255 return retval; 256 256 } 257 258 link = link->next;259 257 } 260 258 -
uspace/lib/c/generic/fibril.c
r1d1bb0f rb72efe8 222 222 fibril_t *dstf; 223 223 if ((stype == FIBRIL_TO_MANAGER) || (stype == FIBRIL_FROM_DEAD)) { 224 dstf = list_get_instance(manager_list.next, fibril_t, link); 224 dstf = list_get_instance(list_first(&manager_list), fibril_t, 225 link); 225 226 if (serialization_count && stype == FIBRIL_TO_MANAGER) { 226 227 serialized_threads++; … … 233 234 } else { 234 235 if (!list_empty(&serialized_list)) { 235 dstf = list_get_instance( serialized_list.next, fibril_t,236 link);236 dstf = list_get_instance(list_first(&serialized_list), 237 fibril_t, link); 237 238 serialized_threads--; 238 239 } else { 239 dstf = list_get_instance( ready_list.next, fibril_t,240 link);240 dstf = list_get_instance(list_first(&ready_list), 241 fibril_t, link); 241 242 } 242 243 } … … 326 327 327 328 if (!list_empty(&manager_list)) 328 list_remove( manager_list.next);329 list_remove(list_first(&manager_list)); 329 330 330 331 futex_up(&fibril_futex); -
uspace/lib/c/generic/fibril_synch.c
r1d1bb0f rb72efe8 148 148 fibril_t *f; 149 149 150 assert(!list_empty(&fm->waiters));151 tmp = fm->waiters.next;150 tmp = list_first(&fm->waiters); 151 assert(tmp != NULL); 152 152 wdp = list_get_instance(tmp, awaiter_t, wu_event.link); 153 153 wdp->active = true; … … 279 279 280 280 while (!list_empty(&frw->waiters)) { 281 link_t *tmp = frw->waiters.next;281 link_t *tmp = list_first(&frw->waiters); 282 282 awaiter_t *wdp; 283 283 fibril_t *f; … … 422 422 futex_down(&async_futex); 423 423 while (!list_empty(&fcv->waiters)) { 424 tmp = fcv->waiters.next;424 tmp = list_first(&fcv->waiters); 425 425 wdp = list_get_instance(tmp, awaiter_t, wu_event.link); 426 426 list_remove(&wdp->wu_event.link); -
uspace/lib/c/generic/io/io.c
r1d1bb0f rb72efe8 127 127 void __stdio_done(void) 128 128 { 129 link_t *link = files.next; 130 131 while (link != &files) { 132 FILE *file = list_get_instance(link, FILE, link); 129 while (!list_empty(&files)) { 130 FILE *file = list_get_instance(list_first(&files), FILE, link); 133 131 fclose(file); 134 link = files.next;135 132 } 136 133 } -
uspace/lib/c/generic/ipc.c
r1d1bb0f rb72efe8 458 458 while (!list_empty(&queued_calls)) { 459 459 async_call_t *call = 460 list_get_instance( queued_calls.next, async_call_t, list);460 list_get_instance(list_first(&queued_calls), async_call_t, list); 461 461 ipc_callid_t callid = 462 462 ipc_call_async_internal(call->u.msg.phoneid, &call->u.msg.data); … … 511 511 512 512 link_t *item; 513 for (item = dispatched_calls. next; item != &dispatched_calls;513 for (item = dispatched_calls.head.next; item != &dispatched_calls.head; 514 514 item = item->next) { 515 515 async_call_t *call =
Note:
See TracChangeset
for help on using the changeset viewer.