2012-09-12 23:21:26 +08:00
|
|
|
/****************************************************************************
|
2014-09-23 00:33:23 +08:00
|
|
|
* mm/mm_gran/mm_grancritical.c
|
2012-09-12 23:21:26 +08:00
|
|
|
*
|
2020-03-30 01:57:53 +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
|
2012-09-12 23:21:26 +08:00
|
|
|
*
|
2020-03-30 01:57:53 +08:00
|
|
|
* http://www.apache.org/licenses/LICENSE-2.0
|
2012-09-12 23:21:26 +08:00
|
|
|
*
|
2020-03-30 01:57:53 +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.
|
2012-09-12 23:21:26 +08:00
|
|
|
*
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* Included Files
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
#include <nuttx/config.h>
|
|
|
|
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <assert.h>
|
|
|
|
#include <errno.h>
|
|
|
|
|
2016-02-14 22:57:01 +08:00
|
|
|
#include <nuttx/irq.h>
|
2014-09-24 20:55:26 +08:00
|
|
|
#include <nuttx/mm/gran.h>
|
2012-09-12 23:21:26 +08:00
|
|
|
|
2014-09-23 00:33:23 +08:00
|
|
|
#include "mm_gran/mm_gran.h"
|
2012-09-12 23:21:26 +08: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-30 01:57:53 +08:00
|
|
|
* gran_enter_critical() may return any error reported by
|
|
|
|
* nxsem_wait_uninterruptible()
|
2012-09-12 23:21:26 +08:00
|
|
|
*
|
|
|
|
****************************************************************************/
|
|
|
|
|
2020-03-30 01:57:53 +08:00
|
|
|
int gran_enter_critical(FAR struct gran_s *priv)
|
2012-09-12 23:21:26 +08:00
|
|
|
{
|
|
|
|
#ifdef CONFIG_GRAN_INTR
|
2016-02-14 22:57:01 +08:00
|
|
|
priv->irqstate = enter_critical_section();
|
2020-03-30 01:57:53 +08:00
|
|
|
return OK;
|
2012-09-12 23:21:26 +08:00
|
|
|
#else
|
2022-09-06 14:18:45 +08:00
|
|
|
return nxmutex_lock(&priv->lock);
|
2012-09-12 23:21:26 +08:00
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
void gran_leave_critical(FAR struct gran_s *priv)
|
|
|
|
{
|
|
|
|
#ifdef CONFIG_GRAN_INTR
|
2016-02-14 22:57:01 +08:00
|
|
|
leave_critical_section(priv->irqstate);
|
2012-09-12 23:21:26 +08:00
|
|
|
#else
|
2022-09-06 14:18:45 +08:00
|
|
|
nxmutex_unlock(&priv->lock);
|
2012-09-12 23:21:26 +08:00
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif /* CONFIG_GRAN */
|