[*] Mucho Sanchez

This commit is contained in:
Reece Wilson 2021-10-23 12:42:31 +01:00
parent 3d859a319e
commit f5a8d875d8

View File

@ -183,7 +183,7 @@ namespace Aurora::IO::FS
bool NtAsyncFileTransaction::StartRead(AuUInt64 offset, void *buffer, AuUInt32 length)
{
if (std::exchange(this->latch_, {}))
if (std::exchange(this->pin_, AuSharedFromThis()))
{
return {};
}
@ -191,14 +191,13 @@ namespace Aurora::IO::FS
this->lastAbstractOffset_ = offset;
this->overlap_.Offset = offset & 0xFFFFFFFF;
this->overlap_.OffsetHigh = (offset >> 32) & 0xFFFFFFFF;
this->pin_ = AU_SHARED_FROM_THIS;
auto ret = ::ReadFileEx(this->handle_->handle, buffer, length, &overlap_, GenericCompletionRoutine);
return TranslateNtStatus(this, ret);
}
bool NtAsyncFileTransaction::StartWrite(AuUInt64 offset, const void *buffer, AuUInt32 length)
{
if (std::exchange(this->latch_, {}))
if (std::exchange(this->pin_, AuSharedFromThis()))
{
return {};
}
@ -206,7 +205,6 @@ namespace Aurora::IO::FS
this->lastAbstractOffset_ = offset;
this->overlap_.Offset = offset & 0xFFFFFFFF;
this->overlap_.OffsetHigh = (offset >> 32) & 0xFFFFFFFF;
this->pin_ = AU_SHARED_FROM_THIS;
auto ret = ::WriteFileEx(this->handle_->handle, buffer, length, &overlap_, GenericCompletionRoutine);
return TranslateNtStatus(this, ret);
}
@ -218,15 +216,14 @@ namespace Aurora::IO::FS
return;
}
if (this->sub_)
auto hold = std::exchange(this->pin_, {}); // this has side effects
if (hold->sub_)
{
DWORD read {};
GetOverlappedResult(this->handle_->handle, &this->overlap_, &read, false);
this->sub_->OnAsyncFileOpFinished(this->lastAbstractOffset_, read);
GetOverlappedResult(hold->handle_->handle, &hold->overlap_, &read, false);
hold->sub_->OnAsyncFileOpFinished(hold->lastAbstractOffset_, read);
}
// TODO: test for write after free
std::exchange(this->pin_, {});
}
bool NtAsyncFileTransaction::Complete()