mirror of
https://github.com/SerenityOS/serenity.git
synced 2025-01-23 18:02:05 -05:00
Kernel: Add a Process::FileDescriptions::get_if_valid(index) API
Note that this is not the same as ::at(index), which has a different precondition ("allocated" vs "valid").
This commit is contained in:
parent
c1ffc17134
commit
e9feced041
2 changed files with 26 additions and 0 deletions
|
@ -428,6 +428,29 @@ RefPtr<Process> Process::from_pid(ProcessID pid)
|
|||
});
|
||||
}
|
||||
|
||||
const Process::FileDescriptionAndFlags* Process::FileDescriptions::get_if_valid(size_t i) const
|
||||
{
|
||||
ScopedSpinLock lock(m_fds_lock);
|
||||
if (m_fds_metadatas.size() <= i)
|
||||
return nullptr;
|
||||
|
||||
if (auto& metadata = m_fds_metadatas[i]; metadata.is_valid())
|
||||
return &metadata;
|
||||
|
||||
return nullptr;
|
||||
}
|
||||
Process::FileDescriptionAndFlags* Process::FileDescriptions::get_if_valid(size_t i)
|
||||
{
|
||||
ScopedSpinLock lock(m_fds_lock);
|
||||
if (m_fds_metadatas.size() <= i)
|
||||
return nullptr;
|
||||
|
||||
if (auto& metadata = m_fds_metadatas[i]; metadata.is_valid())
|
||||
return &metadata;
|
||||
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
const Process::FileDescriptionAndFlags& Process::FileDescriptions::at(size_t i) const
|
||||
{
|
||||
ScopedSpinLock lock(m_fds_lock);
|
||||
|
|
|
@ -643,6 +643,9 @@ public:
|
|||
const FileDescriptionAndFlags& at(size_t i) const;
|
||||
FileDescriptionAndFlags& at(size_t i);
|
||||
|
||||
FileDescriptionAndFlags const* get_if_valid(size_t i) const;
|
||||
FileDescriptionAndFlags* get_if_valid(size_t i);
|
||||
|
||||
void enumerate(Function<void(const FileDescriptionAndFlags&)>) const;
|
||||
void change_each(Function<void(FileDescriptionAndFlags&)>);
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue