+/EE360P
distributed systems
git clone https://git.julia.blue/+/EE360P
cccc41d
master
1import java .util .concurrent .locks .ReentrantLock ; 2public class UnboundedQueue <T > { 3 4ReentrantLock enqLock ,deqLock ; 5Node <T >head ; 6Node <T >tail ; 7int size ; 8public UnboundedQueue () { 9head =new Node <T >(null ); 10tail =head ; 11enqLock =new ReentrantLock (); 12deqLock =new ReentrantLock (); 13 } 14public T deq ()throws EmptyException { 15T result ; 16deqLock .lock (); 17try { 18if (head .next ==null ) { 19throw new EmptyException (); 20 } 21result =head .next .value ; 22head =head .next ; 23 }finally { 24deqLock .unlock (); 25 } 26return result ; 27 } 28public void enq (T x ) { 29if (x ==null )throw new NullPointerException (); 30enqLock .lock (); 31try { 32Node <T >e =new Node <T >(x ); 33tail .next =e ; 34tail =e ; 35 }finally { 36enqLock .unlock (); 37 } 38 } 39 40}