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
|
|
|
*
|
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
|
2016-02-14 15:57:01 +01:00
|
|
|
priv->irqstate = enter_critical_section();
|
2020-03-29 19:57:53 +02:00
|
|
|
return OK;
|
2012-09-12 17:21:26 +02:00
|
|
|
#else
|
2020-03-29 19:57:53 +02:00
|
|
|
return nxsem_wait_uninterruptible(&priv->exclsem);
|
2012-09-12 17:21:26 +02:00
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
void gran_leave_critical(FAR struct gran_s *priv)
|
|
|
|
{
|
|
|
|
#ifdef CONFIG_GRAN_INTR
|
2016-02-14 15:57:01 +01:00
|
|
|
leave_critical_section(priv->irqstate);
|
2012-09-12 17:21:26 +02:00
|
|
|
#else
|
2017-10-03 23:35:24 +02:00
|
|
|
nxsem_post(&priv->exclsem);
|
2012-09-12 17:21:26 +02:00
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif /* CONFIG_GRAN */
|