diff options
author | patacongo <patacongo@42af7a65-404d-4744-a932-0658087f49c3> | 2013-03-08 18:29:56 +0000 |
---|---|---|
committer | patacongo <patacongo@42af7a65-404d-4744-a932-0658087f49c3> | 2013-03-08 18:29:56 +0000 |
commit | 6137a8aa8f69cb0c197efced18d7e49144791666 (patch) | |
tree | fda5a4a9a19544410ab1c45ef4b3e83e92894241 /nuttx/mm/mm_memalign.c | |
parent | 62bccf6b7538cafa63e0ea91ccb603f58417a49a (diff) | |
download | px4-nuttx-6137a8aa8f69cb0c197efced18d7e49144791666.tar.gz px4-nuttx-6137a8aa8f69cb0c197efced18d7e49144791666.tar.bz2 px4-nuttx-6137a8aa8f69cb0c197efced18d7e49144791666.zip |
Move all memory manager globals to a structure. Pass structure pointer as a handler because MM APIs
git-svn-id: svn://svn.code.sf.net/p/nuttx/code/trunk@5719 42af7a65-404d-4744-a932-0658087f49c3
Diffstat (limited to 'nuttx/mm/mm_memalign.c')
-rw-r--r-- | nuttx/mm/mm_memalign.c | 43 |
1 files changed, 35 insertions, 8 deletions
diff --git a/nuttx/mm/mm_memalign.c b/nuttx/mm/mm_memalign.c index 87547c96b..d06964534 100644 --- a/nuttx/mm/mm_memalign.c +++ b/nuttx/mm/mm_memalign.c @@ -1,7 +1,7 @@ /**************************************************************************** * mm/mm_memalign.c * - * Copyright (C) 2007, 2009, 2011 Gregory Nutt. All rights reserved. + * Copyright (C) 2007, 2009, 2011, 2013 Gregory Nutt. All rights reserved. * Author: Gregory Nutt <gnutt@nuttx.org> * * Redistribution and use in source and binary forms, with or without @@ -47,11 +47,11 @@ ****************************************************************************/ /**************************************************************************** - * Global Functions + * Private Functions ****************************************************************************/ /**************************************************************************** - * Name: memalign + * Name: _mm_memalign * * Description: * memalign requests more than enough space from malloc, finds a region @@ -63,7 +63,8 @@ * ****************************************************************************/ -FAR void *memalign(size_t alignment, size_t size) +static inline FAR void *_mm_memalign(FAR struct mm_heap_s *heap, + size_t alignment, size_t size) { FAR struct mm_allocnode_s *node; size_t rawchunk; @@ -107,7 +108,7 @@ FAR void *memalign(size_t alignment, size_t size) * nodelist. */ - mm_takesemaphore(); + mm_takesemaphore(heap); /* Get the node associated with the allocation and the next node after * the allocation. @@ -182,7 +183,7 @@ FAR void *memalign(size_t alignment, size_t size) /* Add the original, newly freed node to the free nodelist */ - mm_addfreechunk((FAR struct mm_freenode_s *)node); + mm_addfreechunk(heap, (FAR struct mm_freenode_s *)node); /* Replace the original node with the newlay realloaced, * aligned node @@ -200,9 +201,35 @@ FAR void *memalign(size_t alignment, size_t size) * malloc-compatible sizes that we have. */ - mm_shrinkchunk(node, size + SIZEOF_MM_ALLOCNODE); + mm_shrinkchunk(heap, node, size + SIZEOF_MM_ALLOCNODE); } - mm_givesemaphore(); + mm_givesemaphore(heap); return (FAR void*)alignedchunk; } + +/**************************************************************************** + * Public Functions + ****************************************************************************/ + +/**************************************************************************** + * Name: _mm_memalign + * + * Description: + * memalign requests more than enough space from malloc, finds a region + * within that chunk that meets the alignment request and then frees any + * leading or trailing space. + * + * The alignment argument must be a power of two (not checked). 8-byte + * alignment is guaranteed by normal malloc calls. + * + ****************************************************************************/ + +#if !defined(CONFIG_NUTTX_KERNEL) || !defined(__KERNEL__) + +FAR void *memalign(size_t alignment, size_t size) +{ + return _mm_memalign(&g_mmheap, alignment, size); +} + +#endif |