This is the mail archive of the
java-patches@gcc.gnu.org
mailing list for the Java project.
[ecj] Patch: FYI: implement Thread.getId
- From: Tom Tromey <tromey at redhat dot com>
- To: Java Patch List <java-patches at gcc dot gnu dot org>
- Date: 14 Aug 2006 11:28:34 -0600
- Subject: [ecj] Patch: FYI: implement Thread.getId
- Reply-to: tromey at redhat dot com
I'm checking this in on the gcj-eclipse branch.
This implements Thread.getId by pulling in the Classpath implementation.
Tom
Index: ChangeLog
from Tom Tromey <tromey@redhat.com>
* java/lang/natThread.cc (getId): Removed.
* java/lang/Thread.java (threadId): New field.
(totalThreadsCreated): Likewise.
(Thread): Set threadId.
(getId): No longer native.
Index: java/lang/Thread.java
===================================================================
--- java/lang/Thread.java (revision 116131)
+++ java/lang/Thread.java (working copy)
@@ -133,6 +133,12 @@
/** The context classloader for this Thread. */
private ClassLoader contextClassLoader;
+ /** This thread's ID. */
+ private final long threadId;
+
+ /** Used to generate the next thread ID to use. */
+ private static long totalThreadsCreated;
+
/** The default exception handler. */
private static UncaughtExceptionHandler defaultHandler;
@@ -383,6 +389,11 @@
priority = NORM_PRIORITY;
}
+ synchronized (Thread.class)
+ {
+ this.threadId = ++totalThreadsCreated;
+ }
+
name = n;
group.addThread(this);
runnable = r;
@@ -1040,7 +1051,10 @@
* @return a positive long number representing the thread's ID.
* @since 1.5
*/
- public native long getId();
+ public long getId()
+ {
+ return threadId;
+ }
/**
* <p>
Index: java/lang/natThread.cc
===================================================================
--- java/lang/natThread.cc (revision 116131)
+++ java/lang/natThread.cc (working copy)
@@ -385,13 +385,6 @@
_Jv_ThreadYield ();
}
-jlong
-java::lang::Thread::getId()
-{
- // FIXME
- return 5;
-}
-
::java::lang::Thread$State *
java::lang::Thread::getState()
{