[+] IProcess::TryAttachProcessExitToCompletionGroup
[+] IProcess::ToCompletionGroupHandle
This commit is contained in:
parent
3090fa3996
commit
f1e170add0
@ -12,6 +12,12 @@ namespace Aurora::Threading
|
||||
struct IWaitable;
|
||||
}
|
||||
|
||||
namespace Aurora::IO::CompletionGroup
|
||||
{
|
||||
struct ICompletionGroup;
|
||||
struct ICompletionGroupWorkHandle;
|
||||
}
|
||||
|
||||
namespace Aurora::Processes
|
||||
{
|
||||
struct IProcess
|
||||
@ -125,5 +131,9 @@ namespace Aurora::Processes
|
||||
* @return
|
||||
*/
|
||||
virtual AuSPtr<IO::IStreamWriter> ToStreamWriter() = 0;
|
||||
|
||||
virtual bool TryAttachProcessExitToCompletionGroup(const AuSPtr<IO::CompletionGroup::ICompletionGroup> &pCompletionGroup) = 0;
|
||||
|
||||
virtual IO::CompletionGroup::ICompletionGroupWorkHandle *ToCompletionGroupHandle() = 0;
|
||||
};
|
||||
}
|
@ -121,12 +121,25 @@ namespace Aurora::Processes
|
||||
{
|
||||
DWORD exitCode;
|
||||
|
||||
if (this->bHasTerminated)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
if (!GetExitCodeProcess(this->process_, &exitCode))
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
return exitCode != STILL_ACTIVE;
|
||||
if (exitCode != STILL_ACTIVE)
|
||||
{
|
||||
this->bHasTerminated = true;
|
||||
return true;
|
||||
}
|
||||
else
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
bool ProcessImpl::Terminate()
|
||||
@ -748,8 +761,14 @@ namespace Aurora::Processes
|
||||
auto result = GetExitCodeProcess(this->processInfo_.hProcess, &exitCode);
|
||||
if (result)
|
||||
{
|
||||
this->bHasTerminated = true;
|
||||
this->exitCode_ = exitCode;
|
||||
}
|
||||
|
||||
if (auto pCompletionGroup = this->pCompletionGroup_)
|
||||
{
|
||||
pCompletionGroup->TryTrigger();
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
@ -773,6 +792,32 @@ namespace Aurora::Processes
|
||||
return true;
|
||||
}
|
||||
|
||||
bool ProcessImpl::TryAttachProcessExitToCompletionGroup(const AuSPtr<IO::CompletionGroup::ICompletionGroup> &pCompletionGroup)
|
||||
{
|
||||
if (this->pCompletionGroup_)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
this->pCompletionGroup_ = pCompletionGroup;
|
||||
return true;
|
||||
}
|
||||
|
||||
IO::CompletionGroup::ICompletionGroupWorkHandle *ProcessImpl::ToCompletionGroupHandle()
|
||||
{
|
||||
return this;
|
||||
}
|
||||
|
||||
bool ProcessImpl::HasCompletedForGCWI()
|
||||
{
|
||||
return this->HasExited();
|
||||
}
|
||||
|
||||
void ProcessImpl::CleanupForGCWI()
|
||||
{
|
||||
AuResetMember(this->pCompletionGroup_);
|
||||
}
|
||||
|
||||
void ProcessImpl::RelOtherHandles()
|
||||
{
|
||||
if (!this->bDontRelOut_)
|
||||
|
@ -11,7 +11,9 @@
|
||||
|
||||
namespace Aurora::Processes
|
||||
{
|
||||
struct ProcessImpl : IProcess
|
||||
struct ProcessImpl :
|
||||
IProcess,
|
||||
IO::CompletionGroup::ICompletionGroupWorkItem
|
||||
{
|
||||
ProcessImpl(StartupParameters &¶ms);
|
||||
~ProcessImpl();
|
||||
@ -43,6 +45,12 @@ namespace Aurora::Processes
|
||||
|
||||
bool Start() override;
|
||||
|
||||
bool TryAttachProcessExitToCompletionGroup(const AuSPtr<IO::CompletionGroup::ICompletionGroup> &pCompletionGroup) override;
|
||||
IO::CompletionGroup::ICompletionGroupWorkHandle *ToCompletionGroupHandle() override;
|
||||
|
||||
bool HasCompletedForGCWI() override;
|
||||
void CleanupForGCWI() override;
|
||||
|
||||
bool Init();
|
||||
void RestLeakyMem();
|
||||
void RelOtherHandles();
|
||||
@ -81,5 +89,7 @@ namespace Aurora::Processes
|
||||
AuThreads::ThreadUnique_t thread_;
|
||||
HANDLE poke_ {INVALID_HANDLE_VALUE};
|
||||
AuSInt exitCode_;
|
||||
bool bHasTerminated {};
|
||||
AuSPtr<IO::CompletionGroup::ICompletionGroup> pCompletionGroup_;
|
||||
};
|
||||
}
|
@ -154,6 +154,11 @@ namespace Aurora::Processes
|
||||
{
|
||||
this->fsErrorStream_->CheckProcess();
|
||||
}
|
||||
|
||||
if (auto pCompletionGroup = this->pCompletionGroup_)
|
||||
{
|
||||
pCompletionGroup->TryTrigger();
|
||||
}
|
||||
}
|
||||
|
||||
void ProcessImpl::ShutdownPipes()
|
||||
@ -738,6 +743,32 @@ namespace Aurora::Processes
|
||||
return true;
|
||||
}
|
||||
|
||||
bool ProcessImpl::TryAttachProcessExitToCompletionGroup(const AuSPtr<IO::CompletionGroup::ICompletionGroup> &pCompletionGroup)
|
||||
{
|
||||
if (this->pCompletionGroup_)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
this->pCompletionGroup_ = pCompletionGroup;
|
||||
return true;
|
||||
}
|
||||
|
||||
IO::CompletionGroup::ICompletionGroupWorkHandle *ProcessImpl::ToCompletionGroupHandle()
|
||||
{
|
||||
return this;
|
||||
}
|
||||
|
||||
bool ProcessImpl::HasCompletedForGCWI()
|
||||
{
|
||||
return this->HasExited();
|
||||
}
|
||||
|
||||
void ProcessImpl::CleanupForGCWI()
|
||||
{
|
||||
AuResetMember(this->pCompletionGroup_);
|
||||
}
|
||||
|
||||
void ProcessImpl::HookMainDeath()
|
||||
{
|
||||
if (this->type_ == ESpawnType::eSpawnChildProcessWorker)
|
||||
|
@ -25,7 +25,9 @@ namespace Aurora::Processes
|
||||
void DeinitUnix();
|
||||
void InitUnix();
|
||||
|
||||
struct ProcessImpl : IProcess
|
||||
struct ProcessImpl :
|
||||
IProcess,
|
||||
IO::CompletionGroup::ICompletionGroupWorkItem
|
||||
{
|
||||
ProcessImpl(StartupParameters &¶ms);
|
||||
~ProcessImpl();
|
||||
@ -53,6 +55,12 @@ namespace Aurora::Processes
|
||||
AuSPtr<IO::IStreamReader> ToStreamReader(EStandardHandle stream) override;
|
||||
AuSPtr<IO::IStreamWriter> ToStreamWriter() override;
|
||||
|
||||
bool TryAttachProcessExitToCompletionGroup(const AuSPtr<IO::CompletionGroup::ICompletionGroup> &pCompletionGroup) override;
|
||||
IO::CompletionGroup::ICompletionGroupWorkHandle *ToCompletionGroupHandle() override;
|
||||
|
||||
bool HasCompletedForGCWI() override;
|
||||
void CleanupForGCWI() override;
|
||||
|
||||
bool Start() override;
|
||||
|
||||
bool Init();
|
||||
@ -92,5 +100,7 @@ namespace Aurora::Processes
|
||||
|
||||
AuSInt exitCode_ {};
|
||||
bool bHasExited {};
|
||||
|
||||
AuSPtr<IO::CompletionGroup::ICompletionGroup> pCompletionGroup_;
|
||||
};
|
||||
}
|
Loading…
Reference in New Issue
Block a user