evdev: Macroize common locking sequences

Reviewed by:	gonzo
Approved by:	gonzo (mentor)
MFC after:	2 weeks
This commit is contained in:
Vladimir Kondratyev 2017-07-23 20:35:26 +00:00
parent ea2e26b1ed
commit 4c0a4665b8
3 changed files with 18 additions and 19 deletions

View File

@ -757,14 +757,11 @@ evdev_push_event(struct evdev_dev *evdev, uint16_t type, uint16_t code,
int32_t value)
{
if (evdev->ev_lock_type != EV_LOCK_INTERNAL)
EVDEV_LOCK_ASSERT(evdev);
if (evdev_check_event(evdev, type, code, value) != 0)
return (EINVAL);
if (evdev->ev_lock_type == EV_LOCK_INTERNAL)
EVDEV_LOCK(evdev);
EVDEV_ENTER(evdev);
evdev_modify_event(evdev, type, code, &value);
if (type == EV_SYN && code == SYN_REPORT &&
bit_test(evdev->ev_flags, EVDEV_FLAG_MT_AUTOREL))
@ -773,8 +770,8 @@ evdev_push_event(struct evdev_dev *evdev, uint16_t type, uint16_t code,
bit_test(evdev->ev_flags, EVDEV_FLAG_MT_STCOMPAT))
evdev_send_mt_compat(evdev);
evdev_send_event(evdev, type, code, value);
if (evdev->ev_lock_type == EV_LOCK_INTERNAL)
EVDEV_UNLOCK(evdev);
EVDEV_EXIT(evdev);
return (0);
}

View File

@ -224,13 +224,9 @@ void
evdev_push_nfingers(struct evdev_dev *evdev, int32_t nfingers)
{
if (evdev->ev_lock_type == EV_LOCK_INTERNAL)
EVDEV_LOCK(evdev);
else
EVDEV_LOCK_ASSERT(evdev);
EVDEV_ENTER(evdev);
evdev_send_nfingers(evdev, nfingers);
if (evdev->ev_lock_type == EV_LOCK_INTERNAL)
EVDEV_UNLOCK(evdev);
EVDEV_EXIT(evdev);
}
void
@ -264,13 +260,9 @@ void
evdev_push_mt_compat(struct evdev_dev *evdev)
{
if (evdev->ev_lock_type == EV_LOCK_INTERNAL)
EVDEV_LOCK(evdev);
else
EVDEV_LOCK_ASSERT(evdev);
EVDEV_ENTER(evdev);
evdev_send_mt_compat(evdev);
if (evdev->ev_lock_type == EV_LOCK_INTERNAL)
EVDEV_UNLOCK(evdev);
EVDEV_EXIT(evdev);
}
void

View File

@ -135,6 +135,16 @@ struct evdev_dev
#define EVDEV_LOCK(evdev) mtx_lock((evdev)->ev_lock)
#define EVDEV_UNLOCK(evdev) mtx_unlock((evdev)->ev_lock)
#define EVDEV_LOCK_ASSERT(evdev) mtx_assert((evdev)->ev_lock, MA_OWNED)
#define EVDEV_ENTER(evdev) do { \
if ((evdev)->ev_lock_type == EV_LOCK_INTERNAL) \
EVDEV_LOCK(evdev); \
else \
EVDEV_LOCK_ASSERT(evdev); \
} while (0)
#define EVDEV_EXIT(evdev) do { \
if ((evdev)->ev_lock_type == EV_LOCK_INTERNAL) \
EVDEV_UNLOCK(evdev); \
} while (0)
struct evdev_client
{