77#include <memory.h>
88#include <assert.h>
99
10- void * application_main_thread_id = 0 ;
11- void * main_browser_thread_id = 0 ;
10+ pthread_t application_thread_id = 0 ;
11+ pthread_t main_runtime_thread_id = 0 ;
1212
13- volatile int saw_keydown_event_on_enter_key_on_application_main_thread = 0 ;
14- volatile int saw_keydown_event_on_enter_key_on_main_browser_thread = 0 ;
13+ volatile int saw_keydown_event_on_enter_key_on_application_thread = 0 ;
14+ volatile int saw_keydown_event_on_enter_key_on_main_runtime_thread = 0 ;
1515volatile int saw_keypress_event_on_enter_key = 0 ;
1616
1717void ReportResult (int code )
@@ -23,41 +23,41 @@ void ReportResult(int code)
2323 exit (code );
2424}
2525
26- EM_BOOL keydown_callback_on_application_main_thread (int eventType , const EmscriptenKeyboardEvent * e , void * userData )
26+ EM_BOOL keydown_callback_on_application_thread (int eventType , const EmscriptenKeyboardEvent * e , void * userData )
2727{
2828 int dom_pk_code = emscripten_compute_dom_pk_code (e -> code );
29- printf ("keydown_callback_on_application_main_thread received on pthread: %p, application_main_thread_id : %p, dom_pk_code: %s\n" , ( void * ) pthread_self (), application_main_thread_id , emscripten_dom_pk_code_to_string (dom_pk_code ));
30- assert (( void * ) pthread_self () == application_main_thread_id );
29+ printf ("keydown_callback_on_application_thread received on pthread: %p, application_thread_id : %p, dom_pk_code: %s\n" , pthread_self (), application_thread_id , emscripten_dom_pk_code_to_string (dom_pk_code ));
30+ assert (pthread_self () == application_thread_id );
3131
32- if (dom_pk_code == DOM_PK_ENTER ) saw_keydown_event_on_enter_key_on_application_main_thread = 1 ;
32+ if (dom_pk_code == DOM_PK_ENTER ) saw_keydown_event_on_enter_key_on_application_thread = 1 ;
3333 return 0 ;
3434}
3535
36- EM_BOOL keydown_callback_on_main_browser_thread (int eventType , const EmscriptenKeyboardEvent * e , void * userData )
36+ EM_BOOL keydown_callback_on_main_runtime_thread (int eventType , const EmscriptenKeyboardEvent * e , void * userData )
3737{
3838 int dom_pk_code = emscripten_compute_dom_pk_code (e -> code );
39- printf ("keydown_callback_on_main_browser_thread received on pthread: %p, main_browser_thread_id ; %p, dom_pk_code: %s\n" , ( void * ) pthread_self (), main_browser_thread_id , emscripten_dom_pk_code_to_string (dom_pk_code ));
40- assert (( void * ) pthread_self () == main_browser_thread_id );
39+ printf ("keydown_callback_on_main_runtime_thread received on pthread: %p, main_runtime_thread_id ; %p, dom_pk_code: %s\n" , pthread_self (), main_runtime_thread_id , emscripten_dom_pk_code_to_string (dom_pk_code ));
40+ assert (pthread_self () == main_runtime_thread_id );
4141
4242#if __EMSCRIPTEN_PTHREADS__
4343 EmscriptenKeyboardEvent * duplicatedEventStruct = malloc (sizeof (* e ));
4444 memcpy (duplicatedEventStruct , e , sizeof (* e ));
45- emscripten_dispatch_to_thread (application_main_thread_id , EM_FUNC_SIG_IIII , keydown_callback_on_application_main_thread , duplicatedEventStruct , eventType , duplicatedEventStruct , userData );
45+ emscripten_dispatch_to_thread (application_thread_id , EM_FUNC_SIG_IIII , keydown_callback_on_application_thread , duplicatedEventStruct , eventType , duplicatedEventStruct , userData );
4646#else
47- keydown_callback_on_application_main_thread (eventType , e , userData );
47+ keydown_callback_on_application_thread (eventType , e , userData );
4848#endif
4949
50- if (dom_pk_code == DOM_PK_ENTER ) saw_keydown_event_on_enter_key_on_main_browser_thread = 1 ;
50+ if (dom_pk_code == DOM_PK_ENTER ) saw_keydown_event_on_enter_key_on_main_runtime_thread = 1 ;
5151
5252 return dom_pk_code == DOM_PK_ENTER ; // Suppress default event handling for the enter/return key so that it should not generate the keypress event.
5353}
5454
5555
56- EM_BOOL keypress_callback_on_application_main_thread (int eventType , const EmscriptenKeyboardEvent * e , void * userData )
56+ EM_BOOL keypress_callback_on_application_thread (int eventType , const EmscriptenKeyboardEvent * e , void * userData )
5757{
5858 int dom_pk_code = emscripten_compute_dom_pk_code (e -> code );
59- printf ("keypress_callback_on_application_main_thread received on pthread: %p, application_main_thread_id ; %p, dom_pk_code: %s\n" , ( void * ) pthread_self (), application_main_thread_id , emscripten_dom_pk_code_to_string (dom_pk_code ));
60- assert (( void * ) pthread_self () == application_main_thread_id );
59+ printf ("keypress_callback_on_application_thread received on pthread: %p, application_thread_id ; %p, dom_pk_code: %s\n" , pthread_self (), application_thread_id , emscripten_dom_pk_code_to_string (dom_pk_code ));
60+ assert (pthread_self () == application_thread_id );
6161
6262 if (dom_pk_code == DOM_PK_ENTER )
6363 {
@@ -68,23 +68,23 @@ EM_BOOL keypress_callback_on_application_main_thread(int eventType, const Emscri
6868 return 0 ;
6969}
7070
71- EM_BOOL keyup_callback_on_application_main_thread (int eventType , const EmscriptenKeyboardEvent * e , void * userData )
71+ EM_BOOL keyup_callback_on_application_thread (int eventType , const EmscriptenKeyboardEvent * e , void * userData )
7272{
7373 int dom_pk_code = emscripten_compute_dom_pk_code (e -> code );
74- printf ("keyup_callback_on_application_main_thread received on pthread: %p, application_main_thread_id ; %p, dom_pk_code: %s\n" , ( void * ) pthread_self (), application_main_thread_id , emscripten_dom_pk_code_to_string (dom_pk_code ));
75- assert (( void * ) pthread_self () == application_main_thread_id );
74+ printf ("keyup_callback_on_application_thread received on pthread: %p, application_thread_id ; %p, dom_pk_code: %s\n" , pthread_self (), application_thread_id , emscripten_dom_pk_code_to_string (dom_pk_code ));
75+ assert (pthread_self () == application_thread_id );
7676
7777 if (dom_pk_code == DOM_PK_ENTER )
7878 {
79- if (!saw_keydown_event_on_enter_key_on_application_main_thread )
79+ if (!saw_keydown_event_on_enter_key_on_application_thread )
8080 {
81- printf ("Test failed! KeyUp event came through, but a KeyDown event should have first been processed on the application main thread!\n" );
81+ printf ("Test failed! KeyUp event came through, but a KeyDown event should have first been processed on the application thread!\n" );
8282 ReportResult (12346 ); // FAIL
8383 }
84- if (!saw_keydown_event_on_enter_key_on_main_browser_thread )
84+ if (!saw_keydown_event_on_enter_key_on_main_runtime_thread )
8585 {
86- printf ("Test failed! KeyUp event came through, but a KeyDown event should have first been processed on the main browser thread!\n" );
87- ReportResult (12347 ); // FAIL
86+ printf ("Test failed! KeyUp event came through, but a KeyDown event should have first been processed on the main runtime thread!\n" );
87+ ReportResult (12347 ); // FAIL
8888 }
8989 if (saw_keypress_event_on_enter_key )
9090 {
@@ -101,14 +101,14 @@ int main()
101101{
102102 main_runtime_thread_id = emscripten_main_runtime_thread_id ();
103103 assert (main_runtime_thread_id );
104- application_main_thread_id = ( void * ) pthread_self ();
105- assert (application_main_thread_id );
104+ application_thread_id = pthread_self ();
105+ assert (application_thread_id );
106106
107- printf ("Main runtime thread ID: %p, application main thread ID: %p\n" , main_runtime_thread_id , application_main_thread_id );
107+ printf ("Main runtime thread ID: %p, application thread ID: %p\n" , main_runtime_thread_id , application_thread_id );
108108
109- emscripten_set_keydown_callback_on_thread (0 , 0 , 1 , keydown_callback_on_main_browser_thread , EM_CALLBACK_THREAD_CONTEXT_MAIN_RUNTIME_THREAD );
110- emscripten_set_keypress_callback_on_thread (0 , 0 , 1 , keypress_callback_on_application_main_thread , EM_CALLBACK_THREAD_CONTEXT_CALLING_THREAD );
111- emscripten_set_keyup_callback_on_thread (0 , 0 , 1 , keyup_callback_on_application_main_thread , EM_CALLBACK_THREAD_CONTEXT_CALLING_THREAD );
109+ emscripten_set_keydown_callback_on_thread (EMSCRIPTEN_EVENT_TARGET_WINDOW , 0 , 1 , keydown_callback_on_main_runtime_thread , EM_CALLBACK_THREAD_CONTEXT_MAIN_RUNTIME_THREAD );
110+ emscripten_set_keypress_callback_on_thread (EMSCRIPTEN_EVENT_TARGET_WINDOW , 0 , 1 , keypress_callback_on_application_thread , EM_CALLBACK_THREAD_CONTEXT_CALLING_THREAD );
111+ emscripten_set_keyup_callback_on_thread (EMSCRIPTEN_EVENT_TARGET_WINDOW , 0 , 1 , keyup_callback_on_application_thread , EM_CALLBACK_THREAD_CONTEXT_CALLING_THREAD );
112112
113113 printf ("Please press the Enter key.\n" );
114114
0 commit comments