Skip to contentSkip to conversation

libnative: Avoid double-evaluation of rt_task_self()

PATCH In review Jan Kiszka 3 participants 6 messages Apr 2, 2009 – Apr 13, 2009

lore
Share & tools
lore

Jan Kiszka

author
#0 lore raw

PATCH 1/1 libnative: Avoid double-evaluation of rt_task_self()

[ can be pulled from git.xenomai.org/xenomai-jki.git queues/assorted ]

Keep the result of rt_task_self() in a local variable to avoid the second invocation.

---

 src/skins/native/task.c |    3 ++-
 1 files changed, 2 insertions(+), 1 deletions(-)
src/skins/native/task.c +2 -1
index 905d366..149717b 100644
@@ -247,10 +247,11 @@ int rt_task_resume(RT_TASK *task)
 
 int rt_task_delete(RT_TASK *task)
 {
+	RT_TASK *self;
 	int err;
 
 	if (task == NULL ||
-	    (rt_task_self() && task->opaque == rt_task_self()->opaque)) {
+	    ((self = rt_task_self()) && self->opaque == task->opaque)) {
 		/* Silently migrate to avoid raising SIGXCPU. */
 		XENOMAI_SYSCALL1(__xn_sys_migrate, XENOMAI_LINUX_DOMAIN);
 		pthread_exit(NULL);
#1 lore raw
Quoted 4 lines · Jan Kiszka

[ can be pulled from git.xenomai.org/xenomai-jki.git queues/assorted ]

Keep the result of rt_task_self() in a local variable to avoid the second invocation.

Maybe we could create a pure/const variant of rt_task_self() for use in task.c only which would avoid the double evaluatino ?

Signature · 1 line
					    Gilles.
#2 lore raw
Quoted 9 lines · Gilles Chanteperdrix
Quoted 4 lines · Jan Kiszka

[ can be pulled from git.xenomai.org/xenomai-jki.git queues/assorted ]

Keep the result of rt_task_self() in a local variable to avoid the second invocation.

Maybe we could create a pure/const variant of rt_task_self() for use in task.c only which would avoid the double evaluatino ?

Can't do const because of pthread_getspecific(), but pure attribute is t hand, yes.

Signature · 1 line
Philippe.
author
#3 lore raw
Quoted 4 lines · Philippe Gerum
Quoted 3 lines · Gilles Chanteperdrix
Quoted 2 lines · Jan Kiszka

[ can be pulled from git.xenomai.org/xenomai-jki.git queues/assorted ]

Quoted 9 lines
Quoted 5 lines
Quoted 2 lines

Keep the result of rt_task_self() in a local variable to avoid the second invocation.

Maybe we could create a pure/const variant of rt_task_self() for use in task.c only which would avoid the double evaluatino ?

Can't do const because of pthread_getspecific(), but pure attribute is t hand, yes.

At least my gcc 4.3 ignores

RT_TASK *rt_task_self(void) __attribute__ ((pure));

and keeps on inserting two calls in rt_task_delete.

Jan

#4 lore raw
Quoted 11 lines · Jan Kiszka
Quoted 10 lines · Philippe Gerum
Quoted 8 lines · Gilles Chanteperdrix
Quoted 4 lines · Jan Kiszka

[ can be pulled from git.xenomai.org/xenomai-jki.git queues/assorted ]

Keep the result of rt_task_self() in a local variable to avoid the second invocation.

Maybe we could create a pure/const variant of rt_task_self() for use in task.c only which would avoid the double evaluatino ?

Quoted 8 lines
Quoted 3 lines

Can't do const because of pthread_getspecific(), but pure attribute is t hand, yes.

At least my gcc 4.3 ignores

RT_TASK *rt_task_self(void) __attribute__ ((pure));

We can't do that on rt_task_self() directly, because of rt_task_shadow().

Quoted 2 lines

and keeps on inserting two calls in rt_task_delete.

What if a pure static inline helper is used internally from task.c?

Quoted 2 lines

Jan

Signature · 1 line
Philippe.
author
#5 lore raw
Quoted 19 lines · Philippe Gerum
Quoted 10 lines · Jan Kiszka
Quoted 9 lines · Philippe Gerum
Quoted 8 lines · Gilles Chanteperdrix
Quoted 4 lines · Jan Kiszka

[ can be pulled from git.xenomai.org/xenomai-jki.git queues/assorted ]

Keep the result of rt_task_self() in a local variable to avoid the second invocation.

Maybe we could create a pure/const variant of rt_task_self() for use in task.c only which would avoid the double evaluatino ?

Quoted 7 lines
Quoted 3 lines

Can't do const because of pthread_getspecific(), but pure attribute is t hand, yes.

At least my gcc 4.3 ignores

RT_TASK *rt_task_self(void) __attribute__ ((pure));

Quoted 8 lines

We can't do that on rt_task_self() directly, because of rt_task_shadow().

Quoted 2 lines

and keeps on inserting two calls in rt_task_delete.

What if a pure static inline helper is used internally from task.c?

Makes no difference (and defining a new helper for this purpose would be overkill anyway).

So please pull my original version from
git://git.xenomai.org/xenomai-jki.git for-upstream

BTW, you'll find another trivial fix in that queue:

src/testsuite/switchtest/switchtest.c +1 -1
@@ -1094,7 +1094,7 @@ int check_fpu(void)
 		exit(EXIT_FAILURE);
 	}
 
-	return (int) status;
+	return (long) status;
 }
 
 int main(int argc, const char *argv[])

Jan