Add basic support for spinlocks (not currently used by anything)
This commit is contained in:
parent
7aa237973c
commit
b022f1e9d8
@ -11469,3 +11469,8 @@
|
|||||||
* include/nuttx/net/arp.h, include/nuttx/net/ioctl.h, net/netdev/netdev_ioctl.c,
|
* include/nuttx/net/arp.h, include/nuttx/net/ioctl.h, net/netdev/netdev_ioctl.c,
|
||||||
and ARP-related files: Add support for IOCTL commands to manage the
|
and ARP-related files: Add support for IOCTL commands to manage the
|
||||||
ARP table (2016-02-08).
|
ARP table (2016-02-08).
|
||||||
|
* ARMv7-A, ARMv7-R, and ARMv7-A: Add test-and-set logic and definitions
|
||||||
|
needed to supports spinlocks (2016-02-09).
|
||||||
|
* include/nuttx/spinlock.h: Add basic definitions for spinlocks. Not yet
|
||||||
|
used by NuttX (2016-02-09).
|
||||||
|
|
||||||
|
2
arch
2
arch
@ -1 +1 @@
|
|||||||
Subproject commit 5c9c3dc73e2ae5e87203801c6ab82e44a3f8fbec
|
Subproject commit 958e4d09fc413d88893881eee612d901b779e057
|
2
configs
2
configs
@ -1 +1 @@
|
|||||||
Subproject commit df66c8b70c69689c9adf46c5d8188c9a5613e2e5
|
Subproject commit 05856eb712badecadbdbd7803c868ebd0b2de451
|
102
include/nuttx/spinlock.h
Normal file
102
include/nuttx/spinlock.h
Normal file
@ -0,0 +1,102 @@
|
|||||||
|
/****************************************************************************
|
||||||
|
* include/nuttx/spinlock.h
|
||||||
|
*
|
||||||
|
* Copyright (C) 2016 Gregory Nutt. All rights reserved.
|
||||||
|
* Author: Gregory Nutt <gnutt@nuttx.org>
|
||||||
|
*
|
||||||
|
* Redistribution and use in source and binary forms, with or without
|
||||||
|
* modification, are permitted provided that the following conditions
|
||||||
|
* are met:
|
||||||
|
*
|
||||||
|
* 1. Redistributions of source code must retain the above copyright
|
||||||
|
* notice, this list of conditions and the following disclaimer.
|
||||||
|
* 2. Redistributions in binary form must reproduce the above copyright
|
||||||
|
* notice, this list of conditions and the following disclaimer in
|
||||||
|
* the documentation and/or other materials provided with the
|
||||||
|
* distribution.
|
||||||
|
* 3. Neither the name NuttX nor the names of its contributors may be
|
||||||
|
* used to endorse or promote products derived from this software
|
||||||
|
* without specific prior written permission.
|
||||||
|
*
|
||||||
|
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||||
|
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||||
|
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
|
||||||
|
* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
|
||||||
|
* COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
|
||||||
|
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
|
||||||
|
* BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
|
||||||
|
* OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
|
||||||
|
* AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||||
|
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
|
||||||
|
* ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||||
|
* POSSIBILITY OF SUCH DAMAGE.
|
||||||
|
*
|
||||||
|
****************************************************************************/
|
||||||
|
|
||||||
|
#ifndef __INCLUDE_NUTTX_SPINLOCK_H
|
||||||
|
#define __INCLUDE_NUTTX_SPINLOCK_H
|
||||||
|
|
||||||
|
/****************************************************************************
|
||||||
|
* Included Files
|
||||||
|
****************************************************************************/
|
||||||
|
|
||||||
|
#include <nuttx/config.h>
|
||||||
|
#include <sched.h>
|
||||||
|
|
||||||
|
/* The architecture specific spinlock.h header file must also provide the
|
||||||
|
* following:
|
||||||
|
*
|
||||||
|
* SP_LOCKED - A definition of the locked state value (usually 1)
|
||||||
|
* SP_UNLOCKED - A definition of the unlocked state value (usually 0)
|
||||||
|
* spinlock_t - The type of a spinlock memory object.
|
||||||
|
*
|
||||||
|
* SP_LOCKED and SP_UNLOCKED must constants of type spinlock_t.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include <arch/spinlock.h>
|
||||||
|
|
||||||
|
/****************************************************************************
|
||||||
|
* Public Function Prototypes
|
||||||
|
****************************************************************************/
|
||||||
|
|
||||||
|
/****************************************************************************
|
||||||
|
* Name: up_testset
|
||||||
|
*
|
||||||
|
* Description:
|
||||||
|
* Perform and atomic test and set operation on the provided spinlock.
|
||||||
|
*
|
||||||
|
* This function must be provided via the architecture-specific logoic.
|
||||||
|
*
|
||||||
|
* Input Parameters:
|
||||||
|
* lock - The address of spinlock object.
|
||||||
|
*
|
||||||
|
* Returned Value:
|
||||||
|
* The spinlock is always locked upon return. The value of previous value
|
||||||
|
* of the spinlock variable is returned, either SP_LOCKED if the spinlock
|
||||||
|
* as previously locked (meaning that the test-and-set operation failed to
|
||||||
|
* obtain the lock) or SP_UNLOCKED if the spinlock was previously unlocked
|
||||||
|
* (meaning that we successfully obtained the lock)
|
||||||
|
*
|
||||||
|
****************************************************************************/
|
||||||
|
|
||||||
|
spinlock_t up_testset(FAR spinlock_t *lock);
|
||||||
|
|
||||||
|
/****************************************************************************
|
||||||
|
* Name: spinlock
|
||||||
|
*
|
||||||
|
* Description:
|
||||||
|
* Loop until the spinlock is successfully locked.
|
||||||
|
*
|
||||||
|
* Input Parameters:
|
||||||
|
* lock - The address of spinlock object.
|
||||||
|
*
|
||||||
|
* Returned Value:
|
||||||
|
* None. When the function returned, the spinlocked was successfully
|
||||||
|
* locked by this CPU.
|
||||||
|
*
|
||||||
|
****************************************************************************/
|
||||||
|
|
||||||
|
#define spinlock(l) while (up_testset(l) == SP_LOCKED) (void)sched_yield()
|
||||||
|
|
||||||
|
#endif /* CONFIG_SIG_EVTHREAD && CONFIG_BUILD_FLAT */
|
||||||
|
#endif /* __INCLUDE_NUTTX_SPINLOCK_H */
|
Loading…
Reference in New Issue
Block a user