📄 00000036.htm
字号:
<HTML><HEAD> <TITLE>BBS水木清华站∶精华区</TITLE></HEAD><BODY><CENTER><H1>BBS水木清华站∶精华区</H1></CENTER>发信人: boom (www), 信区: Linux <BR>标 题: another way for C++ in kernel <BR>发信站: BBS 水木清华站 (Sat Nov 18 13:23:56 2000) <BR> <BR>前面的文章里面介绍过可以在kernel中用c++,但是需要崇写new,delete等等 <BR>最近由人在rtlinux的mailing list 上又提出了一种方法 <BR> <BR>(rtlinux) <BR>On Fri, 17 Nov 2000, Alexander Lichius wrote: <BR>><I> i tried to use c++ because i wanted to estimate the performance of </I><BR>><I> plain C code and some C++ "object oriented" code. but my humble trials </I><BR>><I> were killed at compile time. i think the macros for using module </I><BR>><I> parameters are not defined in the g++ standard include files and i </I><BR>><I> didn't have the time to track down the definition in the C includes. </I><BR> <BR>Hi Alexander and Jef, <BR>I think they are defined in linux/module.h <BR> <BR>I have tried to compile a module in C++, but some of the necessary <BR>kernel module #include files use C++ reserved words as variable names. <BR>e.g., there is a variable called "new" (it is C, not C++, so it is ok) <BR> <BR>therefore, I could not compile C++ directly, but I did this way <BR>(skeleton code, missing many details): <BR> <BR>file module_main_file.c (C, not C++, gcc, not g++) <BR>#define MODULE <BR>#define __KERNEL__ <BR>#define __RT__ <BR>.. <BR>#include <rtl_sched.h> <BR>#include <linux/module.h> <BR>#include <linux/kernel.h> <BR>#include <linux/version.h> <BR>#include "wrapper.c" <BR>.. <BR>int init_module() { <BR>...my rt stuff initilization, etc... <BR>pthread_create (&mytask, NULL, execute_module, (void *) 1); <BR>pthread_make_periodic_np (mytask, now + 0.5 * NSECS_PER_SEC, 0.1 * <BR>NSECS_PER_SEC); <BR> <BR>wrapper_init(); <BR>} <BR> <BR>void* execute_module(void *data){ <BR> while(1){ <BR>wrapper_do(); <BR>pthread_wait_np(); <BR> } <BR>} <BR> <BR>void cleanup_module() { <BR> wrapper_close(); <BR> pthread_delete_np (mytask); <BR>} <BR> <BR>----------------end of file <BR> <BR>file wrapper.cc <BR> <BR>MYMAINOBJECT myobj; <BR> <BR>void wrapper_init() { myobj.init(); } <BR>void wrapper_do() { myobj.do(); } <BR>void wrapper_close() { myobj.close(); } <BR> <BR>this file I can compile with g++, and link with my c++ .o files. <BR>then I link this .o file with the main module .o file and... voilla! my <BR>c++ code works! <BR> <BR>Interesting: I use rtlinux 2.0, but with rtlinux 0.6 and linux <BR>2.0.33 I do not need this stuff: the main module can call my object and be <BR>compiledwith g++, no problem. <BR> <BR>><I> so i didn't bother about C++ but wrote my tasks in C. </I><BR>><I> did you or anybody else compiled some working C++ kernel modules? </I><BR> <BR>I know C++ is not supported in the kernel, and many people do not like <BR>to hear "c++ and kernel", but c++ can be still worth... <BR> <BR>----------------------------------------------------------- <BR>Luiz Gustavo Bizarro Mirisola <BR>Mestrando em Ciencia da Computacao - IC-Unicamp/LRV-IA-CTI <BR>MSc Student in Computer Science <BR>State University of Campinas, Brazil <BR><A HREF="mailto:mirisola@dcc.unicamp.br">mirisola@dcc.unicamp.br</A> <BR>----------------------------------------------------------- <BR> <BR>-- [rtl] --- <BR>To unsubscribe: <BR>echo "unsubscribe rtl" | mail <A HREF="mailto:majordomo@rtlinux.org">majordomo@rtlinux.org</A> OR <BR>echo "unsubscribe rtl <Your_email>" | mail <A HREF="mailto:majordomo@rtlinux.org">majordomo@rtlinux.org</A> <BR>--- <BR>For more information on Real-Time Linux see: <BR><A HREF="http://www.rtlinux.org/rtlinux/">http://www.rtlinux.org/rtlinux/</A> <BR> <BR>-- <BR> <BR>※ 来源:·BBS 水木清华站 smth.org·[FROM: 202.112.137.7] <BR><CENTER><H1>BBS水木清华站∶精华区</H1></CENTER></BODY></HTML>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -