This is the mail archive of the java-patches@gcc.gnu.org mailing list for the Java project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Patch: FYI: fix PR 27730


I'm checking this in on the trunk.

This fixes PR 27730 by merging in Thread.getId from Classpath.

Tom

Index: ChangeLog
from  Tom Tromey  <tromey@redhat.com>
	PR libgcj/27730:
	* java/lang/Thread.java (threadId): New field.
	(nextThreadId): New static field.
	(Thread): Initialize new field.
	(getId): New method.

Index: java/lang/Thread.java
===================================================================
--- java/lang/Thread.java	(revision 114522)
+++ java/lang/Thread.java	(working copy)
@@ -127,6 +127,12 @@
   /** The context classloader for this Thread. */
   private ClassLoader contextClassLoader;
 
+  /** This thread's ID.  */
+  private final long threadId;
+
+  /** The next thread ID to use.  */
+  private static long nextThreadId;
+
   /** The default exception handler.  */
   private static UncaughtExceptionHandler defaultHandler;
 
@@ -354,12 +360,17 @@
       }
     else
       group = g;
-      
+
     data = null;
     interrupt_flag = false;
     alive_flag = false;
     startable_flag = true;
 
+    synchronized (Thread.class)
+      {
+        this.threadId = nextThreadId++;
+      }
+
     if (current != null)
       {
 	group.checkAccess();
@@ -1027,6 +1038,18 @@
     return defaultHandler;
   }
   
+  /** 
+   * Returns the unique identifier for this thread.  This ID is generated
+   * on thread creation, and may be re-used on its death.
+   *
+   * @return a positive long number representing the thread's ID.
+   * @since 1.5 
+   */
+  public long getId()
+  {
+    return threadId;
+  }
+
   /**
    * <p>
    * This interface is used to handle uncaught exceptions


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]