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
|
|
|
*
|
2024-09-12 16:44:55 +02:00
|
|
|
* SPDX-License-Identifier: Apache-2.0
|
|
|
|
*
|
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
|
|
|
|
2021-03-02 09:03:00 +01:00
|
|
|
#include "mm_heap/mm.h"
|
|
|
|
|
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:
|
2021-07-31 17:17:21 +02:00
|
|
|
* Add a free chunk to the nodes list. It is assumed that the caller holds
|
2022-09-06 08:18:45 +02:00
|
|
|
* the mm mutex.
|
2007-02-18 00:21:28 +01:00
|
|
|
*
|
2012-07-15 01:31:12 +02:00
|
|
|
****************************************************************************/
|
2007-02-18 00:21:28 +01:00
|
|
|
|
2021-02-08 16:19:12 +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;
|
2023-09-06 05:48:30 +02:00
|
|
|
size_t nodesize = MM_SIZEOF_NODE(node);
|
2020-02-19 22:23:26 +01:00
|
|
|
int ndx;
|
2007-02-18 00:21:28 +01:00
|
|
|
|
2022-12-30 09:30:55 +01:00
|
|
|
DEBUGASSERT(nodesize >= MM_MIN_CHUNK);
|
2023-09-06 06:30:24 +02:00
|
|
|
DEBUGASSERT(MM_NODE_IS_FREE(node));
|
2020-02-13 09:06:05 +01:00
|
|
|
|
2007-02-18 00:21:28 +01:00
|
|
|
/* Convert the size to a nodelist index */
|
|
|
|
|
2022-12-15 12:55:16 +01:00
|
|
|
ndx = mm_size2ndx(nodesize);
|
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
|
|
|
|
2021-07-03 16:16:25 +02:00
|
|
|
for (prev = &heap->mm_nodelist[ndx],
|
|
|
|
next = heap->mm_nodelist[ndx].flink;
|
2023-09-06 05:48:30 +02:00
|
|
|
next && next->size && MM_SIZEOF_NODE(next) < nodesize;
|
2007-02-18 00:21:28 +01:00
|
|
|
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;
|
|
|
|
}
|
|
|
|
}
|