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/3] native: Avoid lazy non-TLS rt_task_self
Date: Thu, 26 Feb 2009 15:16:19 +0100	[thread overview]
Message-ID: <49A6A433.9040200@domain.hid> (raw)

Unconditionally allocate a self task key in the non-TLS case so that we
do not trigger migration via malloc on first access.

Signed-off-by: Jan Kiszka <jan.kiszka@domain.hid>
---

 src/skins/native/task.c |   50 +++++++++++++++++++++++++----------------------
 1 files changed, 27 insertions(+), 23 deletions(-)

diff --git a/src/skins/native/task.c b/src/skins/native/task.c
index b3ee9b2..24da8ef 100644
--- a/src/skins/native/task.c
+++ b/src/skins/native/task.c
@@ -58,9 +58,16 @@ static void *rt_task_trampoline(void *cookie)
 	void (*entry) (void *cookie);
 	struct sched_param param;
 	struct rt_arg_bulk bulk;
-	RT_TASK *task;
+	RT_TASK *task, *self;
 	long err;
 
+#ifdef HAVE___THREAD
+	self = &__native_self;
+#else /* !HAVE___THREAD */
+	self = malloc(sizeof(*self));
+	pthread_setspecific(__native_tskey, self);
+#endif /* !HAVE___THREAD */
+
 	if (iargs->prio > 0) {
 		/*
 		 * Re-apply sched params here as some libpthread
@@ -95,11 +102,10 @@ static void *rt_task_trampoline(void *cookie)
 	if (err)
 		goto fail;
 
-	xeno_set_current();
+	if (self)
+		*self = *task;
 
-#ifdef HAVE___THREAD
-	__native_self = *task;
-#endif /* HAVE___THREAD */
+	xeno_set_current();
 
 	if (iargs->mode & T_WARNSW)
 		xeno_sigxcpu_no_mlock = 0;
@@ -185,8 +191,20 @@ int rt_task_shadow(RT_TASK *task, const char *name, int prio, int mode)
 	struct sched_param param;
 	struct rt_arg_bulk bulk;
 	RT_TASK task_desc;
+	RT_TASK *self;
 	int err;
 
+#ifdef HAVE___THREAD
+	self = &__native_self;
+#else /* !HAVE___THREAD */
+	self = pthread_getspecific(__native_tskey);
+
+	if (!self)
+		self = malloc(sizeof(*self));
+
+	pthread_setspecific(__native_tskey, self);
+#endif /* !HAVE___THREAD */
+
 	if (task == NULL)
 		task = &task_desc; /* Discarded. */
 
@@ -215,9 +233,9 @@ int rt_task_shadow(RT_TASK *task, const char *name, int prio, int mode)
 				NULL);
 
 	if (!err) {
-#ifdef HAVE___THREAD
-		__native_self = *task;
-#endif /* HAVE___THREAD */
+		if (self)
+			*self = *task;
+
 		xeno_set_current();
 
 		if (mode & T_WARNSW)
@@ -343,22 +361,8 @@ RT_TASK *rt_task_self(void)
 
 	if (self->opaque == XN_NO_HANDLE)
 		return NULL;
-
 #else /* !HAVE___THREAD */
-	self = (RT_TASK *)pthread_getspecific(__native_tskey);
-
-	if (self)
-		return self;
-
-	self = (RT_TASK *)malloc(sizeof(*self));
-
-	if (!self ||
-	    XENOMAI_SKINCALL1(__native_muxid, __native_task_self, self) != 0) {
-		free(self);
-		return NULL;
-	}
-
-	pthread_setspecific(__native_tskey, self);
+	self = pthread_getspecific(__native_tskey);
 #endif /* !HAVE___THREAD */
 
 	return self;


                 reply	other threads:[~2009-02-26 14:16 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

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=49A6A433.9040200@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.