2006-06-12 Maciej Piechotka [EMAIL PROTECTED]
* java/util/concurrent/locks/LockSupport : Added
diff -ruN java.old/util/concurrent/locks/LockSupport.java java/util/concurrent/locks/LockSupport.java
--- java.old/util/concurrent/locks/LockSupport.java 1970-01-01 01:00:00.000000000 +0100
+++ java/util/concurrent/locks/LockSupport.java 2006-06-12 21:27:36.000000000 +0200
@@ -0,0 +1,76 @@
+package java.util.concurrent.locks;
+
+import java.util.concurrent.TimeUnit;
+
+public class LockSupport
+{
+ public static void unpark(Thread thread)
+ {
+ /* if(threadLocks.contains(thread)) {
+ * threadLocks.get(thread).notify();
+ * threadLocks.remove(thread);
+ * } */
+ synchronized(thread)
+ {
+ thread.notify();
+ }
+ }
+
+ public static void park()
+ {
+ /* Is method depended on threads is safe?
+ * It could be also used with some set/map
+ * (in comments) which get more of CPU
+ * And all methods should be synchonised */
+ Thread thread = Thread.currentThread();
+ synchronized (thread)
+ {
+ try
+ {
+ /* threadLocks.put(thread, new Boolean(true)).wait(); */
+ thread.wait();
+ }
+ catch (InterruptedException e)
+ {
+ // Just ignore
+ }
+ }
+ }
+ public static void parkNanos(long nanos)
+ {
+ Thread thread = Thread.currentThread();
+ synchronized (thread)
+ {
+ try
+ {
+ /* TimeUnit.NANOSECONDS.timedWait(threadsLocks.put(thread,
+ * new Boolean(true)),
+ * deadline); */
+ TimeUnit.NANOSECONDS.timedWait(thread, nanos);
+ }
+ catch (InterruptedException e)
+ {
+ // Just ignore
+ }
+ }
+ }
+ public static void parkUntil(long deadline)
+ {
+ Thread thread = Thread.currentThread();
+ synchronized (thread)
+ {
+ try
+ {
+ /* TimeUnit.MILLISECONDS.timedWait(threadsLocks.put(thread,
+ * new Boolean(true)),
+ * deadline); */
+ TimeUnit.MILLISECONDS.timedWait(thread, deadline);
+ }
+ catch (InterruptedException e)
+ {
+ // Just ignore
+ }
+ }
+ }
+ /* private static Map<Thread, Object> threadsLocks; */
+}