mirror of
https://git.FreeBSD.org/src.git
synced 2024-12-04 09:09:56 +00:00
Allow using of driver's mutex instead internal one for evdev locking.
Add new API call: evdev_register_mtx which takes lock argument that should be used instead of internal one for evdev locking. Useful for cases if evdev_push_event() is always called with driver's lock taken and reduces amount of lock aquisitions. This allows to avoid LOR between ev_open/ev_close invocations and evdev_push_event() Such LOR can happen when ev_open/ev_close methods acquire driver lock and evdev_push_event() is called with this lock taken. Submitted by: Vladimir Kondratiev <wulf@cicgroup.ru>
This commit is contained in:
parent
ccb890b548
commit
bfbd1bb744
Notes:
svn2git
2020-12-20 02:59:44 +00:00
svn path=/head/; revision=306855
@ -187,8 +187,8 @@ evdev_estimate_report_size(struct evdev_dev *evdev)
|
||||
return (size);
|
||||
}
|
||||
|
||||
int
|
||||
evdev_register(struct evdev_dev *evdev)
|
||||
static int
|
||||
evdev_register_common(struct evdev_dev *evdev)
|
||||
{
|
||||
int ret;
|
||||
|
||||
@ -196,7 +196,6 @@ evdev_register(struct evdev_dev *evdev)
|
||||
evdev->ev_shortname, evdev->ev_name, evdev->ev_serial);
|
||||
|
||||
/* Initialize internal structures */
|
||||
mtx_init(&evdev->ev_mtx, "evmtx", NULL, MTX_DEF);
|
||||
LIST_INIT(&evdev->ev_clients);
|
||||
|
||||
if (evdev_event_supported(evdev, EV_REP) &&
|
||||
@ -228,12 +227,34 @@ evdev_register(struct evdev_dev *evdev)
|
||||
/* Create char device node */
|
||||
ret = evdev_cdev_create(evdev);
|
||||
bail_out:
|
||||
return (ret);
|
||||
}
|
||||
|
||||
int
|
||||
evdev_register(struct evdev_dev *evdev)
|
||||
{
|
||||
int ret;
|
||||
|
||||
evdev->ev_lock_type = EV_LOCK_INTERNAL;
|
||||
evdev->ev_lock = &evdev->ev_mtx;
|
||||
mtx_init(&evdev->ev_mtx, "evmtx", NULL, MTX_DEF);
|
||||
|
||||
ret = evdev_register_common(evdev);
|
||||
if (ret != 0)
|
||||
mtx_destroy(&evdev->ev_mtx);
|
||||
|
||||
return (ret);
|
||||
}
|
||||
|
||||
int
|
||||
evdev_register_mtx(struct evdev_dev *evdev, struct mtx *mtx)
|
||||
{
|
||||
|
||||
evdev->ev_lock_type = EV_LOCK_MTX;
|
||||
evdev->ev_lock = mtx;
|
||||
return (evdev_register_common(evdev));
|
||||
}
|
||||
|
||||
int
|
||||
evdev_unregister(struct evdev_dev *evdev)
|
||||
{
|
||||
@ -257,7 +278,7 @@ evdev_unregister(struct evdev_dev *evdev)
|
||||
/* destroy_dev can sleep so release lock */
|
||||
ret = evdev_cdev_destroy(evdev);
|
||||
evdev->ev_cdev = NULL;
|
||||
if (ret == 0)
|
||||
if (ret == 0 && evdev->ev_lock_type == EV_LOCK_INTERNAL)
|
||||
mtx_destroy(&evdev->ev_mtx);
|
||||
|
||||
evdev_free_absinfo(evdev->ev_absinfo);
|
||||
@ -735,16 +756,21 @@ 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);
|
||||
|
||||
EVDEV_LOCK(evdev);
|
||||
if (evdev->ev_lock_type == EV_LOCK_INTERNAL)
|
||||
EVDEV_LOCK(evdev);
|
||||
evdev_modify_event(evdev, type, code, &value);
|
||||
if (type == EV_SYN && code == SYN_REPORT && evdev->ev_report_opened &&
|
||||
bit_test(evdev->ev_flags, EVDEV_FLAG_MT_STCOMPAT))
|
||||
evdev_send_mt_compat(evdev);
|
||||
evdev_send_event(evdev, type, code, value);
|
||||
EVDEV_UNLOCK(evdev);
|
||||
if (evdev->ev_lock_type == EV_LOCK_INTERNAL)
|
||||
EVDEV_UNLOCK(evdev);
|
||||
|
||||
return (0);
|
||||
}
|
||||
|
@ -92,6 +92,7 @@ void evdev_set_serial(struct evdev_dev *, const char *);
|
||||
void evdev_set_methods(struct evdev_dev *, void *,
|
||||
const struct evdev_methods *);
|
||||
int evdev_register(struct evdev_dev *);
|
||||
int evdev_register_mtx(struct evdev_dev *, struct mtx *);
|
||||
int evdev_unregister(struct evdev_dev *);
|
||||
int evdev_push_event(struct evdev_dev *, uint16_t, uint16_t, int32_t);
|
||||
int evdev_sync(struct evdev_dev *);
|
||||
|
@ -227,9 +227,13 @@ void
|
||||
evdev_push_nfingers(struct evdev_dev *evdev, int32_t nfingers)
|
||||
{
|
||||
|
||||
EVDEV_LOCK(evdev);
|
||||
if (evdev->ev_lock_type == EV_LOCK_INTERNAL)
|
||||
EVDEV_LOCK(evdev);
|
||||
else
|
||||
EVDEV_LOCK_ASSERT(evdev);
|
||||
evdev_send_nfingers(evdev, nfingers);
|
||||
EVDEV_UNLOCK(evdev);
|
||||
if (evdev->ev_lock_type == EV_LOCK_INTERNAL)
|
||||
EVDEV_UNLOCK(evdev);
|
||||
}
|
||||
|
||||
void
|
||||
@ -263,7 +267,11 @@ void
|
||||
evdev_push_mt_compat(struct evdev_dev *evdev)
|
||||
{
|
||||
|
||||
EVDEV_LOCK(evdev);
|
||||
if (evdev->ev_lock_type == EV_LOCK_INTERNAL)
|
||||
EVDEV_LOCK(evdev);
|
||||
else
|
||||
EVDEV_LOCK_ASSERT(evdev);
|
||||
evdev_send_mt_compat(evdev);
|
||||
EVDEV_UNLOCK(evdev);
|
||||
if (evdev->ev_lock_type == EV_LOCK_INTERNAL)
|
||||
EVDEV_UNLOCK(evdev);
|
||||
}
|
||||
|
@ -71,6 +71,12 @@ enum evdev_clock_id
|
||||
EV_CLOCK_BOOTTIME /* monotonic, suspend-awared */
|
||||
};
|
||||
|
||||
enum evdev_lock_type
|
||||
{
|
||||
EV_LOCK_INTERNAL = 0, /* Internal evdev mutex */
|
||||
EV_LOCK_MTX, /* Driver`s mutex */
|
||||
};
|
||||
|
||||
struct evdev_dev
|
||||
{
|
||||
char ev_name[NAMELEN];
|
||||
@ -78,6 +84,8 @@ struct evdev_dev
|
||||
char ev_serial[NAMELEN];
|
||||
struct cdev * ev_cdev;
|
||||
int ev_unit;
|
||||
enum evdev_lock_type ev_lock_type;
|
||||
struct mtx * ev_lock;
|
||||
struct mtx ev_mtx;
|
||||
struct input_id ev_id;
|
||||
struct evdev_client * ev_grabber;
|
||||
@ -123,9 +131,9 @@ struct evdev_dev
|
||||
LIST_HEAD(, evdev_client) ev_clients;
|
||||
};
|
||||
|
||||
#define EVDEV_LOCK(evdev) mtx_lock(&(evdev)->ev_mtx)
|
||||
#define EVDEV_UNLOCK(evdev) mtx_unlock(&(evdev)->ev_mtx)
|
||||
#define EVDEV_LOCK_ASSERT(evdev) mtx_assert(&(evdev)->ev_mtx, MA_OWNED)
|
||||
#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)
|
||||
|
||||
struct evdev_client
|
||||
{
|
||||
|
Loading…
Reference in New Issue
Block a user