From: "Dmitry A. Kazakov" <mailbox@dmitry-kazakov.de>
Subject: Re: Passing Ada Proc as a C Function Pointer
Date: Wed, 4 Aug 2010 21:36:38 +0200
Date: 2010-08-04T21:36:35+02:00 [thread overview]
Message-ID: <jyu8ysqzcops$.6c5jsyvez9fy.dlg@40tude.net> (raw)
In-Reply-To: i3ccj1$2bnh$1@adenine.netfront.net
On Wed, 04 Aug 2010 11:46:56 -0700, Jeffrey Carter wrote:
> procedure Thread_Proc : out Thread_Context;
> Proc : in Thread_Proc;
> Stack : out Stack_Area)
> is
> type C_Context is ...;
> -- Something C-compatible that corresponds to the C
> -- definition of avr_thread_context, using only
> -- convention-C components.
> pragma Convention (C, C_Context);
>
> procedure Local_Proc is
> -- null;
> begin -- Local_Proc
> Proc.all;
> end Local_Proc;
> pragma Convention (C, Local_Proc);
I am not sure if this works everywhere. The problem is that Local_Proc
refers to a local variable Proc (formal parameter of Thread_Start). This
needs some special techniques on the compiler side to become C-conform,
e.g. a trampoline.
Local_Proc should be moved out of Thread_Proc.
Then a copy of Proc is created in the scope of. That would be not task safe
without a protected object around the copy of Proc.
Another way could be passing a copy of Proc on Thread_Context.
But IMO there is nothing with putting C conventions on Ada callbacks. All
bindings I know, use it without hesitation.
> Are Context and Stack really needed outside Thread_Start?
In any case they need to be collected upon thread completion. Therefore
they must come from outside (unless Thread_Proc could free them, which is
unlikely).
--
Regards,
Dmitry A. Kazakov
http://www.dmitry-kazakov.de
next prev parent reply other threads:[~2010-08-04 19:36 UTC|newest]
Thread overview: 14+ messages / expand[flat|nested] mbox.gz Atom feed top
2010-08-04 16:40 Passing Ada Proc as a C Function Pointer Warren
2010-08-04 17:14 ` Dmitry A. Kazakov
2010-08-05 0:24 ` Warren
2010-08-04 18:46 ` Jeffrey Carter
2010-08-04 19:36 ` Dmitry A. Kazakov [this message]
2010-08-05 0:42 ` Warren
2010-08-05 0:55 ` Warren
2010-08-04 19:46 ` Simon Wright
2010-08-05 0:45 ` Warren
2010-08-05 7:33 ` Rolf
2010-08-05 20:50 ` Simon Wright
-- strict thread matches above, loose matches on Subject: below --
2010-08-05 14:31 Warren
2010-08-05 15:37 ` Warren
2010-08-05 16:51 ` Warren
replies disabled
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox