1 11 package org.eclipse.swt.internal; 12 13 16 public class Lock { 17 int count, waitCount; 18 Thread owner; 19 20 27 public int lock() { 28 synchronized (this) { 29 Thread current = Thread.currentThread(); 30 if (owner != current) { 31 waitCount++; 32 while (count > 0) { 33 try { 34 wait(); 35 } catch (InterruptedException e) { 36 37 } 38 } 39 --waitCount; 40 owner = current; 41 } 42 return ++count; 43 } 44 } 45 46 50 public void unlock() { 51 synchronized (this) { 52 Thread current = Thread.currentThread(); 53 if (owner == current) { 54 if (--count == 0) { 55 owner = null; 56 if (waitCount > 0) notifyAll(); 57 } 58 } 59 } 60 } 61 } 62 | Popular Tags |