summaryrefslogtreecommitdiffstats
path: root/c/src/lib/libcpu/shared/src/cache_aligned_malloc.c
blob: 17fc46814bcd60781a9e16ea8a663d2c566d909b (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
/*
 *  RTEMS Cache Aligned Malloc
 *
 *
 *  COPYRIGHT (c) 1989-1999.
 *  On-Line Applications Research Corporation (OAR).
 *
 *  The license and distribution terms for this file may be
 *  found in the file LICENSE in this distribution or at
 *  http://www.rtems.org/license/LICENSE.
 */

#include <stdlib.h>

#include <rtems.h>
#include <cache_.h>
#include <rtems/rtems/cache.h>

/*
 *  rtems_cache_aligned_malloc
 *
 *  DESCRIPTION:
 *
 *  This function is used to allocate storage that spans an
 *  integral number of cache blocks.
 */

void *rtems_cache_aligned_malloc (
  size_t nbytes
)
{
  /*
   * Arrange to have the user storage start on the first cache
   * block beyond the header.
   */
#if defined(CPU_DATA_CACHE_ALIGNMENT)
  return (void *) ((((unsigned long)
     malloc( nbytes + CPU_DATA_CACHE_ALIGNMENT - 1 ))
        + CPU_DATA_CACHE_ALIGNMENT - 1 ) &(~(CPU_DATA_CACHE_ALIGNMENT - 1)) );
#else
  return malloc( nbytes );
#endif
}