mirror of
https://github.com/SerenityOS/serenity
synced 2024-09-20 00:12:20 +00:00
Kernel: Customize File::unref() and make it virtual
Make File inherit from RefCountedBase and provide a custom unref() implementation. This will allow subclasses that participate in lists to remove themselves in a safe way when being destroyed.
This commit is contained in:
parent
fc0cd8317a
commit
641083f3b8
|
@ -20,6 +20,14 @@ File::~File()
|
|||
{
|
||||
}
|
||||
|
||||
bool File::unref() const
|
||||
{
|
||||
if (deref_base())
|
||||
return false;
|
||||
delete this;
|
||||
return true;
|
||||
}
|
||||
|
||||
KResultOr<NonnullRefPtr<FileDescription>> File::open(int options)
|
||||
{
|
||||
auto description = FileDescription::create(*this);
|
||||
|
|
|
@ -71,9 +71,10 @@ public:
|
|||
// - Should create a Region in the Process and return it if successful.
|
||||
|
||||
class File
|
||||
: public RefCounted<File>
|
||||
: public RefCountedBase
|
||||
, public Weakable<File> {
|
||||
public:
|
||||
virtual bool unref() const;
|
||||
virtual ~File();
|
||||
|
||||
virtual KResultOr<NonnullRefPtr<FileDescription>> open(int options);
|
||||
|
|
Loading…
Reference in a new issue