mirror of
https://github.com/apache/nuttx.git
synced 2025-01-12 23:18:36 +08:00
add spinlock_type.h
reason: Due to incomplete handling of spinlock_t in arch/spinlock.h, it should not be used directly by external code. Furthermore, because pthread.h and nuttx/spinlock.h have a circular dependency, pthread.h cannot successfully include nuttx/spinlock.h. Therefore, we have split spinlock_type.h from spinlock.h. Signed-off-by: hujun5 <hujun5@xiaomi.com>
This commit is contained in:
parent
f1a57f4265
commit
fe2af95222
3 changed files with 93 additions and 45 deletions
|
@ -41,6 +41,8 @@
|
|||
# include <nuttx/atomic.h>
|
||||
#endif
|
||||
|
||||
#include <nuttx/spinlock_type.h>
|
||||
|
||||
#undef EXTERN
|
||||
#if defined(__cplusplus)
|
||||
#define EXTERN extern "C"
|
||||
|
@ -50,50 +52,6 @@ extern "C"
|
|||
#define EXTERN extern
|
||||
#endif
|
||||
|
||||
#if defined(CONFIG_RW_SPINLOCK)
|
||||
typedef int rwlock_t;
|
||||
# define RW_SP_UNLOCKED 0
|
||||
# define RW_SP_READ_LOCKED 1
|
||||
# define RW_SP_WRITE_LOCKED -1
|
||||
#endif
|
||||
|
||||
#ifndef CONFIG_SPINLOCK
|
||||
# define SP_UNLOCKED 0 /* The Un-locked state */
|
||||
# define SP_LOCKED 1 /* The Locked state */
|
||||
|
||||
typedef uint8_t spinlock_t;
|
||||
#elif defined(CONFIG_TICKET_SPINLOCK)
|
||||
|
||||
union spinlock_u
|
||||
{
|
||||
struct
|
||||
{
|
||||
unsigned short owner;
|
||||
unsigned short next;
|
||||
} tickets;
|
||||
unsigned int value;
|
||||
};
|
||||
typedef union spinlock_u spinlock_t;
|
||||
|
||||
# define SP_UNLOCKED (union spinlock_u){{0, 0}}
|
||||
# define SP_LOCKED (union spinlock_u){{0, 1}}
|
||||
|
||||
#else
|
||||
|
||||
/* 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 be constants of type spinlock_t.
|
||||
*/
|
||||
|
||||
#include <arch/spinlock.h>
|
||||
|
||||
#endif /* CONFIG_SPINLOCK */
|
||||
|
||||
/****************************************************************************
|
||||
* Pre-processor Definitions
|
||||
****************************************************************************/
|
||||
|
|
90
include/nuttx/spinlock_type.h
Normal file
90
include/nuttx/spinlock_type.h
Normal file
|
@ -0,0 +1,90 @@
|
|||
/****************************************************************************
|
||||
* include/nuttx/spinlock_type.h
|
||||
*
|
||||
* 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.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
#ifndef __INCLUDE_NUTTX_SPINLOCK_TYPE_H
|
||||
#define __INCLUDE_NUTTX_SPINLOCK_TYPE_H
|
||||
|
||||
/****************************************************************************
|
||||
* Included Files
|
||||
****************************************************************************/
|
||||
|
||||
#include <nuttx/config.h>
|
||||
|
||||
#undef EXTERN
|
||||
#if defined(__cplusplus)
|
||||
#define EXTERN extern "C"
|
||||
extern "C"
|
||||
{
|
||||
#else
|
||||
#define EXTERN extern
|
||||
#endif
|
||||
|
||||
#if defined(CONFIG_RW_SPINLOCK)
|
||||
typedef int rwlock_t;
|
||||
# define RW_SP_UNLOCKED 0
|
||||
# define RW_SP_READ_LOCKED 1
|
||||
# define RW_SP_WRITE_LOCKED -1
|
||||
#endif
|
||||
|
||||
#ifndef CONFIG_SPINLOCK
|
||||
# define SP_UNLOCKED 0 /* The Un-locked state */
|
||||
# define SP_LOCKED 1 /* The Locked state */
|
||||
|
||||
typedef uint8_t spinlock_t;
|
||||
#elif defined(CONFIG_TICKET_SPINLOCK)
|
||||
|
||||
union spinlock_u
|
||||
{
|
||||
struct
|
||||
{
|
||||
unsigned short owner;
|
||||
unsigned short next;
|
||||
} tickets;
|
||||
unsigned int value;
|
||||
};
|
||||
typedef union spinlock_u spinlock_t;
|
||||
|
||||
# define SP_UNLOCKED (union spinlock_u){{0, 0}}
|
||||
# define SP_LOCKED (union spinlock_u){{0, 1}}
|
||||
|
||||
#else
|
||||
|
||||
/* 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 be constants of type spinlock_t.
|
||||
*/
|
||||
|
||||
#include <arch/spinlock.h>
|
||||
|
||||
#endif /* CONFIG_SPINLOCK */
|
||||
|
||||
#undef EXTERN
|
||||
#if defined(__cplusplus)
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* __INCLUDE_NUTTX_SPINLOCK_TYPE_H */
|
|
@ -49,7 +49,7 @@
|
|||
* SP_LOCKED and SP_UNLOCKED must constants of type spinlock_t.
|
||||
*/
|
||||
|
||||
# include <arch/spinlock.h>
|
||||
# include <nuttx/spinlock_type.h>
|
||||
#endif
|
||||
|
||||
/****************************************************************************
|
||||
|
|
Loading…
Reference in a new issue