Thread local data in linux kernel module
Is it possible to create thread local data in a linux kernel module?
I need to store some data for each process/thread calling my module. Is there an easy way of using thread local data, or do I have to resort to writing a hash map which uses the pid of the current process as a key?
Assuming the interface to you kernel module is a character device driver, then you have a private_data field in the file struct (which is analogous to user space file descriptor) exactly for that.
Just allocate and assign a pointer to your structure of choice at the open file operation to it.
It's not exactly thread or process local, but in most cases a mapping of one file descriptor to your process is true and it might be good enough for you.
链接地址: http://www.djcxy.com/p/87874.html上一篇: 用Linux内核中的模块覆盖功能
下一篇: 在Linux内核模块中线程化本地数据