emscripten_push_main_loop_blocker
This commit is contained in:
Родитель
42f93a46a6
Коммит
3b6025a2c4
|
@ -12,6 +12,7 @@ mergeInto(LibraryManager.library, {
|
|||
scheduler: null,
|
||||
shouldPause: false,
|
||||
paused: false,
|
||||
queue: [],
|
||||
pause: function() {
|
||||
Browser.mainLoop.shouldPause = true;
|
||||
},
|
||||
|
@ -220,6 +221,11 @@ mergeInto(LibraryManager.library, {
|
|||
|
||||
var jsFunc = FUNCTION_TABLE[func];
|
||||
var wrapper = function() {
|
||||
if (Browser.mainLoop.queue.length > 0) {
|
||||
Browser.mainLoop.queue.shift()();
|
||||
Browser.mainLoop.scheduler();
|
||||
return;
|
||||
}
|
||||
if (Browser.mainLoop.shouldPause) {
|
||||
// catch pauses from non-main loop sources
|
||||
Browser.mainLoop.paused = true;
|
||||
|
@ -247,19 +253,23 @@ mergeInto(LibraryManager.library, {
|
|||
Browser.mainLoop.scheduler();
|
||||
},
|
||||
|
||||
emscripten_cancel_main_loop: function(func) {
|
||||
emscripten_cancel_main_loop: function() {
|
||||
Browser.mainLoop.scheduler = null;
|
||||
Browser.mainLoop.shouldPause = true;
|
||||
},
|
||||
|
||||
emscripten_pause_main_loop: function(func) {
|
||||
emscripten_pause_main_loop: function() {
|
||||
Browser.mainLoop.pause();
|
||||
},
|
||||
|
||||
emscripten_resume_main_loop: function(func) {
|
||||
emscripten_resume_main_loop: function() {
|
||||
Browser.mainLoop.resume();
|
||||
},
|
||||
|
||||
emscripten_push_main_loop_blocker: function(func) {
|
||||
Browser.mainLoop.queue.push(FUNCTION_TABLE[func]);
|
||||
},
|
||||
|
||||
emscripten_async_call: function(func, millis) {
|
||||
Module['noExitRuntime'] = true;
|
||||
|
||||
|
|
|
@ -48,6 +48,12 @@ extern void emscripten_pause_main_loop();
|
|||
extern void emscripten_resume_main_loop();
|
||||
extern void emscripten_cancel_main_loop();
|
||||
|
||||
/*
|
||||
* Add a function to a queue of events that will execute
|
||||
* before the main loop will continue.
|
||||
*/
|
||||
extern void emscripten_push_main_loop_blocker(void (*func)());
|
||||
|
||||
/*
|
||||
* Call a C function asynchronously, that is, after returning
|
||||
* control to the JS event loop. This is done by a setTimeout.
|
||||
|
|
|
@ -9,6 +9,19 @@ int last = 0;
|
|||
|
||||
extern "C" {
|
||||
|
||||
bool pre1ed = false;
|
||||
bool pre2ed = false;
|
||||
void pre1() {
|
||||
assert(!pre1ed);
|
||||
assert(!pre2ed);
|
||||
pre1ed = true;
|
||||
}
|
||||
void pre2() {
|
||||
assert(pre1ed);
|
||||
assert(!pre2ed);
|
||||
pre2ed = true;
|
||||
}
|
||||
|
||||
bool fived = false;
|
||||
void five() {
|
||||
fived = true;
|
||||
|
@ -22,7 +35,14 @@ void mainey() {
|
|||
emscripten_pause_main_loop();
|
||||
emscripten_async_call(five, 1000);
|
||||
} else if (counter == 22) { // very soon after 20, so without pausing we fail
|
||||
int result = fived;
|
||||
assert(fived);
|
||||
emscripten_push_main_loop_blocker(pre1);
|
||||
emscripten_push_main_loop_blocker(pre2);
|
||||
} else if (counter == 23) {
|
||||
assert(pre1ed);
|
||||
assert(pre2ed);
|
||||
printf("Good!\n");
|
||||
int result = 1;
|
||||
REPORT_RESULT();
|
||||
}
|
||||
}
|
||||
|
|
Загрузка…
Ссылка в новой задаче