Make file rcu_freed

上级 f9f7aaef
...@@ -8,7 +8,7 @@ ...@@ -8,7 +8,7 @@
u64 namehash(const strbuf<DIRSIZ>&); u64 namehash(const strbuf<DIRSIZ>&);
struct file : public referenced { struct file : public referenced, public rcu_freed {
static file* alloc(); static file* alloc();
file* dup(); file* dup();
int stat(struct stat*); int stat(struct stat*);
...@@ -26,6 +26,8 @@ struct file : public referenced { ...@@ -26,6 +26,8 @@ struct file : public referenced {
struct inode *ip; struct inode *ip;
u32 off; u32 off;
virtual void do_gc(void);
private: private:
file(); file();
file& operator=(const file&); file& operator=(const file&);
......
...@@ -16,7 +16,8 @@ file::alloc(void) ...@@ -16,7 +16,8 @@ file::alloc(void)
} }
file::file(void) file::file(void)
: type(file::FD_NONE), readable(0), writable(0), : rcu_freed("file"),
type(file::FD_NONE), readable(0), writable(0),
socket(0), pipe(nullptr), ip(nullptr), off(0) socket(0), pipe(nullptr), ip(nullptr), off(0)
{ {
} }
...@@ -32,6 +33,12 @@ file::onzero(void) const ...@@ -32,6 +33,12 @@ file::onzero(void) const
netclose(socket); netclose(socket);
else if(type != file::FD_NONE) else if(type != file::FD_NONE)
panic("file::close bad type"); panic("file::close bad type");
gc_delayed((file*)this);
}
void
file::do_gc(void)
{
delete this; delete this;
} }
......
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论