2012-07-15 01:31:12 +02:00
|
|
|
/****************************************************************************
|
2014-09-22 18:53:50 +02:00
|
|
|
* mm/mm_heap/mm_addfreechunk.c
|
2007-02-18 00:21:28 +01:00
|
|
|
*
|
2021-02-08 13:50:10 +01:00
|
|
|
* Licensed to the Apache Software Foundation (ASF) under one or more
|
|
|
|
* contributor license agreements. See the NOTICE file distributed with
|
|
|
|
* this work for additional information regarding copyright ownership. The
|
|
|
|
* ASF licenses this file to you under the Apache License, Version 2.0 (the
|
|
|
|
* "License"); you may not use this file except in compliance with the
|
|
|
|
* License. You may obtain a copy of the License at
|
2007-02-18 00:21:28 +01:00
|
|
|
*
|
2021-02-08 13:50:10 +01:00
|
|
|
* http://www.apache.org/licenses/LICENSE-2.0
|
2007-02-18 00:21:28 +01:00
|
|
|
*
|
2021-02-08 13:50:10 +01:00
|
|
|
* Unless required by applicable law or agreed to in writing, software
|
|
|
|
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
|
|
|
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
|
|
|
* License for the specific language governing permissions and limitations
|
|
|
|
* under the License.
|
2007-02-18 00:21:28 +01:00
|
|
|
*
|
2012-07-15 01:31:12 +02:00
|
|
|
****************************************************************************/
|
2007-02-18 00:21:28 +01:00
|
|
|
|
2012-07-15 01:31:12 +02:00
|
|
|
/****************************************************************************
|
2007-02-18 00:21:28 +01:00
|
|
|
* Included Files
|
2012-07-15 01:31:12 +02:00
|
|
|
****************************************************************************/
|
2007-02-18 00:21:28 +01:00
|
|
|
|
2013-03-08 21:36:18 +01:00
|
|
|
#include <nuttx/config.h>
|
|
|
|
|
2020-02-13 09:06:05 +01:00
|
|
|
#include <assert.h>
|
|
|
|
|
2014-09-24 15:29:09 +02:00
|
|
|
#include <nuttx/mm/mm.h>
|
2007-02-18 00:21:28 +01:00
|
|
|
|
2012-07-15 01:31:12 +02:00
|
|
|
/****************************************************************************
|
2015-10-03 00:30:35 +02:00
|
|
|
* Public Functions
|
2012-07-15 01:31:12 +02:00
|
|
|
****************************************************************************/
|
2007-02-18 00:21:28 +01:00
|
|
|
|
2012-07-15 01:31:12 +02:00
|
|
|
/****************************************************************************
|
|
|
|
* Name: mm_addfreechunk
|
2007-02-18 00:21:28 +01:00
|
|
|
*
|
|
|
|
* Description:
|
2012-07-15 01:31:12 +02:00
|
|
|
* Add a free chunk to the node next. It is assumed that the caller holds
|
|
|
|
* the mm semaphore
|
2007-02-18 00:21:28 +01:00
|
|
|
*
|
2012-07-15 01:31:12 +02:00
|
|
|
****************************************************************************/
|
2007-02-18 00:21:28 +01:00
|
|
|
|
2013-03-08 19:29:56 +01:00
|
|
|
void mm_addfreechunk(FAR struct mm_heap_s *heap, FAR struct mm_freenode_s *node)
|
2007-02-18 00:21:28 +01:00
|
|
|
{
|
2007-02-27 22:17:21 +01:00
|
|
|
FAR struct mm_freenode_s *next;
|
|
|
|
FAR struct mm_freenode_s *prev;
|
2020-02-19 22:23:26 +01:00
|
|
|
int ndx;
|
2007-02-18 00:21:28 +01:00
|
|
|
|
2020-02-13 09:06:05 +01:00
|
|
|
DEBUGASSERT(node->size >= SIZEOF_MM_FREENODE);
|
|
|
|
DEBUGASSERT((node->preceding & MM_ALLOC_BIT) == 0);
|
|
|
|
|
2007-02-18 00:21:28 +01:00
|
|
|
/* Convert the size to a nodelist index */
|
|
|
|
|
2020-02-19 22:23:26 +01:00
|
|
|
ndx = mm_size2ndx(node->size);
|
2007-02-18 00:21:28 +01:00
|
|
|
|
2020-02-12 05:03:22 +01:00
|
|
|
/* Now put the new node into the next */
|
2007-02-18 00:21:28 +01:00
|
|
|
|
2013-03-08 19:29:56 +01:00
|
|
|
for (prev = &heap->mm_nodelist[ndx], next = heap->mm_nodelist[ndx].flink;
|
2007-02-18 00:21:28 +01:00
|
|
|
next && next->size && next->size < node->size;
|
|
|
|
prev = next, next = next->flink);
|
|
|
|
|
|
|
|
/* Does it go in mid next or at the end? */
|
|
|
|
|
|
|
|
prev->flink = node;
|
|
|
|
node->blink = prev;
|
|
|
|
node->flink = next;
|
|
|
|
|
|
|
|
if (next)
|
|
|
|
{
|
|
|
|
/* The new node goes between prev and next */
|
|
|
|
|
|
|
|
next->blink = node;
|
|
|
|
}
|
|
|
|
}
|