1 13 14 15 package EDU.oswego.cs.dl.util.concurrent; 16 17 33 34 public class FIFOSemaphore extends QueuedSemaphore { 35 36 42 43 public FIFOSemaphore(long initialPermits) { 44 super(new FIFOWaitQueue(), initialPermits); 45 } 46 47 51 52 protected static class FIFOWaitQueue extends WaitQueue { 53 protected WaitNode head_ = null; 54 protected WaitNode tail_ = null; 55 56 protected void insert(WaitNode w) { 57 if (tail_ == null) 58 head_ = tail_ = w; 59 else { 60 tail_.next = w; 61 tail_ = w; 62 } 63 } 64 65 protected WaitNode extract() { 66 if (head_ == null) 67 return null; 68 else { 69 WaitNode w = head_; 70 head_ = w.next; 71 if (head_ == null) tail_ = null; 72 w.next = null; 73 return w; 74 } 75 } 76 } 77 78 } 79 | Popular Tags |