Skip site navigation (1)Skip section navigation (2)
Date:      Sun, 23 Jul 2017 20:35:27 +0000 (UTC)
From:      Vladimir Kondratyev <wulf@FreeBSD.org>
To:        src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org
Subject:   svn commit: r321398 - head/sys/dev/evdev
Message-ID:  <201707232035.v6NKZRm8095812@repo.freebsd.org>

next in thread | raw e-mail | index | archive | help
Author: wulf
Date: Sun Jul 23 20:35:26 2017
New Revision: 321398
URL: https://svnweb.freebsd.org/changeset/base/321398

Log:
  evdev: Macroize common locking sequences
  
  Reviewed by:	gonzo
  Approved by:	gonzo (mentor)
  MFC after:	2 weeks

Modified:
  head/sys/dev/evdev/evdev.c
  head/sys/dev/evdev/evdev_mt.c
  head/sys/dev/evdev/evdev_private.h

Modified: head/sys/dev/evdev/evdev.c
==============================================================================
--- head/sys/dev/evdev/evdev.c	Sun Jul 23 20:32:54 2017	(r321397)
+++ head/sys/dev/evdev/evdev.c	Sun Jul 23 20:35:26 2017	(r321398)
@@ -757,14 +757,11 @@ evdev_push_event(struct evdev_dev *evdev, uint16_t typ
     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 typ
 	    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);
 }

Modified: head/sys/dev/evdev/evdev_mt.c
==============================================================================
--- head/sys/dev/evdev/evdev_mt.c	Sun Jul 23 20:32:54 2017	(r321397)
+++ head/sys/dev/evdev/evdev_mt.c	Sun Jul 23 20:35:26 2017	(r321398)
@@ -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

Modified: head/sys/dev/evdev/evdev_private.h
==============================================================================
--- head/sys/dev/evdev/evdev_private.h	Sun Jul 23 20:32:54 2017	(r321397)
+++ head/sys/dev/evdev/evdev_private.h	Sun Jul 23 20:35:26 2017	(r321398)
@@ -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
 {



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?201707232035.v6NKZRm8095812>