Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add EventDriverFiles.isUnique #242

Merged
merged 1 commit into from
Sep 13, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions source/eventcore/driver.d
Original file line number Diff line number Diff line change
Expand Up @@ -540,6 +540,9 @@ interface EventDriverFiles {
*/
bool isValid(FileFD handle) const @nogc;

/// Determines if the given file's reference count equals one.
bool isUnique(FileFD descriptor) const;

/** Increments the reference count of the given file.
*/
void addRef(FileFD descriptor);
Expand Down
6 changes: 6 additions & 0 deletions source/eventcore/drivers/threadedfile.d
Original file line number Diff line number Diff line change
Expand Up @@ -417,6 +417,12 @@ final class ThreadedFileEventDriver(Events : EventDriverEvents, Core : EventDriv
return m_files[handle.value].validationCounter == handle.validationCounter;
}

final override bool isUnique(FileFD handle)
const {
if (!isValid(handle)) return false;
return m_files[handle.value].refCount == 1;
}

final override void addRef(FileFD descriptor)
{
if (!isValid(descriptor)) return;
Expand Down
8 changes: 8 additions & 0 deletions source/eventcore/drivers/winapi/files.d
Original file line number Diff line number Diff line change
Expand Up @@ -309,6 +309,14 @@ final class WinAPIEventDriverFiles : EventDriverFiles {
return false;
}

override bool isUnique(FileFD handle)
const {
if (!isValid(handle)) return false;
if (auto ps = idToHandle(handle) in m_core.m_handles)
return ps.refCount == 1;
return false;
}

override void addRef(FileFD descriptor)
{
if (!isValid(descriptor)) return;
Expand Down