Rev 814 | Rev 1264 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 814 | Rev 822 | ||
---|---|---|---|
Line 39... | Line 39... | ||
39 | /** Quicksort wrapper |
39 | /** Quicksort wrapper |
40 | * |
40 | * |
41 | * This is only a wrapper that takes care of memory allocations for storing |
41 | * This is only a wrapper that takes care of memory allocations for storing |
42 | * the pivot and temporary elements for generic quicksort algorithm. |
42 | * the pivot and temporary elements for generic quicksort algorithm. |
43 | * |
43 | * |
- | 44 | * This function _can_ sleep |
|
- | 45 | * |
|
44 | * @param data Pointer to data to be sorted. |
46 | * @param data Pointer to data to be sorted. |
45 | * @param n Number of elements to be sorted. |
47 | * @param n Number of elements to be sorted. |
46 | * @param e_size Size of one element. |
48 | * @param e_size Size of one element. |
47 | * @param cmp Comparator function. |
49 | * @param cmp Comparator function. |
48 | * |
50 | * |
Line 53... | Line 55... | ||
53 | __u8 buf_pivot[EBUFSIZE]; |
55 | __u8 buf_pivot[EBUFSIZE]; |
54 | void * tmp = buf_tmp; |
56 | void * tmp = buf_tmp; |
55 | void * pivot = buf_pivot; |
57 | void * pivot = buf_pivot; |
56 | 58 | ||
57 | if (e_size > EBUFSIZE) { |
59 | if (e_size > EBUFSIZE) { |
58 | pivot = (void *) malloc(e_size); |
60 | pivot = (void *) malloc(e_size, 0); |
59 | tmp = (void *) malloc(e_size); |
61 | tmp = (void *) malloc(e_size, 0); |
60 | - | ||
61 | if (!tmp || !pivot) { |
- | |
62 | panic("Cannot allocate memory\n"); |
- | |
63 | } |
- | |
64 | } |
62 | } |
65 | 63 | ||
66 | _qsort(data, n, e_size, cmp, tmp, pivot); |
64 | _qsort(data, n, e_size, cmp, tmp, pivot); |
67 | 65 | ||
68 | if (e_size > EBUFSIZE) { |
66 | if (e_size > EBUFSIZE) { |
Line 124... | Line 122... | ||
124 | { |
122 | { |
125 | __u8 buf_slot[EBUFSIZE]; |
123 | __u8 buf_slot[EBUFSIZE]; |
126 | void * slot = buf_slot; |
124 | void * slot = buf_slot; |
127 | 125 | ||
128 | if (e_size > EBUFSIZE) { |
126 | if (e_size > EBUFSIZE) { |
129 | slot = (void *) malloc(e_size); |
127 | slot = (void *) malloc(e_size, 0); |
130 | - | ||
131 | if (!slot) { |
- | |
132 | panic("Cannot allocate memory\n"); |
- | |
133 | } |
- | |
134 | } |
128 | } |
135 | 129 | ||
136 | _bubblesort(data, n, e_size, cmp, slot); |
130 | _bubblesort(data, n, e_size, cmp, slot); |
137 | 131 | ||
138 | if (e_size > EBUFSIZE) { |
132 | if (e_size > EBUFSIZE) { |