diff --git a/ChangeLog b/ChangeLog index 44e9c3cc683..36077eb2d42 100755 --- a/ChangeLog +++ b/ChangeLog @@ -11469,3 +11469,8 @@ * 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 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). + diff --git a/arch b/arch index 5c9c3dc73e2..958e4d09fc4 160000 --- a/arch +++ b/arch @@ -1 +1 @@ -Subproject commit 5c9c3dc73e2ae5e87203801c6ab82e44a3f8fbec +Subproject commit 958e4d09fc413d88893881eee612d901b779e057 diff --git a/configs b/configs index df66c8b70c6..05856eb712b 160000 --- a/configs +++ b/configs @@ -1 +1 @@ -Subproject commit df66c8b70c69689c9adf46c5d8188c9a5613e2e5 +Subproject commit 05856eb712badecadbdbd7803c868ebd0b2de451 diff --git a/include/nuttx/spinlock.h b/include/nuttx/spinlock.h new file mode 100644 index 00000000000..b58d7568bed --- /dev/null +++ b/include/nuttx/spinlock.h @@ -0,0 +1,102 @@ +/**************************************************************************** + * include/nuttx/spinlock.h + * + * Copyright (C) 2016 Gregory Nutt. All rights reserved. + * Author: Gregory Nutt + * + * 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 +#include + +/* 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 + +/**************************************************************************** + * 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 */