| /**************************************************************************** |
| * sched/irq/irq_spinlock.c |
| * |
| * SPDX-License-Identifier: Apache-2.0 |
| * |
| * 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 |
| * |
| * http://www.apache.org/licenses/LICENSE-2.0 |
| * |
| * 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. |
| * |
| ****************************************************************************/ |
| |
| /**************************************************************************** |
| * Included Files |
| ****************************************************************************/ |
| |
| #include <nuttx/config.h> |
| #include <nuttx/spinlock.h> |
| |
| #include <assert.h> |
| #include <sys/types.h> |
| #include <arch/irq.h> |
| |
| #include "sched/sched.h" |
| |
| #if defined(CONFIG_SPINLOCK) |
| |
| /**************************************************************************** |
| * Public Data |
| ****************************************************************************/ |
| |
| /**************************************************************************** |
| * Public Functions |
| ****************************************************************************/ |
| |
| #ifdef CONFIG_RW_SPINLOCK |
| |
| /**************************************************************************** |
| * Name: read_lock_irqsave |
| * |
| * Description: |
| * If SMP is enabled: |
| * The argument lock should be specified, |
| * disable local interrupts and take the lock spinlock and return |
| * the interrupt state. |
| * |
| * NOTE: This API is very simple to protect data (e.g. H/W register |
| * or internal data structure) in SMP mode. Do not use this API |
| * with kernel APIs which suspend a caller thread. (e.g. nxsem_wait) |
| * |
| * If SMP is not enabled: |
| * This function is equivalent to up_irq_save(). |
| * |
| * Input Parameters: |
| * lock - Caller specific spinlock, not NULL. |
| * |
| * Returned Value: |
| * An opaque, architecture-specific value that represents the state of |
| * the interrupts prior to the call to write_lock_irqsave(lock); |
| * |
| ****************************************************************************/ |
| |
| irqstate_t read_lock_irqsave(FAR rwlock_t *lock) |
| { |
| irqstate_t ret; |
| ret = up_irq_save(); |
| |
| read_lock(lock); |
| |
| return ret; |
| } |
| |
| /**************************************************************************** |
| * Name: read_unlock_irqrestore |
| * |
| * Description: |
| * If SMP is enabled: |
| * The argument lock should be specified, release the lock and |
| * restore the interrupt state as it was prior to the previous call to |
| * read_lock_irqsave(lock). |
| * |
| * If SMP is not enabled: |
| * This function is equivalent to up_irq_restore(). |
| * |
| * Input Parameters: |
| * lock - Caller specific spinlock, not NULL. |
| * |
| * flags - The architecture-specific value that represents the state of |
| * the interrupts prior to the call to read_lock_irqsave(lock); |
| * |
| * Returned Value: |
| * None |
| * |
| ****************************************************************************/ |
| |
| void read_unlock_irqrestore(rwlock_t *lock, irqstate_t flags) |
| { |
| read_unlock(lock); |
| up_irq_restore(flags); |
| } |
| |
| /**************************************************************************** |
| * Name: write_lock_irqsave |
| * |
| * Description: |
| * If SMP is enabled: |
| * The argument lock should be specified, |
| * disable local interrupts and take the lock spinlock and return |
| * the interrupt state. |
| * |
| * NOTE: This API is very simple to protect data (e.g. H/W register |
| * or internal data structure) in SMP mode. But do not use this API |
| * with kernel APIs which suspend a caller thread. (e.g. nxsem_wait) |
| * |
| * If SMP is not enabled: |
| * This function is equivalent to up_irq_save(). |
| * |
| * Input Parameters: |
| * lock - Caller specific spinlock, not NULL. |
| * |
| * Returned Value: |
| * An opaque, architecture-specific value that represents the state of |
| * the interrupts prior to the call to write_lock_irqsave(lock); |
| * |
| ****************************************************************************/ |
| |
| irqstate_t write_lock_irqsave(rwlock_t *lock) |
| { |
| irqstate_t ret; |
| ret = up_irq_save(); |
| |
| write_lock(lock); |
| |
| return ret; |
| } |
| |
| /**************************************************************************** |
| * Name: write_unlock_irqrestore |
| * |
| * Description: |
| * If SMP is enabled: |
| * The argument lock should be specified, release the lock and |
| * restore the interrupt state as it was prior to the previous call to |
| * write_lock_irqsave(lock). |
| * |
| * If SMP is not enabled: |
| * This function is equivalent to up_irq_restore(). |
| * |
| * Input Parameters: |
| * lock - Caller specific spinlock, not NULL. |
| * |
| * flags - The architecture-specific value that represents the state of |
| * the interrupts prior to the call to write_lock_irqsave(lock); |
| * |
| * Returned Value: |
| * None |
| * |
| ****************************************************************************/ |
| |
| void write_unlock_irqrestore(rwlock_t *lock, irqstate_t flags) |
| { |
| write_unlock(lock); |
| |
| up_irq_restore(flags); |
| } |
| #endif /* CONFIG_RW_SPINLOCK */ |
| #endif /* CONFIG_SPINLOCK */ |