Changeset 7df0c2ff in mainline
- Timestamp:
- 2012-07-23T09:32:52Z (12 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- f9c3ef44
- Parents:
- 7deca26 (diff), ea8b91d (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. - Location:
- uspace
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/drv/bus/usb/ohci/hc.c
r7deca26 r7df0c2ff 66 66 .srcarg = 1, 67 67 .dstarg = 2, 68 .value = OHCI_USED_INTERRUPTS68 .value = 0 69 69 }, 70 70 { … … 132 132 cmds[0].addr = (void *) ®isters->interrupt_status; 133 133 cmds[3].addr = (void *) ®isters->interrupt_status; 134 OHCI_WR(cmds[1].value, OHCI_USED_INTERRUPTS); 134 135 135 136 return EOK; -
uspace/lib/c/generic/malloc.c
r7deca26 r7df0c2ff 109 109 (((uintptr_t) (area)->end) - sizeof(heap_block_foot_t)) 110 110 111 #define AREA_LAST_BLOCK_HEAD(area) \ 112 ((uintptr_t) BLOCK_HEAD(((heap_block_foot_t *)AREA_LAST_BLOCK_FOOT(area)))) 113 111 114 /** Get header in heap block. 112 115 * … … 346 349 return false; 347 350 348 /* Add new free block */ 349 size_t net_size = (size_t) (end - area->end); 350 if (net_size > 0) 351 block_init(area->end, net_size, true, area); 351 heap_block_head_t *last_head = (heap_block_head_t *) AREA_LAST_BLOCK_HEAD(area); 352 353 if (last_head->free) { 354 /* Add the new space to the last block. */ 355 size_t net_size = (size_t) (end - area->end) + last_head->size; 356 malloc_assert(net_size > 0); 357 block_init(last_head, net_size, true, area); 358 } else { 359 /* Add new free block */ 360 size_t net_size = (size_t) (end - area->end); 361 if (net_size > 0) 362 block_init(area->end, net_size, true, area); 363 } 352 364 353 365 /* Update heap area parameters */ … … 355 367 356 368 return true; 357 }358 359 /** Try to enlarge any of the heap areas360 *361 * Should be called only inside the critical section.362 *363 * @param size Gross size of item to allocate (bytes).364 *365 */366 static bool heap_grow(size_t size)367 {368 if (size == 0)369 return true;370 371 /* First try to enlarge some existing area */372 for (heap_area_t *area = first_heap_area; area != NULL;373 area = area->next) {374 if (area_grow(area, size))375 return true;376 }377 378 /* Eventually try to create a new area */379 return area_create(AREA_OVERHEAD(size));380 369 } 381 370 … … 661 650 } 662 651 652 /** Try to enlarge any of the heap areas. 653 * If successful, allocate block of the given size in the area. 654 * 655 * Should be called only inside the critical section. 656 * 657 * @param size Gross size of item to allocate (bytes). 658 * @param align Memory address alignment. 659 * 660 */ 661 static void *heap_grow_and_alloc(size_t size, size_t align) 662 { 663 if (size == 0) 664 return NULL; 665 666 /* First try to enlarge some existing area */ 667 for (heap_area_t *area = first_heap_area; area != NULL; 668 area = area->next) { 669 670 if (area_grow(area, size + align)) { 671 heap_block_head_t *first = (heap_block_head_t *) AREA_LAST_BLOCK_HEAD(area); 672 673 void *addr = malloc_area(area, first, NULL, size, align); 674 malloc_assert(addr != NULL); 675 return addr; 676 } 677 } 678 679 /* Eventually try to create a new area */ 680 if (area_create(AREA_OVERHEAD(size + align))) { 681 heap_block_head_t *first = (heap_block_head_t *) AREA_FIRST_BLOCK_HEAD(last_heap_area); 682 683 void *addr = malloc_area(last_heap_area, first, NULL, size, align); 684 malloc_assert(addr != NULL); 685 return addr; 686 } 687 688 return NULL; 689 } 690 663 691 /** Allocate a memory block 664 692 * … … 679 707 680 708 size_t falign = lcm(align, BASE_ALIGN); 681 size_t real_size = GROSS_SIZE(ALIGN_UP(size, falign)); 682 683 bool retry = false; 709 710 /* Check for integer overflow. */ 711 if (falign < align) 712 return NULL; 713 714 size_t gross_size = GROSS_SIZE(size); 715 684 716 heap_block_head_t *split; 685 686 loop:687 717 688 718 /* Try the next fit approach */ … … 690 720 691 721 if (split != NULL) { 692 void *addr = malloc_area(split->area, split, NULL, real_size,722 void *addr = malloc_area(split->area, split, NULL, gross_size, 693 723 falign); 694 724 … … 703 733 AREA_FIRST_BLOCK_HEAD(area); 704 734 705 void *addr = malloc_area(area, first, split, real_size,735 void *addr = malloc_area(area, first, split, gross_size, 706 736 falign); 707 737 … … 710 740 } 711 741 712 if (!retry) { 713 /* Try to grow the heap space */ 714 if (heap_grow(real_size)) { 715 retry = true; 716 goto loop; 717 } 718 } 719 720 return NULL; 742 /* Finally, try to grow heap space and allocate in the new area. */ 743 return heap_grow_and_alloc(gross_size, falign); 721 744 } 722 745
Note:
See TracChangeset
for help on using the changeset viewer.