Bug fix and a note about funny semantics of close with a shared file table

上级 f7766586
...@@ -58,12 +58,17 @@ public: ...@@ -58,12 +58,17 @@ public:
} }
void close(int fd) { void close(int fd) {
struct file *f = ofile_[fd]; // XXX(sbw) if f->ref_ > 1 the kernel will not actually close
// the file when this function returns (i.e. sys_close can return
// while the file/pipe/socket is still open). Maybe we should clear
// ofile_[fd], wait until f.ref_ == 1, f->dec(), and then return.
acquire(&lock_); acquire(&lock_);
struct file *f = ofile_[fd];
ofile_[fd] = nullptr; ofile_[fd] = nullptr;
release(&lock_); release(&lock_);
f->dec(); if (f)
f->dec();
} }
void decref() { void decref() {
......
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论