[PATCH] resource: Add FreeResourceByTypeValue

Chris Wilson chris at chris-wilson.co.uk
Mon Jul 11 07:56:21 PDT 2011


Another variant on the FreeResource theme. The purpose of this is to
free the exactly matching resource for both the type and value, useful in
circumstance where there are a number of identically typed resources
associated with an id and only one needs to be removed.

References: https://bugs.freedesktop.org/show_bug.cgi?id=37700
Signed-off-by: Chris Wilson <chris at chris-wilson.co.uk>
---
 dix/resource.c     |   32 ++++++++++++++++++++++++++++++++
 include/resource.h |    6 ++++++
 2 files changed, 38 insertions(+), 0 deletions(-)

diff --git a/dix/resource.c b/dix/resource.c
index eb9f049..745d4bc 100644
--- a/dix/resource.c
+++ b/dix/resource.c
@@ -644,6 +644,38 @@ FreeResourceByType(XID id, RESTYPE type, Bool skipFree)
     }
 }
 
+void
+FreeResourceByTypeValue(XID id, RESTYPE type, pointer value, Bool skipFree)
+{
+    int		cid;
+    ResourcePtr res;
+    ResourcePtr *prev, *head;
+    if (((cid = CLIENT_ID(id)) < MAXCLIENTS) && clientTable[cid].buckets)
+    {
+	head = &clientTable[cid].resources[Hash(cid, id)];
+
+	prev = head;
+	while ( (res = *prev) )
+	{
+	    if (res->id == id && res->type == type && res->value == value)
+	    {
+#ifdef XSERVER_DTRACE
+		XSERVER_RESOURCE_FREE(res->id, res->type,
+			      res->value, TypeNameString(res->type));
+#endif
+		*prev = res->next;
+		clientTable[cid].elements--;
+
+		doFreeResource(res, skipFree);
+
+		break;
+	    }
+	    else
+		prev = &res->next;
+        }
+    }
+}
+
 /*
  * Change the value associated with a resource id.  Caller
  * is responsible for "doing the right thing" with the old
diff --git a/include/resource.h b/include/resource.h
index 772b7b8..7cfd8ba 100644
--- a/include/resource.h
+++ b/include/resource.h
@@ -189,6 +189,12 @@ extern _X_EXPORT void FreeResourceByType(
     RESTYPE /*type*/,
     Bool /*skipFree*/);
 
+extern _X_EXPORT void FreeResourceByTypeValue(
+    XID /*id*/,
+    RESTYPE /*type*/,
+    pointer /*value*/,
+    Bool /*skipFree*/);
+
 extern _X_EXPORT Bool ChangeResourceValue(
     XID /*id*/,
     RESTYPE /*rtype*/,
-- 
1.7.5.4



More information about the xorg-devel mailing list