2012-09-12 17:21:26 +02:00
|
|
|
/****************************************************************************
|
2014-09-22 18:33:23 +02:00
|
|
|
* mm/mm_gran/mm_grancritical.c
|
2012-09-12 17:21:26 +02:00
|
|
|
*
|
2024-09-12 16:44:55 +02:00
|
|
|
* SPDX-License-Identifier: Apache-2.0
|
|
|
|
*
|
2020-03-29 19:57:53 +02: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
|
2012-09-12 17:21:26 +02:00
|
|
|
*
|
2020-03-29 19:57:53 +02:00
|
|
|
* http://www.apache.org/licenses/LICENSE-2.0
|
2012-09-12 17:21:26 +02:00
|
|
|
*
|
2020-03-29 19:57:53 +02: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.
|
2012-09-12 17:21:26 +02:00
|
|
|
*
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* Included Files
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
#include <nuttx/config.h>
|
|
|
|
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <assert.h>
|
|
|
|
#include <errno.h>
|
|
|
|
|
2016-02-14 15:57:01 +01:00
|
|
|
#include <nuttx/irq.h>
|
2014-09-24 14:55:26 +02:00
|
|
|
#include <nuttx/mm/gran.h>
|
2012-09-12 17:21:26 +02:00
|
|
|
|
2014-09-22 18:33:23 +02:00
|
|
|
#include "mm_gran/mm_gran.h"
|
2012-09-12 17:21:26 +02:00
|
|
|
|
|
|
|
#ifdef CONFIG_GRAN
|
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* Public Functions
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* Name: gran_enter_critical and gran_leave_critical
|
|
|
|
*
|
|
|
|
* Description:
|
|
|
|
* Critical section management for the granule allocator.
|
|
|
|
*
|
|
|
|
* Input Parameters:
|
|
|
|
* priv - Pointer to the gran state
|
|
|
|
*
|
|
|
|
* Returned Value:
|
2020-03-29 19:57:53 +02:00
|
|
|
* gran_enter_critical() may return any error reported by
|
|
|
|
* nxsem_wait_uninterruptible()
|
2012-09-12 17:21:26 +02:00
|
|
|
*
|
|
|
|
****************************************************************************/
|
|
|
|
|
2020-03-29 19:57:53 +02:00
|
|
|
int gran_enter_critical(FAR struct gran_s *priv)
|
2012-09-12 17:21:26 +02:00
|
|
|
{
|
|
|
|
#ifdef CONFIG_GRAN_INTR
|
2023-10-21 11:20:02 +02:00
|
|
|
priv->irqstate = spin_lock_irqsave(&priv->lock);
|
2020-03-29 19:57:53 +02:00
|
|
|
return OK;
|
2012-09-12 17:21:26 +02:00
|
|
|
#else
|
2022-09-06 08:18:45 +02:00
|
|
|
return nxmutex_lock(&priv->lock);
|
2012-09-12 17:21:26 +02:00
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
void gran_leave_critical(FAR struct gran_s *priv)
|
|
|
|
{
|
|
|
|
#ifdef CONFIG_GRAN_INTR
|
2023-10-21 11:20:02 +02:00
|
|
|
spin_unlock_irqrestore(&priv->lock, priv->irqstate);
|
2012-09-12 17:21:26 +02:00
|
|
|
#else
|
2022-09-06 08:18:45 +02:00
|
|
|
nxmutex_unlock(&priv->lock);
|
2012-09-12 17:21:26 +02:00
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif /* CONFIG_GRAN */
|