Skip to content

Commit

Permalink
Merge pull request #242 from vibe-d/add_file_isunique
Browse files Browse the repository at this point in the history
Add EventDriverFiles.isUnique
  • Loading branch information
l-kramer authored Sep 13, 2024
2 parents 95525a7 + 43d4b1d commit 3cdca04
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 0 deletions.
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

0 comments on commit 3cdca04

Please sign in to comment.