On Fri, 17 Nov 2000, Alexander Lichius wrote:
> i tried to use c++ because i wanted to estimate the performance of
> plain C code and some C++ "object oriented" code. but my humble trials
> were killed at compile time. i think the macros for using module
> parameters are not defined in the g++ standard include files and i
> didn't have the time to track down the definition in the C includes.

        Hi Alexander and Jef,
        I think they are defined in linux/module.h

        I have tried to compile a module in C++, but some of the necessary
kernel module #include files use C++ reserved words as variable names.
e.g., there is a variable called "new" (it is C, not C++, so it is ok)

        therefore, I could not compile C++ directly, but I did this way
(skeleton code, missing many details):

file module_main_file.c (C, not C++, gcc, not g++)
#define MODULE
#define __KERNEL__
#define __RT__
...
#include <rtl_sched.h> 
#include <linux/module.h>
#include <linux/kernel.h>
#include <linux/version.h>
#include "wrapper.c"
...
int init_module() {
 ...my rt stuff initilization, etc...
 pthread_create (&mytask, NULL, execute_module, (void *) 1);
 pthread_make_periodic_np (mytask, now + 0.5 * NSECS_PER_SEC, 0.1 *
NSECS_PER_SEC);

wrapper_init();
}

void* execute_module(void *data){
  while(1){
        wrapper_do();
        pthread_wait_np();
  }
}

void cleanup_module() {
  wrapper_close();
  pthread_delete_np (mytask);
}

----------------end of file

file wrapper.cc

MYMAINOBJECT myobj;

void wrapper_init() { myobj.init(); }
void wrapper_do() { myobj.do(); }
void wrapper_close() { myobj.close(); }

this file I can compile with g++, and link with my c++ .o files. 
then I link this .o file with the main module .o file and... voilla! my
c++ code works!

Interesting: I use rtlinux 2.0, but with rtlinux 0.6 and linux
2.0.33 I do not need this stuff: the main module can call my object and be
compiledwith g++, no problem.

> so i didn't bother about C++ but wrote my tasks in C.
> did you or anybody else compiled some working C++ kernel modules?

I know C++ is not supported in the kernel, and many people do not like
to hear "c++ and kernel", but c++ can be still worth...

-----------------------------------------------------------
Luiz Gustavo Bizarro Mirisola
Mestrando em Ciencia da Computacao - IC-Unicamp/LRV-IA-CTI              
MSc Student in Computer Science 
State University of Campinas, Brazil
[EMAIL PROTECTED]
-----------------------------------------------------------

-- [rtl] ---
To unsubscribe:
echo "unsubscribe rtl" | mail [EMAIL PROTECTED] OR
echo "unsubscribe rtl <Your_email>" | mail [EMAIL PROTECTED]
---
For more information on Real-Time Linux see:
http://www.rtlinux.org/rtlinux/

Reply via email to