Changeset 60fe374 in rtems for cpukit/sapi


Ignore:
Timestamp:
Aug 3, 2014, 11:02:58 AM (5 years ago)
Author:
Sebastian Huber <sebastian.huber@…>
Branches:
4.11, master
Children:
390cfcd
Parents:
40dcafa
git-author:
Sebastian Huber <sebastian.huber@…> (08/03/14 11:02:58)
git-committer:
Sebastian Huber <sebastian.huber@…> (08/05/14 07:30:37)
Message:

rbtree: Add and use RBTree_Compare_result

Location:
cpukit/sapi
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • cpukit/sapi/include/rtems/rbheap.h

    r40dcafa r60fe374  
    155155 *
    156156 * @retval RTEMS_SUCCESSFUL Successful operation.
    157  * @retval RTEMS_INVALID_NUMBER The alignment is not positive.
    158157 * @retval RTEMS_INVALID_ADDRESS The memory area is invalid.
    159158 * @retval RTEMS_NO_MEMORY Not enough chunk descriptors.
  • cpukit/sapi/include/rtems/rbtree.h

    r40dcafa r60fe374  
    5656
    5757/**
    58  * This type defines function pointers for user-provided comparison
    59  * function. The function compares two nodes in order to determine
    60  * the order in a red-black tree.
     58 * @copydoc RBTree_Compare_result
     59 */
     60typedef RBTree_Compare_result rtems_rbtree_compare_result;
     61
     62/**
     63 * @copydoc RBTree_Compare
    6164 */
    6265typedef RBTree_Compare rtems_rbtree_compare;
  • cpukit/sapi/src/rbheap.c

    r40dcafa r60fe374  
    4747}
    4848
    49 static int chunk_compare(const rtems_rbtree_node *a, const rtems_rbtree_node *b)
     49static rtems_rbtree_compare_result chunk_compare(
     50  const rtems_rbtree_node *a,
     51  const rtems_rbtree_node *b
     52)
    5053{
    5154  const rtems_rbheap_chunk *left = rtems_rbheap_chunk_of_node(a);
    5255  const rtems_rbheap_chunk *right = rtems_rbheap_chunk_of_node(b);
    5356
    54   return (int) (left->begin - right->begin);
     57  return (rtems_rbtree_compare_result)
     58    ((left->begin >> 1) - (right->begin >> 1));
    5559}
    5660
     
    9498{
    9599  rtems_status_code sc = RTEMS_SUCCESSFUL;
    96 
    97   if (alignment > 0) {
    98     uintptr_t begin = (uintptr_t) area_begin;
    99     uintptr_t end = begin + area_size;
    100     uintptr_t aligned_begin = align_up(alignment, begin);
    101     uintptr_t aligned_end = align_down(alignment, end);
    102 
    103     if (begin < end && begin <= aligned_begin && aligned_begin < aligned_end) {
    104       rtems_chain_control *free_chain = &control->free_chunk_chain;
    105       rtems_rbtree_control *chunk_tree = &control->chunk_tree;
    106       rtems_rbheap_chunk *first = NULL;
    107 
    108       rtems_chain_initialize_empty(free_chain);
    109       rtems_chain_initialize_empty(&control->spare_descriptor_chain);
    110       rtems_rbtree_initialize_empty(chunk_tree);
    111       control->alignment = alignment;
    112       control->handler_arg = handler_arg;
    113       control->extend_descriptors = extend_descriptors;
    114 
    115       first = get_chunk(control);
    116       if (first != NULL) {
    117         first->begin = aligned_begin;
    118         first->size = aligned_end - aligned_begin;
    119         add_to_chain(free_chain, first);
    120         insert_into_tree(chunk_tree, first);
    121       } else {
    122         sc = RTEMS_NO_MEMORY;
    123       }
     100  uintptr_t begin = (uintptr_t) area_begin;
     101  uintptr_t end = begin + area_size;
     102  uintptr_t aligned_begin;
     103  uintptr_t aligned_end;
     104
     105  /*
     106   * Ensure that the alignment is at least two, so that we can keep
     107   * chunk_compare() that simple.
     108   */
     109  alignment = alignment < 2 ? 2 : alignment;
     110
     111  aligned_begin = align_up(alignment, begin);
     112  aligned_end = align_down(alignment, end);
     113
     114  if (begin < end && begin <= aligned_begin && aligned_begin < aligned_end) {
     115    rtems_chain_control *free_chain = &control->free_chunk_chain;
     116    rtems_rbtree_control *chunk_tree = &control->chunk_tree;
     117    rtems_rbheap_chunk *first = NULL;
     118
     119    rtems_chain_initialize_empty(free_chain);
     120    rtems_chain_initialize_empty(&control->spare_descriptor_chain);
     121    rtems_rbtree_initialize_empty(chunk_tree);
     122    control->alignment = alignment;
     123    control->handler_arg = handler_arg;
     124    control->extend_descriptors = extend_descriptors;
     125
     126    first = get_chunk(control);
     127    if (first != NULL) {
     128      first->begin = aligned_begin;
     129      first->size = aligned_end - aligned_begin;
     130      add_to_chain(free_chain, first);
     131      insert_into_tree(chunk_tree, first);
    124132    } else {
    125       sc = RTEMS_INVALID_ADDRESS;
     133      sc = RTEMS_NO_MEMORY;
    126134    }
    127135  } else {
    128     sc = RTEMS_INVALID_NUMBER;
     136    sc = RTEMS_INVALID_ADDRESS;
    129137  }
    130138
Note: See TracChangeset for help on using the changeset viewer.