All of lore.kernel.org
 help / color / mirror / Atom feed
From: Philippe Gerum <rpm@xenomai.org>
To: Jan Kiszka <jan.kiszka@domain.hid>
Cc: xenomai-core <xenomai@xenomai.org>
Subject: Re: [Xenomai-core] __thread instead of pthread_get/setspecific
Date: Tue, 14 Oct 2008 16:30:10 +0200	[thread overview]
Message-ID: <48F4ACF2.3000408@domain.hid> (raw)
In-Reply-To: <48F4A234.9030309@domain.hid>

Jan Kiszka wrote:
> Gilles Chanteperdrix wrote:
>> Jan Kiszka wrote:
>>> Ack. There are rt_printf (rtdk) and the task-self services of vxworks,
>>> vrtx and native skins. So if I get an OK for the proposal, I'll convert
>>> the rest, too.
>> And I really do not understand how the keys can be chosen at
>> compilation-time, especially in the situation where multiple libraries
>> allocate __thread objects separately: how does the compiler know which
>> key to give for each library ?
> 
> The keys are known at linking time when a) their context is module-local
> and b) their TLS storage can be appended to main's TLS area (and that
> can only happen during initial linking, of course).
> 
> 
> BTW, another advantage of TLS over getspecific /wrt task-self is that it
> overcomes its laziness: its now cheap and easy to set self in the thread
> trampoline.
> 
> Philippe, could it be that vrtx's sc_tinquiry implementation is broken?
> I only find the corresponding pthread_setspecific in the lib
> constructor. That pattern totally disagrees with native and vxworks.
>

Oh my... I killed this dead O/S once again!

--- src/skins/vrtx/task.c	(revision 4211)
+++ src/skins/vrtx/task.c	(working copy)
@@ -80,6 +80,7 @@
 	struct sched_param param;
 	int policy;
 	long err;
+	TCB *tcb;

 	/* Backup the arg struct, it might vanish after completion. */
 	memcpy(&_iargs, iargs, sizeof(_iargs));
@@ -94,6 +95,15 @@
 	/* vrtx_task_delete requires asynchronous cancellation */
 	pthread_setcanceltype(PTHREAD_CANCEL_ASYNCHRONOUS, NULL);

+	tcb = (TCB *) malloc(sizeof(*tcb));
+	if (tcb == NULL) {
+		fprintf(stderr, "Xenomai: failed to allocate local TCB?!\n");
+		err = -ENOMEM;
+		goto fail;
+	}
+
+	pthread_setspecific(__vrtx_tskey, tcb);
+
 	old_sigharden_handler = signal(SIGHARDEN, &vrtx_task_sigharden);

 	bulk.a1 = (u_long)iargs->tid;
@@ -116,9 +126,7 @@

 	if (!err)
 		_iargs.entry(_iargs.param);
-
-      fail:
-
+fail:
 	pthread_exit((void *)err);
 }

Index: src/skins/vrtx/init.c
===================================================================
--- src/skins/vrtx/init.c	(revision 4211)
+++ src/skins/vrtx/init.c	(working copy)
@@ -39,8 +39,6 @@
 static __attribute__ ((constructor))
 void __init_xeno_interface(void)
 {
-	TCB *tcb;
-
 	__vrtx_muxid =
 	    xeno_bind_skin(VRTX_SKIN_MAGIC, "vrtx", "xeno_vrtx");
 	__vrtx_muxid = __xn_mux_shifted_id(__vrtx_muxid);
@@ -51,13 +49,4 @@
 		fprintf(stderr, "Xenomai: failed to allocate new TSD key?!\n");
 		exit(1);
 	}
-
-	tcb = (TCB *) malloc(sizeof(*tcb));
-
-	if (!tcb) {
-		fprintf(stderr, "Xenomai: failed to allocate local TCB?!\n");
-		exit(1);
-	}
-
-	pthread_setspecific(__vrtx_tskey, tcb);
 }


> Jan
> 


-- 
Philippe.



  reply	other threads:[~2008-10-14 14:30 UTC|newest]

Thread overview: 19+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2008-10-13 21:55 [Xenomai-core] __thread instead of pthread_get/setspecific Jan Kiszka
2008-10-14  8:28 ` Gilles Chanteperdrix
2008-10-14  9:08   ` Jan Kiszka
2008-10-14  9:15     ` Gilles Chanteperdrix
2008-10-14  9:26       ` Jan Kiszka
2008-10-14  9:41         ` Gilles Chanteperdrix
2008-10-14 10:25           ` Jan Kiszka
2008-10-14 12:18             ` Gilles Chanteperdrix
2008-10-14 12:49               ` Jan Kiszka
2008-10-14 12:53                 ` Gilles Chanteperdrix
2008-10-14 12:59                   ` Jan Kiszka
2008-10-14 13:02                     ` Gilles Chanteperdrix
2008-10-14 13:09                       ` Jan Kiszka
2008-10-14 13:22                         ` Gilles Chanteperdrix
2008-10-14 13:25                         ` Gilles Chanteperdrix
2008-10-14 13:44                           ` Jan Kiszka
2008-10-14 14:30                             ` Philippe Gerum [this message]
2008-10-14  9:58         ` Gilles Chanteperdrix
2008-10-14 10:26           ` Jan Kiszka

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=48F4ACF2.3000408@domain.hid \
    --to=rpm@xenomai.org \
    --cc=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.