Don't allow thread preemption when resuming a thread.

This commit is contained in:
Yuan Xulei 2015-03-03 19:25:01 +08:00
Родитель 19aa2266cd
Коммит c77a23a8ff
2 изменённых файлов: 4 добавлений и 23 удалений

Просмотреть файл

@ -4,7 +4,7 @@ import gnu.testlet.Testlet;
import gnu.testlet.TestHarness;
public class TestThreadPriority implements Testlet {
public int getExpectedPass() { return 2; }
public int getExpectedPass() { return 1; }
public int getExpectedFail() { return 0; }
public int getExpectedKnownFail() { return 0; }
private static String result = "";
@ -25,10 +25,6 @@ public class TestThreadPriority implements Testlet {
new Prioritized(priorities[i]).start();
}
// The priority of the main thread is 5. Threads with higher priorities
// should preempt the main thread to run first.
th.check(result, "9 7 ");
String expected = "9 7 5 1 ";
try {
while (result.length() < expected.length()) {

Просмотреть файл

@ -682,19 +682,11 @@ module J2ME {
}
}
/*
* @param jump If true, move the context to the first of others who have the
* same priority.
*/
enqueue(ctx: Context, jump: boolean) {
enqueue(ctx: Context) {
var priority = ctx.getPriority();
release || assert(priority >= MIN_PRIORITY && priority <= MAX_PRIORITY,
"Invalid priority: " + priority);
if (jump) {
this._queues[priority].unshift(ctx);
} else {
this._queues[priority].push(ctx);
}
this._queues[priority].push(ctx);
this._top = Math.max(priority, this._top);
}
@ -735,14 +727,7 @@ module J2ME {
* higher priority thread is scheduled to run.
*/
static scheduleRunningContext(ctx: Context) {
// Preempt current thread if the new thread has higher priority
if ($ && ctx.getPriority() > $.ctx.getPriority()) {
Runtime._runningQueue.enqueue($.ctx, true);
Runtime._runningQueue.enqueue(ctx, false);
$.pause("preempt");
} else {
Runtime._runningQueue.enqueue(ctx, false);
}
Runtime._runningQueue.enqueue(ctx);
Runtime.processRunningQueue();
}