All of lore.kernel.org
 help / color / mirror / Atom feed
From: Jan Kiszka <jan.kiszka@domain.hid>
To: xenomai-core <xenomai@xenomai.org>
Subject: [Xenomai-core] [PATCH 4/6] Eliminate xnobjhash
Date: Tue, 26 Aug 2008 13:55:32 +0200	[thread overview]
Message-ID: <48B3EF34.90001@domain.hid> (raw)
In-Reply-To: <48B3ED52.7080101@domain.hid>

Hook up xnobject directly to the hash table instead of establishing
dynamically created xnobjhash redirections.

---
 include/nucleus/registry.h |   10 +-----
 ksrc/nucleus/registry.c    |   73 +++++++++++++++++++--------------------------
 2 files changed, 33 insertions(+), 50 deletions(-)

Index: b/include/nucleus/registry.h
===================================================================
--- a/include/nucleus/registry.h
+++ b/include/nucleus/registry.h
@@ -55,6 +55,8 @@ typedef struct xnobject {
 
     u_long cstamp;	/* !< Creation stamp. */
 
+    struct xnobject *hnext;	/* !< Next in h-table */
+
 #ifdef CONFIG_PROC_FS
 
     struct xnpnode *pnode; /* !< /proc information class. */
@@ -65,14 +67,6 @@ typedef struct xnobject {
 
 } xnobject_t;
 
-typedef struct xnobjhash {
-
-    xnobject_t *object;
-
-    struct xnobjhash *next;	/* !< Next in h-table */
-
-} xnobjhash_t;
-
 #ifdef __cplusplus
 extern "C" {
 #endif
Index: b/ksrc/nucleus/registry.c
===================================================================
--- a/ksrc/nucleus/registry.c
+++ b/ksrc/nucleus/registry.c
@@ -54,7 +54,7 @@ static xnqueue_t registry_obj_busyq;	/*
 
 static u_long registry_obj_stamp;
 
-static xnobjhash_t **registry_hash_table;
+static xnobject_t **registry_hash_table;
 
 static int registry_hash_entries;
 
@@ -132,8 +132,8 @@ int xnregistry_init(void)
 	registry_hash_entries =
 	    primes[obj_hash_max(CONFIG_XENO_OPT_REGISTRY_NRSLOTS / 100)];
 	registry_hash_table =
-	    (xnobjhash_t **) xnarch_alloc_host_mem(sizeof(xnobjhash_t *) *
-					     registry_hash_entries);
+	    (xnobject_t **) xnarch_alloc_host_mem(sizeof(xnobject_t *) *
+						  registry_hash_entries);
 
 	if (!registry_hash_table) {
 #ifdef CONFIG_XENO_EXPORT_REGISTRY
@@ -153,45 +153,42 @@ int xnregistry_init(void)
 
 void xnregistry_cleanup(void)
 {
-	xnobjhash_t *ecurr, *enext;
+	xnobject_t *ecurr, *enext;
 	int n;
 
+#ifdef CONFIG_XENO_EXPORT_REGISTRY
 	for (n = 0; n < registry_hash_entries; n++) {
 		for (ecurr = registry_hash_table[n]; ecurr; ecurr = enext) {
-			enext = ecurr->next;
+			enext = ecurr->hnext;
 
-#ifdef CONFIG_XENO_EXPORT_REGISTRY
-			if (ecurr->object && ecurr->object->pnode) {
-				remove_proc_entry(ecurr->object->key,
-						  ecurr->object->pnode->dir);
+			if (ecurr->pnode) {
+				remove_proc_entry(ecurr->key,
+						  ecurr->pnode->dir);
 
-				if (--ecurr->object->pnode->entries <= 0) {
-					remove_proc_entry(ecurr->object->pnode->
+				if (--ecurr->pnode->entries <= 0) {
+					remove_proc_entry(ecurr->pnode->
 							  type,
-							  ecurr->object->pnode->
+							  ecurr->pnode->
 							  root->dir);
-					ecurr->object->pnode->dir = NULL;
+					ecurr->pnode->dir = NULL;
 
-					if (--ecurr->object->pnode->root->
+					if (--ecurr->pnode->root->
 					    entries <= 0) {
 						remove_proc_entry(ecurr->
-								  object->
 								  pnode->root->
 								  name,
 								  registry_proc_root);
-						ecurr->object->pnode->root->
+						ecurr->pnode->root->
 						    dir = NULL;
 					}
 				}
 			}
-#endif /* CONFIG_XENO_EXPORT_REGISTRY */
-
-			xnfree(ecurr);
 		}
 	}
