summaryrefslogtreecommitdiffstats
path: root/cpukit/libcsupport/src
diff options
context:
space:
mode:
authorSebastian Huber <sebastian.huber@embedded-brains.de>2014-11-25 14:58:13 +0100
committerSebastian Huber <sebastian.huber@embedded-brains.de>2014-11-25 16:08:16 +0100
commit7e5c9b895e52c76376386e54a0008c3a9e4a1698 (patch)
treebb8f7db25258fc1438c58a60aa950d782d0d77ab /cpukit/libcsupport/src
parentsptest/spcache01: New test cases (diff)
downloadrtems-7e5c9b895e52c76376386e54a0008c3a9e4a1698.tar.bz2
rtems: Move rtems_cache_aligned_malloc()
Make sure also the size is cache aligned since otherwise we may have some overlap with the next allocation block. A cache invalidate on this area would be fatal.
Diffstat (limited to 'cpukit/libcsupport/src')
-rw-r--r--cpukit/libcsupport/src/cachealignedalloc.c28
1 files changed, 28 insertions, 0 deletions
diff --git a/cpukit/libcsupport/src/cachealignedalloc.c b/cpukit/libcsupport/src/cachealignedalloc.c
new file mode 100644
index 0000000000..a704859dbe
--- /dev/null
+++ b/cpukit/libcsupport/src/cachealignedalloc.c
@@ -0,0 +1,28 @@
+/*
+ * 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 <rtems.h>
+#include <rtems/malloc.h>
+
+void *rtems_cache_aligned_malloc( size_t nbytes )
+{
+ size_t line_size = rtems_cache_get_data_line_size();
+
+ if ( line_size > 0 ) {
+ /* Assume that the cache line size is a power of two */
+ size_t m = line_size - 1;
+
+ nbytes = (nbytes + m) & ~m;
+ }
+
+ return rtems_heap_allocate_aligned_with_boundary( nbytes, line_size, 0 );
+}