Skip to content

Commit

Permalink
fixup! ntdll: Simulate async file read and IO cancellation to workaro…
Browse files Browse the repository at this point in the history
…und AC:Odyssey out of order dialogues bug.

CW-Bug-Id: #21711
  • Loading branch information
Paul Gofman committed Mar 5, 2024
1 parent 9cf34c9 commit 34bbb1a
Showing 1 changed file with 13 additions and 0 deletions.
13 changes: 13 additions & 0 deletions dlls/ntdll/unix/file.c
Original file line number Diff line number Diff line change
Expand Up @@ -5648,6 +5648,7 @@ struct async_file_read_job
LONG cancelled;
struct list queue_entry;
struct async_file_read_job *next;
ULONG64 queue_time_mcs;
};


Expand All @@ -5668,7 +5669,9 @@ static void *async_file_read_thread(void *dummy)
ULONG buffer_length = 0;
void *buffer = NULL;
struct list *entry;
struct timespec ts;
NTSTATUS status;
ULONG64 delay;
ULONG total;
int result;

Expand Down Expand Up @@ -5719,6 +5722,13 @@ static void *async_file_read_thread(void *dummy)
break;
}

clock_gettime( CLOCK_MONOTONIC, &ts );
delay = ts.tv_sec * (ULONG64)1000000 + ts.tv_nsec / 1000 - job->queue_time_mcs;
if (delay < 1000)
usleep( 1000 - delay );
else
usleep( 50 );

total = result;
status = (total || !job->length) ? STATUS_SUCCESS : STATUS_END_OF_FILE;
done:
Expand Down Expand Up @@ -5779,6 +5789,7 @@ static NTSTATUS queue_async_file_read( HANDLE handle, int unix_handle, int needs
IO_STATUS_BLOCK *io, void *buffer, ULONG length, LARGE_INTEGER *offset )
{
struct async_file_read_job *job;
struct timespec ts;

pthread_once( &async_file_read_once, async_file_read_init );

Expand Down Expand Up @@ -5810,6 +5821,8 @@ static NTSTATUS queue_async_file_read( HANDLE handle, int unix_handle, int needs
job->offset = *offset;
job->thread_id = GetCurrentThreadId();
job->cancelled = 0;
clock_gettime( CLOCK_MONOTONIC, &ts );
job->queue_time_mcs = ts.tv_sec * (ULONG64)1000000 + ts.tv_nsec / 1000;

list_add_tail( &async_file_read_queue, &job->queue_entry );

Expand Down

0 comments on commit 34bbb1a

Please sign in to comment.