Use C99 array initialization, which also makes the code
self-documented, and eases addition of new ops. For the similar reasons, eliminate UMTX_OP_MAX. nitems() handles the only use of the symbol. Sponsored by: The FreeBSD Foundation MFC after: 1 week
This commit is contained in:
parent
ce8df48b73
commit
c539e87014
Notes:
svn2git
2020-12-20 02:59:44 +00:00
svn path=/head/; revision=290202
@ -3439,43 +3439,44 @@ __umtx_op_sem2_wake(struct thread *td, struct _umtx_op_args *uap)
|
|||||||
|
|
||||||
typedef int (*_umtx_op_func)(struct thread *td, struct _umtx_op_args *uap);
|
typedef int (*_umtx_op_func)(struct thread *td, struct _umtx_op_args *uap);
|
||||||
|
|
||||||
static _umtx_op_func op_table[] = {
|
static const _umtx_op_func op_table[] = {
|
||||||
__umtx_op_unimpl, /* UMTX_OP_RESERVED0 */
|
[UMTX_OP_RESERVED0] = __umtx_op_unimpl,
|
||||||
__umtx_op_unimpl, /* UMTX_OP_RESERVED1 */
|
[UMTX_OP_RESERVED1] = __umtx_op_unimpl,
|
||||||
__umtx_op_wait, /* UMTX_OP_WAIT */
|
[UMTX_OP_WAIT] = __umtx_op_wait,
|
||||||
__umtx_op_wake, /* UMTX_OP_WAKE */
|
[UMTX_OP_WAKE] = __umtx_op_wake,
|
||||||
__umtx_op_trylock_umutex, /* UMTX_OP_MUTEX_TRYLOCK */
|
[UMTX_OP_MUTEX_TRYLOCK] = __umtx_op_trylock_umutex,
|
||||||
__umtx_op_lock_umutex, /* UMTX_OP_MUTEX_LOCK */
|
[UMTX_OP_MUTEX_LOCK] = __umtx_op_lock_umutex,
|
||||||
__umtx_op_unlock_umutex, /* UMTX_OP_MUTEX_UNLOCK */
|
[UMTX_OP_MUTEX_UNLOCK] = __umtx_op_unlock_umutex,
|
||||||
__umtx_op_set_ceiling, /* UMTX_OP_SET_CEILING */
|
[UMTX_OP_SET_CEILING] = __umtx_op_set_ceiling,
|
||||||
__umtx_op_cv_wait, /* UMTX_OP_CV_WAIT*/
|
[UMTX_OP_CV_WAIT] = __umtx_op_cv_wait,
|
||||||
__umtx_op_cv_signal, /* UMTX_OP_CV_SIGNAL */
|
[UMTX_OP_CV_SIGNAL] = __umtx_op_cv_signal,
|
||||||
__umtx_op_cv_broadcast, /* UMTX_OP_CV_BROADCAST */
|
[UMTX_OP_CV_BROADCAST] = __umtx_op_cv_broadcast,
|
||||||
__umtx_op_wait_uint, /* UMTX_OP_WAIT_UINT */
|
[UMTX_OP_WAIT_UINT] = __umtx_op_wait_uint,
|
||||||
__umtx_op_rw_rdlock, /* UMTX_OP_RW_RDLOCK */
|
[UMTX_OP_RW_RDLOCK] = __umtx_op_rw_rdlock,
|
||||||
__umtx_op_rw_wrlock, /* UMTX_OP_RW_WRLOCK */
|
[UMTX_OP_RW_WRLOCK] = __umtx_op_rw_wrlock,
|
||||||
__umtx_op_rw_unlock, /* UMTX_OP_RW_UNLOCK */
|
[UMTX_OP_RW_UNLOCK] = __umtx_op_rw_unlock,
|
||||||
__umtx_op_wait_uint_private, /* UMTX_OP_WAIT_UINT_PRIVATE */
|
[UMTX_OP_WAIT_UINT_PRIVATE] = __umtx_op_wait_uint_private,
|
||||||
__umtx_op_wake_private, /* UMTX_OP_WAKE_PRIVATE */
|
[UMTX_OP_WAKE_PRIVATE] = __umtx_op_wake_private,
|
||||||
__umtx_op_wait_umutex, /* UMTX_OP_MUTEX_WAIT */
|
[UMTX_OP_MUTEX_WAIT] = __umtx_op_wait_umutex,
|
||||||
__umtx_op_wake_umutex, /* UMTX_OP_MUTEX_WAKE */
|
[UMTX_OP_MUTEX_WAKE] = __umtx_op_wake_umutex,
|
||||||
#if defined(COMPAT_FREEBSD9) || defined(COMPAT_FREEBSD10)
|
#if defined(COMPAT_FREEBSD9) || defined(COMPAT_FREEBSD10)
|
||||||
__umtx_op_sem_wait, /* UMTX_OP_SEM_WAIT */
|
[UMTX_OP_SEM_WAIT] = __umtx_op_sem_wait,
|
||||||
__umtx_op_sem_wake, /* UMTX_OP_SEM_WAKE */
|
[UMTX_OP_SEM_WAKE] = __umtx_op_sem_wake,
|
||||||
#else
|
#else
|
||||||
__umtx_op_unimpl, /* UMTX_OP_SEM_WAIT */
|
[UMTX_OP_SEM_WAIT] = __umtx_op_unimpl,
|
||||||
__umtx_op_unimpl, /* UMTX_OP_SEM_WAKE */
|
[UMTX_OP_SEM_WAKE] = __umtx_op_unimpl,
|
||||||
#endif
|
#endif
|
||||||
__umtx_op_nwake_private, /* UMTX_OP_NWAKE_PRIVATE */
|
[UMTX_OP_NWAKE_PRIVATE] = __umtx_op_nwake_private,
|
||||||
__umtx_op_wake2_umutex, /* UMTX_OP_MUTEX_WAKE2 */
|
[UMTX_OP_MUTEX_WAKE2] = __umtx_op_wake2_umutex,
|
||||||
__umtx_op_sem2_wait, /* UMTX_OP_SEM2_WAIT */
|
[UMTX_OP_SEM2_WAIT] = __umtx_op_sem2_wait,
|
||||||
__umtx_op_sem2_wake, /* UMTX_OP_SEM2_WAKE */
|
[UMTX_OP_SEM2_WAKE] = __umtx_op_sem2_wake,
|
||||||
};
|
};
|
||||||
|
|
||||||
int
|
int
|
||||||
sys__umtx_op(struct thread *td, struct _umtx_op_args *uap)
|
sys__umtx_op(struct thread *td, struct _umtx_op_args *uap)
|
||||||
{
|
{
|
||||||
if ((unsigned)uap->op < UMTX_OP_MAX)
|
|
||||||
|
if ((unsigned)uap->op < nitems(op_table))
|
||||||
return (*op_table[uap->op])(td, uap);
|
return (*op_table[uap->op])(td, uap);
|
||||||
return (EINVAL);
|
return (EINVAL);
|
||||||
}
|
}
|
||||||
@ -3734,44 +3735,46 @@ __umtx_op_nwake_private32(struct thread *td, struct _umtx_op_args *uap)
|
|||||||
}
|
}
|
||||||
|
|
||||||
static _umtx_op_func op_table_compat32[] = {
|
static _umtx_op_func op_table_compat32[] = {
|
||||||
__umtx_op_unimpl, /* UMTX_OP_RESERVED0 */
|
[UMTX_OP_RESERVED0] = __umtx_op_unimpl,
|
||||||
__umtx_op_unimpl, /* UMTX_OP_RESERVED1 */
|
[UMTX_OP_RESERVED1] = __umtx_op_unimpl,
|
||||||
__umtx_op_wait_compat32, /* UMTX_OP_WAIT */
|
[UMTX_OP_WAIT] = __umtx_op_wait_compat32,
|
||||||
__umtx_op_wake, /* UMTX_OP_WAKE */
|
[UMTX_OP_WAKE] = __umtx_op_wake,
|
||||||
__umtx_op_trylock_umutex, /* UMTX_OP_MUTEX_LOCK */
|
[UMTX_OP_MUTEX_LOCK] = __umtx_op_trylock_umutex,
|
||||||
__umtx_op_lock_umutex_compat32, /* UMTX_OP_MUTEX_TRYLOCK */
|
[UMTX_OP_MUTEX_TRYLOCK] = __umtx_op_lock_umutex_compat32,
|
||||||
__umtx_op_unlock_umutex, /* UMTX_OP_MUTEX_UNLOCK */
|
[UMTX_OP_MUTEX_UNLOCK] = __umtx_op_unlock_umutex,
|
||||||
__umtx_op_set_ceiling, /* UMTX_OP_SET_CEILING */
|
[UMTX_OP_SET_CEILING] = __umtx_op_set_ceiling,
|
||||||
__umtx_op_cv_wait_compat32, /* UMTX_OP_CV_WAIT*/
|
[UMTX_OP_CV_WAIT] = __umtx_op_cv_wait_compat32,
|
||||||
__umtx_op_cv_signal, /* UMTX_OP_CV_SIGNAL */
|
[UMTX_OP_CV_SIGNAL] = __umtx_op_cv_signal,
|
||||||
__umtx_op_cv_broadcast, /* UMTX_OP_CV_BROADCAST */
|
[UMTX_OP_CV_BROADCAST] = __umtx_op_cv_broadcast,
|
||||||
__umtx_op_wait_compat32, /* UMTX_OP_WAIT_UINT */
|
[UMTX_OP_WAIT_UINT] = __umtx_op_wait_compat32,
|
||||||
__umtx_op_rw_rdlock_compat32, /* UMTX_OP_RW_RDLOCK */
|
[UMTX_OP_RW_RDLOCK] = __umtx_op_rw_rdlock_compat32,
|
||||||
__umtx_op_rw_wrlock_compat32, /* UMTX_OP_RW_WRLOCK */
|
[UMTX_OP_RW_WRLOCK] = __umtx_op_rw_wrlock_compat32,
|
||||||
__umtx_op_rw_unlock, /* UMTX_OP_RW_UNLOCK */
|
[UMTX_OP_RW_UNLOCK] = __umtx_op_rw_unlock,
|
||||||
__umtx_op_wait_uint_private_compat32, /* UMTX_OP_WAIT_UINT_PRIVATE */
|
[UMTX_OP_WAIT_UINT_PRIVATE] = __umtx_op_wait_uint_private_compat32,
|
||||||
__umtx_op_wake_private, /* UMTX_OP_WAKE_PRIVATE */
|
[UMTX_OP_WAKE_PRIVATE] = __umtx_op_wake_private,
|
||||||
__umtx_op_wait_umutex_compat32, /* UMTX_OP_MUTEX_WAIT */
|
[UMTX_OP_MUTEX_WAIT] = __umtx_op_wait_umutex_compat32,
|
||||||
__umtx_op_wake_umutex, /* UMTX_OP_MUTEX_WAKE */
|
[UMTX_OP_MUTEX_WAKE] = __umtx_op_wake_umutex,
|
||||||
#if defined(COMPAT_FREEBSD9) || defined(COMPAT_FREEBSD10)
|
#if defined(COMPAT_FREEBSD9) || defined(COMPAT_FREEBSD10)
|
||||||
__umtx_op_sem_wait_compat32, /* UMTX_OP_SEM_WAIT */
|
[UMTX_OP_SEM_WAIT] = __umtx_op_sem_wait_compat32,
|
||||||
__umtx_op_sem_wake, /* UMTX_OP_SEM_WAKE */
|
[UMTX_OP_SEM_WAKE] = __umtx_op_sem_wake,
|
||||||
#else
|
#else
|
||||||
__umtx_op_unimpl, /* UMTX_OP_SEM_WAIT */
|
[UMTX_OP_SEM_WAIT] = __umtx_op_unimpl,
|
||||||
__umtx_op_unimpl, /* UMTX_OP_SEM_WAKE */
|
[UMTX_OP_SEM_WAKE] = __umtx_op_unimpl,
|
||||||
#endif
|
#endif
|
||||||
__umtx_op_nwake_private32, /* UMTX_OP_NWAKE_PRIVATE */
|
[UMTX_OP_NWAKE_PRIVATE] = __umtx_op_nwake_private32,
|
||||||
__umtx_op_wake2_umutex, /* UMTX_OP_MUTEX_WAKE2 */
|
[UMTX_OP_MUTEX_WAKE2] = __umtx_op_wake2_umutex,
|
||||||
__umtx_op_sem2_wait_compat32, /* UMTX_OP_SEM2_WAIT */
|
[UMTX_OP_SEM2_WAIT] = __umtx_op_sem2_wait_compat32,
|
||||||
__umtx_op_sem2_wake, /* UMTX_OP_SEM2_WAKE */
|
[UMTX_OP_SEM2_WAKE] = __umtx_op_sem2_wake,
|
||||||
};
|
};
|
||||||
|
|
||||||
int
|
int
|
||||||
freebsd32_umtx_op(struct thread *td, struct freebsd32_umtx_op_args *uap)
|
freebsd32_umtx_op(struct thread *td, struct freebsd32_umtx_op_args *uap)
|
||||||
{
|
{
|
||||||
if ((unsigned)uap->op < UMTX_OP_MAX)
|
|
||||||
|
if ((unsigned)uap->op < nitems(op_table_compat32)) {
|
||||||
return (*op_table_compat32[uap->op])(td,
|
return (*op_table_compat32[uap->op])(td,
|
||||||
(struct _umtx_op_args *)uap);
|
(struct _umtx_op_args *)uap);
|
||||||
|
}
|
||||||
return (EINVAL);
|
return (EINVAL);
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
@ -83,7 +83,6 @@
|
|||||||
#define UMTX_OP_MUTEX_WAKE2 22
|
#define UMTX_OP_MUTEX_WAKE2 22
|
||||||
#define UMTX_OP_SEM2_WAIT 23
|
#define UMTX_OP_SEM2_WAIT 23
|
||||||
#define UMTX_OP_SEM2_WAKE 24
|
#define UMTX_OP_SEM2_WAKE 24
|
||||||
#define UMTX_OP_MAX 25
|
|
||||||
|
|
||||||
/* Flags for UMTX_OP_CV_WAIT */
|
/* Flags for UMTX_OP_CV_WAIT */
|
||||||
#define CVWAIT_CHECK_UNPARKING 0x01
|
#define CVWAIT_CHECK_UNPARKING 0x01
|
||||||
|
Loading…
Reference in New Issue
Block a user