Add blank classes for DoJa graphics3d.
[SquirrelJME.git] / modules / cldc-compact / src / main / java / cc / squirreljme / jvm / mle / ThreadShelf.java
blob1c2eb5d92b7462e1f4467b64e8722224b911b957
1 // -*- Mode: Java; indent-tabs-mode: t; tab-width: 4 -*-
2 // ---------------------------------------------------------------------------
3 // SquirrelJME
4 // Copyright (C) Stephanie Gawroriski <xer@multiphasicapps.net>
5 // ---------------------------------------------------------------------------
6 // SquirrelJME is under the Mozilla Public License Version 2.0.
7 // See license.mkd for licensing and copyright information.
8 // ---------------------------------------------------------------------------
10 package cc.squirreljme.jvm.mle;
12 import cc.squirreljme.jvm.mle.brackets.TaskBracket;
13 import cc.squirreljme.jvm.mle.brackets.TracePointBracket;
14 import cc.squirreljme.jvm.mle.brackets.VMThreadBracket;
15 import cc.squirreljme.jvm.mle.constants.ThreadModelType;
16 import cc.squirreljme.jvm.mle.exceptions.MLECallError;
17 import cc.squirreljme.runtime.cldc.annotation.Api;
18 import cc.squirreljme.runtime.cldc.annotation.SquirrelJMEVendorApi;
19 import org.intellij.lang.annotations.Flow;
20 import org.intellij.lang.annotations.MagicConstant;
21 import org.jetbrains.annotations.Blocking;
22 import org.jetbrains.annotations.CheckReturnValue;
23 import org.jetbrains.annotations.NotNull;
24 import org.jetbrains.annotations.Range;
26 /**
27 * This shelf handles everything regarding threading and otherwise.
29 * @see VMThreadBracket
30 * @since 2020/06/17
32 @SuppressWarnings("UnstableApiUsage")
33 @SquirrelJMEVendorApi
34 public final class ThreadShelf
36 /**
37 * Returns the number of alive threads.
39 * @param __includeMain Include main threads?
40 * @param __includeDaemon Include daemon threads?
41 * @return The number of alive threads.
42 * @since 2020/06/17
44 @SquirrelJMEVendorApi
45 public static native int aliveThreadCount(boolean __includeMain,
46 boolean __includeDaemon);
48 /**
49 * Creates a virtual machine thread for the given Java thread.
51 * @param __javaThread The Java thread to create under.
52 * @param __name The name of this thread.
53 * @return The virtual machine thread.
54 * @throws MLECallError If {@code __javaThread} is null.
55 * @since 2020/06/17
57 @SquirrelJMEVendorApi
58 public static native VMThreadBracket createVMThread(
59 @Flow(target = "this._vmThread") @NotNull Thread __javaThread,
60 String __name)
61 throws MLECallError;
63 /**
64 * Returns the exit code for the current process.
66 * @return The exit code for the current process.
67 * @since 2020/06/17
69 @SquirrelJMEVendorApi
70 public static native int currentExitCode();
72 /**
73 * Returns the current Java thread.
75 * @return The current {@link Thread}.
76 * @since 2020/06/17
78 @SquirrelJMEVendorApi
79 public static native Thread currentJavaThread();
81 /**
82 * Returns the current virtual machine thread.
84 * @return The current virtual machine thread.
85 * @since 2021/05/08
87 @SquirrelJMEVendorApi
88 public static native VMThreadBracket currentVMThread();
90 /**
91 * Checks if these two threads are the same.
93 * @param __a The first thread.
94 * @param __b The second thread.
95 * @return If these are the same thread.
96 * @throws MLECallError If either arguments are null.
97 * @since 2021/05/08
99 @SquirrelJMEVendorApi
100 public static native boolean equals(VMThreadBracket __a,
101 VMThreadBracket __b)
102 throws MLECallError;
105 * Returns whether the interrupt flag was raised and clears it.
107 * @param __javaThread The Java thread.
108 * @return If the thread was interrupted.
109 * @throws MLECallError If {@code __javaThread} is null.
110 * @since 2020/06/17
112 @SquirrelJMEVendorApi
113 public static native boolean javaThreadClearInterrupt(
114 @NotNull Thread __javaThread)
115 throws MLECallError;
118 * Marks the thread as being started.
120 * @param __javaThread The thread to mark started.
121 * @throws MLECallError If {@code __javaThread} is null.
122 * @since 2020/06/17
124 @SquirrelJMEVendorApi
125 public static native void javaThreadFlagStarted(
126 @NotNull Thread __javaThread)
127 throws MLECallError;
130 * Has this Java thread been started?
132 * @param __javaThread The Java thread.
133 * @return If this thread has been started.
134 * @throws MLECallError If {@code __javaThread} is null.
135 * @since 2020/06/17
137 @SquirrelJMEVendorApi
138 @Flow(source = "this._started")
139 public static native boolean javaThreadIsStarted(
140 @NotNull Thread __javaThread)
141 throws MLECallError;
144 * Returns the runnable for the given Java thread.
146 * @param __javaThread The Java thread.
147 * @return The {@link Runnable} for the given thread.
148 * @throws MLECallError If {@code __javaThread} is null.
149 * @since 2020/06/17
152 @SquirrelJMEVendorApi
153 @Flow(source = "this._runnable")
154 public static native Runnable javaThreadRunnable(
155 @NotNull Thread __javaThread)
156 throws MLECallError;
159 * Sets if the thread is alive or not.
161 * @param __javaThread The Java thread.
162 * @param __set If this is to be alive or not. If this is {@code true}
163 * then the active count goes up, otherwise it shall go down.
164 * @throws MLECallError If {@code __javaThread} is null.
165 * @since 2020/06/17
167 @SquirrelJMEVendorApi
168 public static native void javaThreadSetAlive(@NotNull Thread __javaThread,
169 boolean __set)
170 throws MLECallError;
173 * Sets the thread to be a daemon thread, it cannot be started.
175 * @param __javaThread The thread to set as a daemon thread.
176 * @throws MLECallError If {@code __javaThread} is null or is already
177 * started.
178 * @since 2020/09/12
180 @SquirrelJMEVendorApi
181 public static native void javaThreadSetDaemon(@NotNull Thread __javaThread)
182 throws MLECallError;
185 * Returns the {@link ThreadModelType} of the virtual machine.
187 * @return The {@link ThreadModelType} of the virtual machine.
188 * @since 2021/05/07
190 @SquirrelJMEVendorApi
191 @MagicConstant(valuesFromClass = ThreadModelType.class)
192 public static native int model();
195 * Runs the main entry point for the current process and gives it all of
196 * the arguments that were specified on program initialization.
198 * @since 2020/06/17
200 @SquirrelJMEVendorApi
201 public static native void runProcessMain();
204 * Sets the current process exit code.
206 * @param __code The exit code to use.
207 * @since 2020/06/17
209 @SquirrelJMEVendorApi
210 public static native void setCurrentExitCode(int __code);
213 * Sets the trace of the current task so that it can be requested by
214 * another or launching program.
216 * @param __message The message of the trace.
217 * @param __trace The trace to set.
218 * @throws MLECallError If {@code __message} is {@code null}, or
219 * {@code __trace} or any element within is {@code null}.
220 * @since 2020/07/02
222 @SquirrelJMEVendorApi
223 public static native void setTrace(@NotNull String __message,
224 @NotNull TracePointBracket[] __trace)
225 throws MLECallError;
228 * Sleeps the current thread for the given amount of time.
230 * If both times are zero, this means to yield the thread (give up its
231 * current execution context).
233 * If SquirrelJME is running in cooperative
234 * single threaded mode, this will relinquish control of the current
235 * thread.
237 * @param __ms The number of milliseconds.
238 * @param __ns The number of nanoseconds.
239 * @return {@code true} if the thread was interrupted.
240 * @throws MLECallError If either value is negative or the nanoseconds is
241 * out of range.
242 * @since 2020/06/17
244 @SquirrelJMEVendorApi
245 @Blocking
246 public static native boolean sleep(
247 @Range(from = 0, to = Integer.MAX_VALUE) int __ms,
248 @Range(from = 0, to = 999999) int __ns)
249 throws MLECallError;
252 * Returns the Java thread for the VM thread.
254 * @param __vmThread The VM thread.
255 * @return The Java thread which belongs to this thread.
256 * @throws MLECallError If {@code __thread} is null.
257 * @since 2020/06/17
259 @SquirrelJMEVendorApi
260 public static native Thread toJavaThread(
261 @NotNull VMThreadBracket __vmThread)
262 throws MLECallError;
265 * Returns the virtual machine thread from the given Java thread.
267 * @param __thread The Java thread.
268 * @return The VM thread for this thread.
269 * @throws MLECallError If {@code __thread} is null.
270 * @since 2020/06/17
272 @SquirrelJMEVendorApi
273 @Flow(source = "this._vmThread")
274 public static native VMThreadBracket toVMThread(
275 @NotNull Thread __thread)
276 throws MLECallError;
279 * Signals that the thread has ended and is no longer considered to be
280 * alive.
282 * @param __vmThread The virtual machine thread.
283 * @throws MLECallError If {@code __vmThread} is null.
284 * @since 2021/03/14
286 @SquirrelJMEVendorApi
287 public static native void vmThreadEnd(
288 @NotNull VMThreadBracket __vmThread)
289 throws MLECallError;
292 * Returns the thread ID for the given thread.
294 * @param __vmThread The virtual machine thread.
295 * @return The thread ID.
296 * @throws MLECallError If {@code __vmThread} is null.
297 * @since 2020/06/17
299 @SquirrelJMEVendorApi
300 public static native int vmThreadId(
301 @NotNull VMThreadBracket __vmThread)
302 throws MLECallError;
305 * Performs a hardware interrupt on the thread.
307 * @param __vmThread The virtual machine thread.
308 * @throws MLECallError If {@code __vmThread} is null.
309 * @since 2020/06/17
311 @SquirrelJMEVendorApi
312 public static native void vmThreadInterrupt(
313 @NotNull VMThreadBracket __vmThread)
314 throws MLECallError;
317 * Checks if the given thread is a main thread.
319 * @param __vmThread The thread to check.
320 * @return {@code true} if the given thread is a main thread.
321 * @throws MLECallError If {@code __vmThread} is null.
322 * @since 2020/06/17
324 @SquirrelJMEVendorApi
325 public static native boolean vmThreadIsMain(
326 @NotNull VMThreadBracket __vmThread)
327 throws MLECallError;
330 * Sets the thread priority in the same manner as
331 * {@link Thread#setPriority(int)} if this is supported by the hardware.
333 * This may or may not be supported and should only be used as a hint and
334 * not a guarantee.
336 * @param __vmThread The virtual machine thread.
337 * @param __p The priority to set, this will be the same as
338 * {@link Thread#setPriority(int)}.
339 * @throws MLECallError If {@code __vmThread} is null or {@code __p} is
340 * not within {@link Thread#MIN_PRIORITY} and {@link Thread#MAX_PRIORITY}
341 * inclusive.
342 * @since 2020/06/17
344 @SquirrelJMEVendorApi
345 public static native void vmThreadSetPriority(
346 @NotNull VMThreadBracket __vmThread, int __p)
347 throws MLECallError;
350 * Performs the actual start of the given thread.
352 * @param __vmThread The thread to start.
353 * @return If the start of the thread succeeded.
354 * @throws MLECallError If {@code __vmThread} is null.
355 * @since 2020/06/17
357 @SquirrelJMEVendorApi
358 public static native boolean vmThreadStart(
359 @NotNull VMThreadBracket __vmThread)
360 throws MLECallError;
363 * Returns the task that owns the given thread.
365 * @param __vmThread The thread to get the task of.
366 * @return The task for the given thread.
367 * @throws MLECallError If the thread is not valid.
368 * @since 2021/05/08
370 @SquirrelJMEVendorApi
371 public static native TaskBracket vmThreadTask(
372 @NotNull VMThreadBracket __vmThread)
373 throws MLECallError;
376 * Waits for the state of threads to be updated, or just times out.
378 * A thread update is when another thread becomes alive, becomes dead,
379 * or is started.
381 * If waiting and SquirrelJME is running in cooperative
382 * single threaded mode, this will relinquish control of the current
383 * thread.
385 * @param __ms The amount of time to wait for.
386 * @return If the thread was interrupted while waiting.
387 * @throws MLECallError If {@code __ms} is negative.
388 * @since 2020/06/17
390 @SquirrelJMEVendorApi
391 @Blocking
392 public static native boolean waitForUpdate(int __ms)
393 throws MLECallError;