Ejemplo n.º 1
0
int posix_memalign(void **memptr, size_t alignment, size_t size)
{
  int ret;
  if( !chpl_mem_inited() ) {
    *memptr = NULL;
    ret = chpl_posix_memalign_check_valid(alignment);
    if( ret ) return ret;
    *memptr = __libc_memalign(alignment, size);
    if( ! *memptr ) return ENOMEM;
    if( DEBUG_REPLACE_MALLOC ) 
      printf("in early posix_memalign %p = system posix_memalign(%#x)\n",
             *memptr, (int) size);
    track_system_allocated(*memptr, size, __libc_malloc);
    return 0;
  }

  if( DEBUG_REPLACE_MALLOC ) 
    printf("in posix_memalign\n");

  ret = chpl_posix_memalign(memptr, alignment, size);

  if( DEBUG_REPLACE_MALLOC ) 
    printf("%p = chpl_posix_memalign(%#x, %#x) returned %i\n",
           *memptr, (int) alignment, (int) size, ret);

  return ret;
}
Ejemplo n.º 2
0
int chpl_posix_memalign(void** ptr, size_t alignment, size_t size) {
  void* allocated;
  int err;

  *ptr = NULL;

  err = chpl_posix_memalign_check_valid(alignment);
  if( err ) return err;

  // otherwise, allocate the pointer and return 0 or ENOMEM if it failed.
  allocated = chpl_memalign(alignment, size);

  if( ! allocated ) return ENOMEM;

  *ptr = allocated;
  return 0;
}