예제 #1
0
파일: heapgreedy.c 프로젝트: chch1028/rtems
Heap_Block *_Heap_Greedy_allocate_all_except_largest(
  Heap_Control *heap,
  uintptr_t *allocatable_size
)
{
  Heap_Information info;

  _Heap_Get_free_information( heap, &info );
  *allocatable_size = info.largest - HEAP_BLOCK_HEADER_SIZE + HEAP_ALLOC_BONUS;

  return _Heap_Greedy_allocate( heap, allocatable_size, 1 );
}
예제 #2
0
파일: init.c 프로젝트: greenmeent/rtems
static void test_greedy_allocate(void)
{
  Heap_Control *heap = &TestHeap;
  uintptr_t block_size = 1;
  void *p;

  _Heap_Initialize( heap, &TestHeapMemory[0], sizeof(TestHeapMemory), 0 );

  _Heap_Greedy_allocate( heap, &block_size, 1 );

  p = _Heap_Allocate( heap, 1 );
  rtems_test_assert( p != NULL );

  p = _Heap_Allocate( heap, 1 );
  rtems_test_assert( p == NULL );

  /* The internal allocation fails */
  _Heap_Greedy_allocate( heap, &block_size, 1 );

  p = _Heap_Allocate( heap, 1 );
  rtems_test_assert( p == NULL );
}
예제 #3
0
void *rtems_heap_greedy_allocate(
  const uintptr_t *block_sizes,
  size_t block_count
)
{
  void *opaque;

  _RTEMS_Lock_allocator();
  opaque = _Heap_Greedy_allocate( RTEMS_Malloc_Heap, block_sizes, block_count );
  _RTEMS_Unlock_allocator();

  return opaque;
}
예제 #4
0
파일: init.c 프로젝트: greenmeent/rtems
static void test_heap_extend_allocation_order_with_empty_heap(void)
{
  Heap_Control *heap = &TestHeap;
  uintptr_t size = 256;
  uintptr_t gap = 256;
  uint8_t *init_area_begin = TestHeapMemory;
  uint8_t *extend_area_begin = init_area_begin + size + gap;
  bool ret;
  uint8_t *p;

  _Heap_Initialize( heap, init_area_begin, size, 0 );

  _Heap_Greedy_allocate( heap, NULL, 0 );

  ret = _Protected_heap_Extend( heap, extend_area_begin, size );
  test_heap_assert( ret, true );

  p = _Heap_Allocate( heap, 1 );
  rtems_test_assert( (uintptr_t) (p - extend_area_begin) < size );
}