changeset 175:9e7e1a8bc813

get a JThread for a thread that was just a Thread.
author Frank Benoit <benoit@tionex.de>
date Fri, 12 Sep 2008 09:44:36 +0200
parents c6d7b1ea700b
children ed80c5c2b550
files dwtx/dwtxhelper/JThread.d
diffstat 1 files changed, 12 insertions(+), 1 deletions(-) [+]
line wrap: on
line diff
--- a/dwtx/dwtxhelper/JThread.d	Thu Sep 11 00:32:24 2008 +0200
+++ b/dwtx/dwtxhelper/JThread.d	Fri Sep 12 09:44:36 2008 +0200
@@ -52,7 +52,18 @@
     }
 
     public static JThread currentThread(){
-        return getTls().val();
+        auto res = getTls().val();
+        if( res is null ){
+            synchronized(JThread.classinfo){
+                res = getTls().val();
+                if( res is null ){
+                    res = new JThread();
+                    res.thread = Thread.getThis();
+                    getTls().val( res );
+                }
+            }
+        }
+        return res;
     }
     public int getPriority() {
         return (thread.priority-Thread.PRIORITY_MIN) * (MAX_PRIORITY-MIN_PRIORITY) / (Thread.PRIORITY_MAX-Thread.PRIORITY_MIN) + MIN_PRIORITY;