Modifier and Type | Field and Description |
---|---|
static int |
DEFAULT_STACK_SIZE
Default stack size for the data stack.
|
protected YieldReason |
reason |
Constructor and Description |
---|
Coroutine(CoroutineProto proto)
Creates a new Coroutine from the given CoroutineProto.
|
Coroutine(CoroutineProto proto,
int stackSize)
Creates a new Coroutine from the given CoroutineProto.
|
Modifier and Type | Method and Description |
---|---|
protected static Coroutine |
getActiveCoroutine()
Returns the active Coroutine on this thread or NULL if no coroutine is running.
|
CoroutineProto |
getProto()
Returns the CoroutineProto that is used for this Coroutine
|
YieldReason |
getReason() |
CoroutineState |
getState()
Returns the current state of this Coroutine.
|
void |
markCompleted() |
void |
run()
Runs the Coroutine until it is finished or suspended.
|
static void |
yield()
Suspend the currently running Coroutine on the calling thread.
|
public static final int DEFAULT_STACK_SIZE
protected YieldReason reason
public Coroutine(CoroutineProto proto)
proto
- the CoroutineProto for the Coroutine.public Coroutine(CoroutineProto proto, int stackSize)
proto
- the CoroutineProto for the Coroutine.stackSize
- the initial stack size for the data stackNullPointerException
- when proto is nullIllegalArgumentException
- when stackSize is <= 0public static void yield() throws SuspendableException, IllegalStateException
SuspendableException
- This exception is used for control transfer - don't catch it !IllegalStateException
- If not called from a Coroutineprotected static Coroutine getActiveCoroutine()
public CoroutineProto getProto()
public CoroutineState getState()
Returns the current state of this Coroutine. May be called by the Coroutine itself but should not be called by another thread.
The Coroutine starts in the state NEW then changes to RUNNING. From RUNNING it may change to FINISHED or SUSPENDED. SUSPENDED can only change to RUNNING by calling run() again.
run()
public void markCompleted()
public YieldReason getReason()
public void run() throws IllegalStateException
run
in interface Runnable
IllegalStateException
- if the Coroutine is currently running or already finished.Copyright © 2015 Rice University - Department of Computer Science. All rights reserved.