Check-in [679430edaf]

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

Overview
Comment:Add means to protect runMethod() from being called across threads.
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA1:679430edafd35ab9115fc465093d59cea4d51397
User & Date: stephanie.gawroriski 2019-01-11 02:44:59
Context
2019-01-11
08:02
Backup developer notes. check-in: 2bfb68e48c user: squirreljme tags: trunk
02:44
Add means to protect runMethod() from being called across threads. check-in: 679430edaf user: stephanie.gawroriski tags: trunk
02:29
Add check for the current thread in another method and call that to make sure calls are not done out of thread. check-in: 915ab69ac6 user: stephanie.gawroriski tags: trunk
Changes
Hide Diffs Unified Diffs Ignore Whitespace Patch

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

32
33
34
35
36
37
38






39
40
41
42
43
44
45
...
106
107
108
109
110
111
112
113


114


























115















116
117
118
119
120
121
122
...
230
231
232
233
234
235
236

237
238
239
240
241
242
243
244
245

246
247

248
249
250
	
	/** The task status this reports on. */
	protected final TaskStatus status;
	
	/** Has this thread been started via the run method. */
	private volatile boolean _didstart;
	






	/**
	 * Initializes the thread.
	 *
	 * @param __id The thread ID.
	 * @param __s The task status.
	 * @throws NullPointerException On null arguments.
	 * @since 2019/01/10
................................................................................
	public Value runMethod(MethodHandle __mh, Value... __args)
		throws IllegalStateException, NullPointerException
	{
		if (__mh == null)
			throw new NullPointerException("NARG");
		
		// Must be the same thread
		__checkSameThread();


		


























		throw new todo.TODO();















	}
	
	/**
	 * Creates a new array instance.
	 *
	 * @param __cl The class to create an array of, this is not the component
	 * type.
................................................................................
	}
	
	/**
	 * Checks that the call was done in the same thread, since when the thread
	 * is running it will completely break if another thread decides it wants
	 * to do things in this thread.
	 *

	 * @throws IllegalStateException If the thread was started and the check
	 * was performed in a different thread.
	 * @since 2019/01/10
	 */
	private final void __checkSameThread()
		throws IllegalStateException
	{
		// {@squirreljme.error AE01 This thread has already been started and
		// as such this method may only be called from within that thread.}

		if (this._didstart && this != Thread.currentThread())
			throw new IllegalStateException("AE01");

	}
}








>
>
>
>
>
>







 







|
>
>
|
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
|
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>







 







>




|




>
|

>



32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
...
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
...
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
	
	/** The task status this reports on. */
	protected final TaskStatus status;
	
	/** Has this thread been started via the run method. */
	private volatile boolean _didstart;
	
	/** Owner thread, for when it is not started and has been called. */
	private volatile Thread _rmthread;
	
	/** The counts for the current thread run. */
	private volatile int _rmcount;
	
	/**
	 * Initializes the thread.
	 *
	 * @param __id The thread ID.
	 * @param __s The task status.
	 * @throws NullPointerException On null arguments.
	 * @since 2019/01/10
................................................................................
	public Value runMethod(MethodHandle __mh, Value... __args)
		throws IllegalStateException, NullPointerException
	{
		if (__mh == null)
			throw new NullPointerException("NARG");
		
		// Must be the same thread
		boolean didstart = __checkSameThread();
		if (!didstart)
			synchronized (this)
			{
				// Current thread is always used
				Thread current = Thread.currentThread();
				
				// Take over for this thread
				Thread rmthread = this._rmthread;
				if (rmthread == null)
				{
					this._rmthread = current;
					this._rmcount = 1;
				}
				
				// Count up the thread usage
				else
				{
					// {@squirreljme.error AE02 Cannot run a method which is
					// crossed from another thread which is running a method.}
					if (rmthread != Thread.currentThread())
						throw new IllegalStateException("AE02");
					
					this._rmcount++;
				}
			}
		
		// Needed to clear the current thread
		try
		{
			throw new todo.TODO();
		}
		
		// Make sure this is always run
		finally
		{
			// If the thread has not been started then reduce our count and
			// additionally make sure if it clears that the current context
			// thread is also cleared
			if (!didstart)
				synchronized (this)
				{
					if ((--this._rmcount) <= 0)
						this._rmthread = null;
				}
		}
	}
	
	/**
	 * Creates a new array instance.
	 *
	 * @param __cl The class to create an array of, this is not the component
	 * type.
................................................................................
	}
	
	/**
	 * Checks that the call was done in the same thread, since when the thread
	 * is running it will completely break if another thread decides it wants
	 * to do things in this thread.
	 *
	 * @return If the thread has been started, and is using {@link #run()}.
	 * @throws IllegalStateException If the thread was started and the check
	 * was performed in a different thread.
	 * @since 2019/01/10
	 */
	private final boolean __checkSameThread()
		throws IllegalStateException
	{
		// {@squirreljme.error AE01 This thread has already been started and
		// as such this method may only be called from within that thread.}
		boolean didstart = this._didstart;
		if (didstart && this != Thread.currentThread())
			throw new IllegalStateException("AE01");
		return didstart;
	}
}