Remove VM-locking yield mode per discussion

This commit is contained in:
Tim Mickel 2016-06-30 16:57:12 -04:00
parent 9a7ab57f6f
commit 6daee9a70e
4 changed files with 2 additions and 44 deletions

View file

@ -78,11 +78,10 @@ Scratch3OperatorsBlocks.prototype.not = function (args) {
return Boolean(!args.OPERAND);
};
Scratch3OperatorsBlocks.prototype.random = function (args, util) {
Scratch3OperatorsBlocks.prototype.random = function (args) {
// As a demo, this implementation of random returns after 1 second of yield.
// @todo Match Scratch 2.0 implementation with int-truncation.
// See: http://bit.ly/1Qc0GzC
util.yieldAndBlock();
var examplePromise = new Promise(function(resolve) {
setTimeout(function() {
var res = (Math.random() * (args.TO - args.FROM)) + args.FROM;

View file

@ -74,7 +74,6 @@ var execute = function (sequencer, thread) {
var primitiveReportedValue = null;
primitiveReportedValue = blockFunction(argValues, {
yield: thread.yield.bind(thread),
yieldAndBlock: thread.yieldAndBlock.bind(thread),
done: function() {
sequencer.proceedThread(thread);
},

View file

@ -32,13 +32,6 @@ Sequencer.WORK_TIME = 10;
Sequencer.prototype.stepThreads = function (threads) {
// Start counting toward WORK_TIME
this.timer.start();
// Check for a blocking thread.
var blockingThread = this.getBlockingThread_(threads);
if (blockingThread) {
// Attempt to resolve any timeouts, but otherwise stop stepping.
blockingThread.resolveTimeouts();
return [];
}
// List of threads which have been killed by this step.
var inactiveThreads = [];
// If all of the threads are yielding, we should yield.
@ -70,10 +63,6 @@ Sequencer.prototype.stepThreads = function (threads) {
activeThread.status = Thread.STATUS_RUNNING;
// @todo Deal with the return value
}
// Has the thread gone into "blocking" mode? If so, stop stepping.
if (activeThread.status === Thread.STATUS_YIELD_BLOCK) {
return inactiveThreads;
}
if (activeThread.stack.length === 0 &&
activeThread.status === Thread.STATUS_DONE) {
// Finished with this thread - tell runtime to clean it up.
@ -89,20 +78,6 @@ Sequencer.prototype.stepThreads = function (threads) {
return inactiveThreads;
};
/**
* Return the thread blocking all other threads, if one exists.
* @param {Array.<Thread>} threads List of which threads to check.
* @return {?Thread} The blocking thread if one exists.
*/
Sequencer.prototype.getBlockingThread_ = function (threads) {
for (var i = 0; i < threads.length; i++) {
if (threads[i].status === Thread.STATUS_YIELD_BLOCK) {
return threads[i];
}
}
return null;
};
/**
* Step the requested thread
* @param {!Thread} thread Thread object to step

View file

@ -52,21 +52,13 @@ Thread.STATUS_RUNNING = 0;
*/
Thread.STATUS_YIELD = 1;
/**
* Thread status for a yielded thread that should block all other threads.
* This is desirable when an asynchronous capability should appear to take
* a synchronous amount of time (e.g., color touching color).
* @const
*/
Thread.STATUS_YIELD_BLOCK = 2;
/**
* Thread status for a finished/done thread.
* Thread is moved to this state when the interpreter
* can proceed with execution.
* @const
*/
Thread.STATUS_DONE = 3;
Thread.STATUS_DONE = 2;
/**
* Push stack and update stack frames appropriately.
@ -139,13 +131,6 @@ Thread.prototype.yield = function () {
this.status = Thread.STATUS_YIELD;
};
/**
* Yields the thread and blocks other threads until unyielded.
*/
Thread.prototype.yieldAndBlock = function () {
this.status = Thread.STATUS_YIELD_BLOCK;
};
/**
* Add an execution-synced timeouts for this thread.
* See also: util/yieldtimers.js:timeout