2 * To change this template, choose Tools | Templates
3 * and open the template in the editor.
6 package org.apidesign.privileged.api;
8 import java.util.concurrent.locks.Lock;
9 import java.util.concurrent.locks.ReentrantLock;
13 * @author Jaroslav Tulach <jaroslav.tulach@netbeans.org>
16 public final class Mutex {
17 Lock lock = new ReentrantLock();
22 public void withLock(Runnable r) {
32 // BEGIN: mutex.privileged.api
33 public Mutex(Privileged privileged) {
34 if (privileged.mutex != null) {
35 throw new IllegalStateException();
37 privileged.mutex = this;
40 public static final class Privileged {
47 public void unlock() {
51 // END: mutex.privileged.api