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 2/6] Allow key-less registry entries
Date: Tue, 26 Aug 2008 13:51:51 +0200	[thread overview]
Message-ID: <48B3EE57.2000606@domain.hid> (raw)
In-Reply-To: <48B3ED52.7080101@domain.hid>

No need to add anonymous registry entries with pseudo names to the hash
table - no one will look them up anyway. Reduces hash key collisions for
named objects.

---
 ChangeLog               |    3 +++
 ksrc/nucleus/registry.c |   34 ++++++++++++++++++++++------------
 2 files changed, 25 insertions(+), 12 deletions(-)

Index: b/ksrc/nucleus/registry.c
===================================================================
--- a/ksrc/nucleus/registry.c
+++ b/ksrc/nucleus/registry.c
@@ -542,7 +542,9 @@ static inline unsigned registry_wakeup_s
  * @param key A valid NULL-terminated string by which the object will
  * be indexed and later retrieved in the registry. Since it is assumed
  * that such key is stored into the registered object, it will *not*
- * be copied but only kept by reference in the registry.
+ * be copied but only kept by reference in the registry. Pass an empty
+ * string if the object shall only occupy a registry slot
+ * for handle-based lookups.
  *
  * @param objaddr An opaque pointer to the object to index by @a
  * key.
@@ -560,8 +562,8 @@ static inline unsigned registry_wakeup_s
  *
  * @return 0 is returned upon success. Otherwise:
  *
- * - -EINVAL is returned if @a key or @a objaddr are NULL, or if @a
- * key constains an invalid '/' character.
+ * - -EINVAL is returned if @a objaddr are NULL, or if @a key constains
+ * an invalid '/' character.
  *
  * - -ENOMEM is returned if the system fails to get enough dynamic
  * memory from the global real-time heap in order to register the
@@ -601,6 +603,18 @@ int xnregistry_enter(const char *key,
 
 	object = link2xnobj(holder);
 
+	xnsynch_init(&object->safesynch, XNSYNCH_FIFO);
+	object->objaddr = objaddr;
+	object->cstamp = ++registry_obj_stamp;
+	object->safelock = 0;
+	object->pnode = NULL;
+
+	if (!*key) {
+		object->key = NULL;
+		*phandle = object - registry_obj_slots;
+		return 0;
+	}
+
 	err = registry_hash_enter(key, object);
 
 	if (err) {
@@ -608,10 +622,6 @@ int xnregistry_enter(const char *key,
 		goto unlock_and_exit;
 	}
 
-	xnsynch_init(&object->safesynch, XNSYNCH_FIFO);
-	object->objaddr = objaddr;
-	object->cstamp = ++registry_obj_stamp;
-	object->safelock = 0;
 	appendq(&registry_obj_busyq, holder);
 
 	/* <!> Make sure the handle is written back before the
@@ -621,10 +631,6 @@ int xnregistry_enter(const char *key,
 #ifdef CONFIG_XENO_EXPORT_REGISTRY
 	if (pnode)
 		registry_proc_export(object, pnode);
-	else {
-		object->proc = NULL;
-		object->pnode = NULL;
-	}
 #endif /* CONFIG_XENO_EXPORT_REGISTRY */
 
 	if (registry_wakeup_sleepers(key))
@@ -831,10 +837,14 @@ int xnregistry_remove(xnhandle_t handle)
 			  object->pnode->type);
 #endif
 
-	registry_hash_remove(object);
 	object->objaddr = NULL;
 	object->cstamp = 0;
 
+	if (!object->key)
+		goto unlock_and_exit;
+
+	registry_hash_remove(object);
+
 #ifdef CONFIG_XENO_EXPORT_REGISTRY
 	if (object->pnode) {
 		registry_proc_unexport(object);
Index: b/ChangeLog
===================================================================
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,8 @@
 2008-08-26  Jan Kiszka  <jan.kiszka@domain.hid>
 
+	* ksrc/nucleus/registry.c (xnregistry_enter/remove): Allow for
+	key-less anonymous object registration.
+
 	* ksrc/nucleus/registry.c (xnregistry_fetch/get/put): Remove
 	pointless locking, move XNOBJECT_SELF lookups out of critical
 	sections.



  parent reply	other threads:[~2008-08-26 11:51 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 ` Jan Kiszka [this message]
2008-08-26 11:53 ` [Xenomai-core] [PATCH 3/6] Native skin: Use key-less registry entries Jan Kiszka
2008-08-26 11:55 ` [Xenomai-core] [PATCH 4/6] Eliminate xnobjhash Jan Kiszka
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=48B3EE57.2000606@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.