Source-Changes-HG archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
[src/trunk]: src/sys Add a function to compare 2 devhandles.
details: https://anonhg.NetBSD.org/src/rev/9e8a72380193
branches: trunk
changeset: 359778:9e8a72380193
user: thorpej <thorpej%NetBSD.org@localhost>
date: Sat Jan 22 11:58:15 2022 +0000
description:
Add a function to compare 2 devhandles.
diffstat:
sys/kern/subr_device.c | 47 +++++++++++++++++++++++++++++++++++++++++++++--
sys/sys/device.h | 3 ++-
2 files changed, 47 insertions(+), 3 deletions(-)
diffs (85 lines):
diff -r 1302f9988e2e -r 9e8a72380193 sys/kern/subr_device.c
--- a/sys/kern/subr_device.c Sat Jan 22 11:49:16 2022 +0000
+++ b/sys/kern/subr_device.c Sat Jan 22 11:58:15 2022 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: subr_device.c,v 1.10 2022/01/21 15:55:36 thorpej Exp $ */
+/* $NetBSD: subr_device.c,v 1.11 2022/01/22 11:58:15 thorpej Exp $ */
/*
* Copyright (c) 2006, 2021 The NetBSD Foundation, Inc.
@@ -27,7 +27,7 @@
*/
#include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: subr_device.c,v 1.10 2022/01/21 15:55:36 thorpej Exp $");
+__KERNEL_RCSID(0, "$NetBSD: subr_device.c,v 1.11 2022/01/22 11:58:15 thorpej Exp $");
#include <sys/param.h>
#include <sys/device.h>
@@ -77,6 +77,49 @@
return handle.impl->type;
}
+int
+devhandle_compare(devhandle_t handle1, devhandle_t handle2)
+{
+ devhandle_type_t type1 = devhandle_type(handle1);
+ devhandle_type_t type2 = devhandle_type(handle2);
+
+ if (type1 == DEVHANDLE_TYPE_INVALID) {
+ return -1;
+ }
+ if (type2 == DEVHANDLE_TYPE_INVALID) {
+ return 1;
+ }
+
+ if (type1 < type2) {
+ return -1;
+ }
+ if (type1 > type2) {
+ return 1;
+ }
+
+ /* For private handles, we also compare the impl pointers. */
+ if (type1 == DEVHANDLE_TYPE_PRIVATE) {
+ intptr_t impl1 = (intptr_t)handle1.impl;
+ intptr_t impl2 = (intptr_t)handle2.impl;
+
+ if (impl1 < impl2) {
+ return -1;
+ }
+ if (impl1 > impl2) {
+ return 1;
+ }
+ }
+
+ if (handle1.integer < handle2.integer) {
+ return -1;
+ }
+ if (handle1.integer > handle2.integer) {
+ return 1;
+ }
+
+ return 0;
+}
+
device_call_t
devhandle_lookup_device_call(devhandle_t handle, const char *name,
devhandle_t *call_handlep)
diff -r 1302f9988e2e -r 9e8a72380193 sys/sys/device.h
--- a/sys/sys/device.h Sat Jan 22 11:49:16 2022 +0000
+++ b/sys/sys/device.h Sat Jan 22 11:58:15 2022 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: device.h,v 1.177 2022/01/22 11:16:00 thorpej Exp $ */
+/* $NetBSD: device.h,v 1.178 2022/01/22 11:58:15 thorpej Exp $ */
/*
* Copyright (c) 2021 The NetBSD Foundation, Inc.
@@ -674,6 +674,7 @@
bool devhandle_is_valid(devhandle_t);
devhandle_t devhandle_invalid(void);
devhandle_type_t devhandle_type(devhandle_t);
+int devhandle_compare(devhandle_t, devhandle_t);
device_call_t devhandle_lookup_device_call(devhandle_t, const char *,
devhandle_t *);
Home |
Main Index |
Thread Index |
Old Index