Check-in [d141949d20]

Many hyperlinks are disabled.
Use anonymous login to enable hyperlinks.

Overview
Comment:Use a specific monitor object for task status notifications to make it easier to notify when a task changes state for later checking.
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA1:d141949d2064cba87e225694752ce4f349eb4bc0
User & Date: stephanie.gawroriski 2019-01-05 21:29:46
Context
2019-01-06
08:02
Backup developer notes. check-in: 460a32ece8 user: squirreljme tags: trunk
2019-01-05
21:29
Use a specific monitor object for task status notifications to make it easier to notify when a task changes state for later checking. check-in: d141949d20 user: stephanie.gawroriski tags: trunk
21:18
Base for creating new tasks, no threads yet; Add base for clas loader; Have ExitAwaiter wait on TaskStatus instead of on an actual task since it would complicate things. check-in: fae09851d5 user: stephanie.gawroriski tags: trunk
Changes
Hide Diffs Unified Diffs Ignore Whitespace Patch

Changes to runt/libs/summercoat-vm/cc/squirreljme/vm/summercoat/TaskStatus.java.

16
17
18
19
20
21
22



23
24
25
26
27
28
29
..
40
41
42
43
44
45
46

47

48
49
50

51




52
53
54
55
 * This contains the status for a single task and is used to detect when a
 * task is running and if it has ever exited.
 *
 * @since 2019/01/05
 */
public class TaskStatus
{



	/** The ID of this task. */
	protected final int id;
	
	/** The exit code for this virtual machine. */
	volatile int _exitcode =
		Integer.MIN_VALUE;
	
................................................................................
	 * it needs to have UI events sent to it.
	 */
	volatile NativeDisplayEventCallback _eventcallback;
	
	/**
	 * Initializes the task.
	 *

	 * @param __id The ID of the task.

	 * @since 2019/01/05
	 */
	public TaskStatus(int __id)

	{




		this.id = __id;
	}
}








>
>
>







 







>

>


|
>

>
>
>
>




16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
..
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
 * This contains the status for a single task and is used to detect when a
 * task is running and if it has ever exited.
 *
 * @since 2019/01/05
 */
public class TaskStatus
{
	/** The monitor or the task statuses, used to signal state changes. */
	protected final Object monitor;
	
	/** The ID of this task. */
	protected final int id;
	
	/** The exit code for this virtual machine. */
	volatile int _exitcode =
		Integer.MIN_VALUE;
	
................................................................................
	 * it needs to have UI events sent to it.
	 */
	volatile NativeDisplayEventCallback _eventcallback;
	
	/**
	 * Initializes the task.
	 *
	 * @param __m The monitor to notify when the task changes state.
	 * @param __id The ID of the task.
	 * @throws NullPointerException On null arguments.
	 * @since 2019/01/05
	 */
	public TaskStatus(Object __m, int __id)
		throws NullPointerException
	{
		if (__m == null)
			throw new NullPointerException("NARG");
		
		this.monitor = __m;
		this.id = __id;
	}
}

Changes to runt/libs/summercoat-vm/cc/squirreljme/vm/summercoat/TaskStatuses.java.

18
19
20
21
22
23
24




25
26
27
28
29
30
31
..
38
39
40
41
42
43
44
45

46
47
48
49
50
51
52
53
54
..
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90

91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
 * running at once, it allows the status to be retrieved for each task
 * regardless of whether it is directly accessible or not.
 *
 * @since 2019/01/05
 */
public final class TaskStatuses
{




	/** Tasks which are currently available. */
	private final Map<Integer, TaskStatus> _statuses =
		new HashMap<>();
	
	/** The next task ID. */
	private volatile int _nextid;
	
................................................................................
	 * @throws InterruptedException If the thread was interrupted while this
	 * was requested.
	 * @since 2019/01/05
	 */
	public final boolean awaitFinished(long __ms)
		throws InterruptedException
	{
		// Lock on self since we control the map

		Map<Integer, TaskStatus> statuses = this._statuses;
		synchronized (this)
		{
			// This loop is only here for the wait forever case because signal
			// might end otherwise.
			for (boolean initrun = true;; initrun = false)
			{
				// Find any task which is not in the exit state, because if
				// there is then 
................................................................................
				// saying that things are running
				if (!initrun && __ms != 0)
					return false;
				
				// Wait for signal on self, 0 is to wait forever
				// If InterruptedException is thrown then it will be sent to
				// the calling method accordingly
				this.wait(__ms);
			}
		}
	}
	
	/**
	 * Creates a status holder for a task giving it a unique ID.
	 *
	 * @return The newly created task with a newly allocated ID.
	 * @since 2019/01/05
	 */
	public final TaskStatus createNew()
	{
		// Lock on self

		synchronized (this)
		{
			// Setup new task with this ID
			int tid;
			TaskStatus rv = new TaskStatus((tid = this._nextid++));
			
			// Need to keep track of this task, so we know when it exits
			this._statuses.put(tid, rv);
			
			// And return the created task
			return rv;
		}
	}
}








>
>
>
>







 







|
>

|







 







|













>
|



|










18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
..
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
..
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
 * running at once, it allows the status to be retrieved for each task
 * regardless of whether it is directly accessible or not.
 *
 * @since 2019/01/05
 */
public final class TaskStatuses
{
	/** The monitor for thread status. */
	protected final Object monitor =
		new Object();
	
	/** Tasks which are currently available. */
	private final Map<Integer, TaskStatus> _statuses =
		new HashMap<>();
	
	/** The next task ID. */
	private volatile int _nextid;
	
................................................................................
	 * @throws InterruptedException If the thread was interrupted while this
	 * was requested.
	 * @since 2019/01/05
	 */
	public final boolean awaitFinished(long __ms)
		throws InterruptedException
	{
		// Lock on our monitor since we need notifications
		Object monitor = this.monitor;
		Map<Integer, TaskStatus> statuses = this._statuses;
		synchronized (monitor)
		{
			// This loop is only here for the wait forever case because signal
			// might end otherwise.
			for (boolean initrun = true;; initrun = false)
			{
				// Find any task which is not in the exit state, because if
				// there is then 
................................................................................
				// saying that things are running
				if (!initrun && __ms != 0)
					return false;
				
				// Wait for signal on self, 0 is to wait forever
				// If InterruptedException is thrown then it will be sent to
				// the calling method accordingly
				monitor.wait(__ms);
			}
		}
	}
	
	/**
	 * Creates a status holder for a task giving it a unique ID.
	 *
	 * @return The newly created task with a newly allocated ID.
	 * @since 2019/01/05
	 */
	public final TaskStatus createNew()
	{
		// Lock on self
		Object monitor = this.monitor;
		synchronized (monitor)
		{
			// Setup new task with this ID
			int tid;
			TaskStatus rv = new TaskStatus(monitor, (tid = this._nextid++));
			
			// Need to keep track of this task, so we know when it exits
			this._statuses.put(tid, rv);
			
			// And return the created task
			return rv;
		}
	}
}