Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 18 additions & 3 deletions quasar-core/src/main/java/co/paralleluniverse/fibers/Fiber.java
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ private static long nextFiberId() {
// private int preemptionCredits;
private transient Thread runningThread;
private final SuspendableCallable<V> target;
private byte priority;
private int priority;
private transient ClassLoader contextClassLoader;
private transient AccessControlContext inheritedAccessControlContext;
// These are typed as Object because they store JRE-internal ThreadLocalMap objects, which is a package private
Expand Down Expand Up @@ -176,7 +176,7 @@ public Fiber(String name, FiberScheduler scheduler, int stackSize, SuspendableCa
this.task = scheduler != null ? scheduler.newFiberTask(this) : new FiberForkJoinTask(this);
this.initialStackSize = stackSize;
this.stack = new Stack(this, stackSize > 0 ? stackSize : DEFAULT_STACK_SIZE);
this.priority = (byte)NORM_PRIORITY;
this.priority = NORM_PRIORITY;

if (Debug.isDebug())
record(1, "Fiber", "<init>", "Creating fiber name: %s, scheduler: %s, parent: %s, target: %s, task: %s, stackSize: %s", name, scheduler, parent, target, task, stackSize);
Expand Down Expand Up @@ -230,6 +230,21 @@ public Fiber(String name, int stackSize, SuspendableCallable<V> target) {
this(name, defaultScheduler(), stackSize, target);
}

/**
* The minimum priority that a fiber can have.
*/
public final static int MIN_PRIORITY = Integer.MIN_VALUE;

/**
* The default priority that is assigned to a fiber.
*/
public final static int NORM_PRIORITY = 0;

/**
* The maximum priority that a fiber can have.
*/
public final static int MAX_PRIORITY = Integer.MAX_VALUE;

private static FiberScheduler defaultScheduler() {
final Fiber parent = currentFiber();
if (parent == null)
Expand Down Expand Up @@ -310,7 +325,7 @@ public final Fiber<V> setName(String name) {
public Fiber setPriority(int newPriority) {
if (newPriority > MAX_PRIORITY || newPriority < MIN_PRIORITY)
throw new IllegalArgumentException();
this.priority = (byte) newPriority;
this.priority = newPriority;
return this;
}

Expand Down
15 changes: 0 additions & 15 deletions quasar-core/src/main/java/co/paralleluniverse/strands/Strand.java
Original file line number Diff line number Diff line change
Expand Up @@ -55,21 +55,6 @@ public static Strand of(Fiber fiber) {
return fiber;
}

/**
* The minimum priority that a strand can have.
*/
public final static int MIN_PRIORITY = 1;

/**
* The default priority that is assigned to a strand.
*/
public final static int NORM_PRIORITY = 5;

/**
* The maximum priority that a strand can have.
*/
public final static int MAX_PRIORITY = 10;

/**
* A strand's running state
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -114,20 +114,22 @@ public void run() throws SuspendExecution {
}
});

assertThat(fiber.getPriority(), is(Strand.NORM_PRIORITY));
assertThat(fiber.getPriority(), is(Fiber.NORM_PRIORITY));

fiber.setPriority(3);
assertThat(fiber.getPriority(), is(3));

try {
fiber.setPriority(Strand.MAX_PRIORITY + 1);
fail();
fiber.setPriority(Fiber.MAX_PRIORITY + 1);
if (Fiber.MAX_PRIORITY + 1 != Integer.MIN_VALUE) // Ignore overflow
fail();
} catch (IllegalArgumentException e) {
}

try {
fiber.setPriority(Strand.MIN_PRIORITY - 1);
fail();
fiber.setPriority(Fiber.MIN_PRIORITY - 1);
if (Fiber.MIN_PRIORITY - 1 != Integer.MAX_VALUE) // Ignore underflow
fail();
} catch (IllegalArgumentException e) {
}
}
Expand Down