running C++ function as THREADCONTROL thread

Marcus Völp voelp at os.inf.tu-dresden.de
Wed May 25 09:57:28 CEST 2005


Jayesh Salvi wrote:

> Hi,
>
> I looked at the pingpong code and found how a thread is created and 
> activated using THREADCONTROL system call. It uses C function pointers 
> and typecasts them to L4_Word_t which are then passed to threadcontrol 
> system call to run this function as thread.
>
> I want to use a C++ function as the thread. But C++ member function 
> pointer seem not to be as simple as C function pointers. Their size 
> changes as well, with the compiler or compiler-options, because of 
> inheritance. Is their any example code that does this?

Hi,
the typical way to deal with the like is to define a wrapper function an 
externalize it as a C function. The below example (taken from the fiasco 
source code) defines a C function sys_thread_ex_regs_wrapper which in 
turn calls sys_thread_ex_regs of class Thread.

extern "C" void sys_thread_ex_regs_wrapper()
{ Proc::sti(); current_thread()->sys_thread_ex_regs(); }


Marcus

-- 
Marcus Völp

TU-Dresden 
Department of Computer Science
Institute for System Architecture

Tel: +49 (351) 463-38350
Fax: +49 (351) 463-38284






More information about the l4-hackers mailing list