Skip to content

Commit a0b78ce

Browse files
zfiguraGuy1524
authored andcommitted
ntdll, server: Revert to old implementation of hung queue detection.
By manually notifying the server every time we enter and exit a message wait. The hung queue logic keeps breaking. In the case of bug #9 it was breaking because we were waiting for more than 5 seconds on our queue and then someone sent us a message with SMTO_ABORTIFHUNG. Just stop fighting against the server and try to coöperate with it instead. It takes two extra server calls, but ideally the GUI thread isn't going to be in the same sort of performance- critical code that this patchset was written for.
1 parent a70819c commit a0b78ce

File tree

3 files changed

+73
-21
lines changed

3 files changed

+73
-21
lines changed

dlls/ntdll/esync.c

Lines changed: 40 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -831,8 +831,8 @@ static void update_grabbed_object( struct esync *obj )
831831

832832
/* A value of STATUS_NOT_IMPLEMENTED returned from this function means that we
833833
* need to delegate to server_select(). */
834-
NTSTATUS esync_wait_objects( DWORD count, const HANDLE *handles, BOOLEAN wait_any,
835-
BOOLEAN alertable, const LARGE_INTEGER *timeout )
834+
static NTSTATUS __esync_wait_objects( DWORD count, const HANDLE *handles,
835+
BOOLEAN wait_any, BOOLEAN alertable, const LARGE_INTEGER *timeout )
836836
{
837837
static const LARGE_INTEGER zero = {0};
838838

@@ -895,22 +895,11 @@ NTSTATUS esync_wait_objects( DWORD count, const HANDLE *handles, BOOLEAN wait_an
895895

896896
if (objs[count - 1] && objs[count - 1]->type == ESYNC_QUEUE)
897897
{
898-
select_op_t select_op;
899-
900898
/* Last object in the list is a queue, which means someone is using
901899
* MsgWaitForMultipleObjects(). We have to wait not only for the server
902900
* fd (signaled on send_message, etc.) but also the USER driver's fd
903901
* (signaled on e.g. X11 events.) */
904902
msgwait = TRUE;
905-
906-
/* We need to let the server know we are doing a message wait, for two
907-
* reasons. First one is WaitForInputIdle(). Second one is checking for
908-
* hung queues. Do it like this. */
909-
select_op.wait.op = SELECT_WAIT;
910-
select_op.wait.handles[0] = wine_server_obj_handle( handles[count - 1] );
911-
ret = server_select( &select_op, offsetof( select_op_t, wait.handles[1] ), 0, &zero );
912-
if (ret != STATUS_WAIT_0 && ret != STATUS_TIMEOUT)
913-
ERR("Unexpected ret %#x\n", ret);
914903
}
915904

916905
if (has_esync && has_server)
@@ -1283,6 +1272,44 @@ NTSTATUS esync_wait_objects( DWORD count, const HANDLE *handles, BOOLEAN wait_an
12831272
return ret;
12841273
}
12851274

1275+
/* We need to let the server know when we are doing a message wait, and when we
1276+
* are done with one, so that all of the code surrounding hung queues works.
1277+
* We also need this for WaitForInputIdle(). */
1278+
static void server_set_msgwait( int in_msgwait )
1279+
{
1280+
SERVER_START_REQ( esync_msgwait )
1281+
{
1282+
req->in_msgwait = in_msgwait;
1283+
wine_server_call( req );
1284+
}
1285+
SERVER_END_REQ;
1286+
}
1287+
1288+
/* This is a very thin wrapper around the proper implementation above. The
1289+
* purpose is to make sure the server knows when we are doing a message wait.
1290+
* This is separated into a wrapper function since there are at least a dozen
1291+
* exit paths from esync_wait_objects(). */
1292+
NTSTATUS esync_wait_objects( DWORD count, const HANDLE *handles, BOOLEAN wait_any,
1293+
BOOLEAN alertable, const LARGE_INTEGER *timeout )
1294+
{
1295+
BOOL msgwait = FALSE;
1296+
struct esync *obj;
1297+
NTSTATUS ret;
1298+
1299+
if (!get_object( handles[count - 1], &obj ) && obj->type == ESYNC_QUEUE)
1300+
{
1301+
msgwait = TRUE;
1302+
server_set_msgwait( 1 );
1303+
}
1304+
1305+
ret = __esync_wait_objects( count, handles, wait_any, alertable, timeout );
1306+
1307+
if (msgwait)
1308+
server_set_msgwait( 0 );
1309+
1310+
return ret;
1311+
}
1312+
12861313
NTSTATUS esync_signal_and_wait( HANDLE signal, HANDLE wait, BOOLEAN alertable,
12871314
const LARGE_INTEGER *timeout )
12881315
{

server/protocol.def

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4068,7 +4068,11 @@ struct handle_info
40684068

40694069
/* Retrieve the fd to wait on for user APCs. */
40704070
@REQ(get_esync_apc_fd)
4071-
@REPLY
4071+
@END
4072+
4073+
/* Notify the server that we are doing a message wait (or done with one). */
4074+
@REQ(esync_msgwait)
4075+
int in_msgwait; /* are we in a message wait? */
40724076
@END
40734077

40744078
enum esync_type

server/queue.c

Lines changed: 28 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,7 @@ struct msg_queue
126126
struct thread *thread; /* reference to the thread owning the queue */
127127
struct fd *fd; /* optional file descriptor to poll */
128128
int esync_fd; /* esync file descriptor (signalled on message) */
129+
int esync_in_msgwait; /* our thread is currently waiting on us */
129130
unsigned int wake_bits; /* wakeup bits */
130131
unsigned int wake_mask; /* wakeup mask */
131132
unsigned int changed_bits; /* changed wakeup bits */
@@ -975,7 +976,21 @@ static void cleanup_results( struct msg_queue *queue )
975976
/* check if the thread owning the queue is hung (not checking for messages) */
976977
static int is_queue_hung( struct msg_queue *queue )
977978
{
978-
return (current_time - queue->last_get_msg > 5 * TICKS_PER_SEC);
979+
struct wait_queue_entry *entry;
980+
981+
if (current_time - queue->last_get_msg <= 5 * TICKS_PER_SEC)
982+
return 0; /* less than 5 seconds since last get message -> not hung */
983+
984+
LIST_FOR_EACH_ENTRY( entry, &queue->obj.wait_queue, struct wait_queue_entry, entry )
985+
{
986+
if (get_wait_queue_thread(entry)->queue == queue)
987+
return 0; /* thread is waiting on queue -> not hung */
988+
}
989+
990+
if (do_esync() && queue->esync_in_msgwait)
991+
return 0; /* thread is waiting on queue in absentia -> not hung */
992+
993+
return 1;
979994
}
980995

981996
static int msg_queue_add_queue( struct object *obj, struct wait_queue_entry *entry )
@@ -991,12 +1006,6 @@ static int msg_queue_add_queue( struct object *obj, struct wait_queue_entry *ent
9911006
}
9921007
if (process->idle_event && !(queue->wake_mask & QS_SMRESULT)) set_event( process->idle_event );
9931008

994-
/* On Windows, we are considered hung iff we have not somehow processed
995-
* messages OR done a MsgWait call in the last 5 seconds. Note that in the
996-
* latter case repeatedly waiting for 0 seconds is not hung, but waiting
997-
* forever is hung, so this is correct. */
998-
queue->last_get_msg = current_time;
999-
10001009
if (queue->fd && list_empty( &obj->wait_queue )) /* first on the queue */
10011010
set_fd_events( queue->fd, POLLIN );
10021011
add_queue( obj, entry );
@@ -1688,6 +1697,7 @@ static int send_hook_ll_message( struct desktop *desktop, struct message *hardwa
16881697

16891698
if (!(hook_thread = get_first_global_hook( id ))) return 0;
16901699
if (!(queue = hook_thread->queue)) return 0;
1700+
if (is_queue_hung( queue )) return 0;
16911701

16921702
if (!(msg = mem_alloc( sizeof(*msg) ))) return 0;
16931703

@@ -3295,3 +3305,14 @@ DECL_HANDLER(update_rawinput_devices)
32953305
e = find_rawinput_device( 1, 6 );
32963306
current->process->rawinput_kbd = e ? &e->device : NULL;
32973307
}
3308+
3309+
DECL_HANDLER(esync_msgwait)
3310+
{
3311+
struct msg_queue *queue = get_current_queue();
3312+
3313+
if (!queue) return;
3314+
queue->esync_in_msgwait = req->in_msgwait;
3315+
3316+
if (current->process->idle_event && !(queue->wake_mask & QS_SMRESULT))
3317+
set_event( current->process->idle_event );
3318+
}

0 commit comments

Comments
 (0)