[*] Qt: More LoopQueue NT fun

This commit is contained in:
Reece Wilson 2023-07-27 19:06:09 +01:00
parent 6e035195f7
commit 5dddc9d0d8
2 changed files with 26 additions and 1 deletions

View File

@ -203,6 +203,11 @@ namespace Aurora::IO::Loop
that->Sync(); that->Sync();
} }
bool TryLock()
{
return that->Sync2();
}
void Unlock() void Unlock()
{ {
that->Unlock(); that->Unlock();
@ -224,6 +229,25 @@ namespace Aurora::IO::Loop
::ResetEvent(this->hEvent_); ::ResetEvent(this->hEvent_);
} }
bool LoopQueue::Sync2()
{
if (this->hEvent_ != INVALID_HANDLE_VALUE)
{
::SetEvent(this->hEvent_);
}
if (!this->rwMutex_->AsWritable()->TryLock())
{
return false;
}
if (this->hEvent_ != INVALID_HANDLE_VALUE)
{
::ResetEvent(this->hEvent_);
}
return true;
}
void LoopQueue::Unlock() void LoopQueue::Unlock()
{ {
this->rwMutex_->AsWritable()->Unlock(); this->rwMutex_->AsWritable()->Unlock();
@ -317,7 +341,7 @@ namespace Aurora::IO::Loop
} }
LoopJoinable joinable {this}; LoopJoinable joinable {this};
AU_LOCK_GUARD(joinable); AU_TRY_LOCK_GUARD_RET_DEF(joinable);
return CommitLocked(); return CommitLocked();
} }

View File

@ -46,6 +46,7 @@ namespace Aurora::IO::Loop
AuList<AuSPtr<ILoopSource>> WaitAnyEx(AuUInt32 timeout) override; AuList<AuSPtr<ILoopSource>> WaitAnyEx(AuUInt32 timeout) override;
void Sync(); void Sync();
bool Sync2();
void Unlock(); void Unlock();
bool bCheckForDups {}; bool bCheckForDups {};
bool bCheckForForce {}; bool bCheckForForce {};