2012-07-15 07:31:12 +08:00
|
|
|
/****************************************************************************
|
2014-09-23 00:53:50 +08:00
|
|
|
* mm/mm_heap/mm_size2ndx.c
|
2007-02-18 07:21:28 +08:00
|
|
|
*
|
2021-02-08 20:50:10 +08: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 07:21:28 +08:00
|
|
|
*
|
2021-02-08 20:50:10 +08:00
|
|
|
* http://www.apache.org/licenses/LICENSE-2.0
|
2007-02-18 07:21:28 +08:00
|
|
|
*
|
2021-02-08 20:50:10 +08: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 07:21:28 +08:00
|
|
|
*
|
2012-07-15 07:31:12 +08:00
|
|
|
****************************************************************************/
|
2007-02-18 07:21:28 +08:00
|
|
|
|
2012-07-15 07:31:12 +08:00
|
|
|
/****************************************************************************
|
2007-02-18 07:21:28 +08:00
|
|
|
* Included Files
|
2012-07-15 07:31:12 +08:00
|
|
|
****************************************************************************/
|
2007-02-18 07:21:28 +08:00
|
|
|
|
2013-03-09 04:36:18 +08:00
|
|
|
#include <nuttx/config.h>
|
|
|
|
|
2014-09-24 21:29:09 +08:00
|
|
|
#include <nuttx/mm/mm.h>
|
2007-02-18 07:21:28 +08:00
|
|
|
|
2021-03-02 16:03:00 +08:00
|
|
|
#include "mm_heap/mm.h"
|
|
|
|
|
2012-07-15 07:31:12 +08:00
|
|
|
/****************************************************************************
|
2007-02-18 07:21:28 +08:00
|
|
|
* Public Functions
|
2012-07-15 07:31:12 +08:00
|
|
|
****************************************************************************/
|
2007-02-18 07:21:28 +08:00
|
|
|
|
2012-07-15 07:31:12 +08:00
|
|
|
/****************************************************************************
|
|
|
|
* Name: mm_size2ndx
|
|
|
|
*
|
|
|
|
* Description:
|
|
|
|
* Convert the size to a nodelist index.
|
|
|
|
*
|
|
|
|
****************************************************************************/
|
2007-02-18 07:21:28 +08:00
|
|
|
|
2007-02-22 05:55:16 +08:00
|
|
|
int mm_size2ndx(size_t size)
|
2007-02-18 07:21:28 +08:00
|
|
|
{
|
|
|
|
int ndx = 0;
|
|
|
|
|
|
|
|
if (size >= MM_MAX_CHUNK)
|
|
|
|
{
|
2020-02-13 21:58:07 +08:00
|
|
|
return MM_NNODES - 1;
|
2007-02-18 07:21:28 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
size >>= MM_MIN_SHIFT;
|
|
|
|
while (size > 1)
|
|
|
|
{
|
|
|
|
ndx++;
|
|
|
|
size >>= 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
return ndx;
|
|
|
|
}
|