samples/privilegedcreator/src/api/Mutex.java
changeset 330 be82436a7a8b
parent 329 918e6f7f8136
child 331 b5228ed41a43
     1.1 --- a/samples/privilegedcreator/src/api/Mutex.java	Wed Apr 29 11:56:47 2009 +0200
     1.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.3 @@ -1,51 +0,0 @@
     1.4 -/*
     1.5 - * To change this template, choose Tools | Templates
     1.6 - * and open the template in the editor.
     1.7 - */
     1.8 -
     1.9 -package api;
    1.10 -
    1.11 -import java.util.concurrent.locks.Lock;
    1.12 -import java.util.concurrent.locks.ReentrantLock;
    1.13 -
    1.14 -/**
    1.15 - *
    1.16 - * @author Jaroslav Tulach <jaroslav.tulach@netbeans.org>
    1.17 - */
    1.18 -public class Mutex {
    1.19 -    Lock lock = new ReentrantLock();
    1.20 -    
    1.21 -    public Mutex() {
    1.22 -    }
    1.23 -
    1.24 -    
    1.25 -    public void readAccess(Runnable r) {
    1.26 -        try {
    1.27 -            lock.lock();
    1.28 -            r.run();
    1.29 -        } finally {
    1.30 -            lock.unlock();
    1.31 -        }
    1.32 -    }
    1.33 -    
    1.34 -
    1.35 -    
    1.36 -    public Mutex(Privileged privileged) {
    1.37 -        if (privileged.mutex != null) {
    1.38 -            throw new IllegalStateException();
    1.39 -        }
    1.40 -        privileged.mutex = this;
    1.41 -    }
    1.42 -    
    1.43 -    public static final class Privileged {
    1.44 -        private Mutex mutex;
    1.45 -        
    1.46 -        public void enterReadAccess() {
    1.47 -            mutex.lock.lock();
    1.48 -        }
    1.49 -        
    1.50 -        public void exitReadAccess() {
    1.51 -            mutex.lock.unlock();
    1.52 -        }
    1.53 -    }
    1.54 -}