+#endif /* CONFIG_XENO_EXPORT_REGISTRY */
 
 	xnarch_free_host_mem(registry_hash_table,
-		       sizeof(xnobjhash_t *) * registry_hash_entries);
+		       sizeof(xnobject_t *) * registry_hash_entries);
 
 	xnsynch_destroy(&registry_hash_synch);
 
@@ -448,25 +445,19 @@ static unsigned registry_hash_crunch(con
 
 static inline int registry_hash_enter(const char *key, xnobject_t *object)
 {
-	xnobjhash_t *enew, *ecurr;
+	xnobject_t *ecurr;
 	unsigned s;
 
 	object->key = key;
 	s = registry_hash_crunch(key);
 
-	for (ecurr = registry_hash_table[s]; ecurr != NULL; ecurr = ecurr->next) {
-		if (ecurr->object == object || !strcmp(key, ecurr->object->key))
+	for (ecurr = registry_hash_table[s]; ecurr != NULL; ecurr = ecurr->hnext) {
+		if (ecurr == object || !strcmp(key, ecurr->key))
 			return -EEXIST;
 	}
 
-	enew = (xnobjhash_t *) xnmalloc(sizeof(*enew));
-
-	if (!enew)
-		return -ENOMEM;
-
-	enew->object = object;
-	enew->next = registry_hash_table[s];
-	registry_hash_table[s] = enew;
+	object->hnext = registry_hash_table[s];
+	registry_hash_table[s] = object;
 
 	return 0;
 }
@@ -474,17 +465,15 @@ static inline int registry_hash_enter(co
 static inline int registry_hash_remove(xnobject_t *object)
 {
 	unsigned s = registry_hash_crunch(object->key);
-	xnobjhash_t *ecurr, *eprev;
+	xnobject_t *ecurr, *eprev;
 
 	for (ecurr = registry_hash_table[s], eprev = NULL;
-	     ecurr != NULL; eprev = ecurr, ecurr = ecurr->next) {
-		if (ecurr->object == object) {
+	     ecurr != NULL; eprev = ecurr, ecurr = ecurr->hnext) {
+		if (ecurr == object) {
 			if (eprev)
-				eprev->next = ecurr->next;
+				eprev->hnext = ecurr->hnext;
 			else
-				registry_hash_table[s] = ecurr->next;
-
-			xnfree(ecurr);
+				registry_hash_table[s] = ecurr->hnext;
 
 			return 0;
 		}
@@ -495,12 +484,12 @@ static inline int registry_hash_remove(x
 
 static xnobject_t *registry_hash_find(const char *key)
 {
-	xnobjhash_t *ecurr;
+	xnobject_t *ecurr;
 
 	for (ecurr = registry_hash_table[registry_hash_crunch(key)];
-	     ecurr != NULL; ecurr = ecurr->next) {
-		if (!strcmp(key, ecurr->object->key))
-			return ecurr->object;
+	     ecurr != NULL; ecurr = ecurr->hnext) {
+		if (!strcmp(key, ecurr->key))
+			return ecurr;
 	}
 
 	return NULL;



  parent reply	other threads:[~2008-08-26 11:55 UTC|newest]

Thread overview: 14+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2008-08-26 12:08 [Xenomai-core] [PATCH 0/6] Registry-related cleanups and improvements Jan Kiszka
2008-08-26 11:49 ` [Xenomai-core] [PATCH 1/6] Remove / shorten critical sections in registry code Jan Kiszka
2008-08-26 11:51 ` [Xenomai-core] [PATCH 2/6] Allow key-less registry entries Jan Kiszka
2008-08-26 11:53 ` [Xenomai-core] [PATCH 3/6] Native skin: Use " Jan Kiszka
2008-08-26 11:55 ` Jan Kiszka [this message]
2008-08-26 11:56 ` [Xenomai-core] [RESEND][PATCH 5/6] Avoid add_proc_leaf duplicates Jan Kiszka
2008-08-26 11:58 ` [Xenomai-core] [RESEND][PATCH 6/6] Report registry slot usage via /proc Jan Kiszka
2008-08-26 16:08   ` Philippe Gerum
2008-08-26 16:19     ` Jan Kiszka
2008-08-26 16:22       ` Philippe Gerum
2008-08-26 17:08         ` Jan Kiszka
2008-08-26 13:40 ` [Xenomai-core] [PATCH 0/6] Registry-related cleanups and improvements Gilles Chanteperdrix
2008-08-26 16:03   ` Philippe Gerum
2008-08-27  9:35 ` Philippe Gerum

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=48B3EF34.90001@domain.hid \
    --to=jan.kiszka@domain.hid \
    --cc=xenomai@xenomai.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.