为什么 posix 线程 id 在 Linux 内核函数 filp_close 中可以为 NULL?
Why can the posix thread id be NULL in Linux kernel function filp_close?
以下摘自linux内核:
/*
* "id" is the POSIX thread ID. We use the
* files pointer for this..
*/
int filp_close(struct file *filp, fl_owner_t id)
文档说id
是posix线程id,应该是current->files
.
然而,我在 Linux 内核中发现了很多用法,例如acct_on,用作filp_close(filp, NULL)
我的问题是:
为什么调用filp_close
时可以接受NULL?
争论的目的是什么id
?
根据此 discussion,fl_owner_t
的正式描述将是
A generic "file lock owner" value. This is set differently for different
types of locks.
The POSIX file lock owner is determined by the "struct files_struct" in the
thread group.
Flock (BSD) locks, OFD locks and leases set the fl_owner to the
file description pointer.
但实际上这是不透明指针
legacy typedef, should eventually go away
指的是进程文件描述符table (struct files_struct
).
至于filp_close
函数,只有fs/file.c
源使用非NULL id
参数。所有其他用户手动创建 filp
(使用 filp_open
或 file_open_name
)并将 id
作为 NULL 传递。
以下摘自linux内核:
/*
* "id" is the POSIX thread ID. We use the
* files pointer for this..
*/
int filp_close(struct file *filp, fl_owner_t id)
文档说id
是posix线程id,应该是current->files
.
然而,我在 Linux 内核中发现了很多用法,例如acct_on,用作filp_close(filp, NULL)
我的问题是:
为什么调用filp_close
时可以接受NULL?
争论的目的是什么id
?
根据此 discussion,fl_owner_t
的正式描述将是
A generic "file lock owner" value. This is set differently for different
types of locks.
The POSIX file lock owner is determined by the "struct files_struct" in the
thread group.
Flock (BSD) locks, OFD locks and leases set the fl_owner to the
file description pointer.
但实际上这是不透明指针
legacy typedef, should eventually go away
指的是进程文件描述符table (struct files_struct
).
至于filp_close
函数,只有fs/file.c
源使用非NULL id
参数。所有其他用户手动创建 filp
(使用 filp_open
或 file_open_name
)并将 id
作为 NULL 传递。