+++ /dev/null
-/*\r
- * Simple semaphore implementation, from Doug Lea (public domain)\r
- *\r
- * Copyright 2006,2007,2010 The SimGrid Team \r
- * All right reserved. \r
- *\r
- * This program is free software; you can redistribute \r
- * it and/or modify it under the terms of the license \r
- *(GNU LGPL) which comes with this package. \r
- */ \r
-\rpackage simgrid.msg;
-\r\rpublic class Sem {\r
- /******************************************************************/ \r
- /* Simple semaphore implementation, from Doug Lea (public domain) */ \r
- /******************************************************************/ \r
- private int permits_;
-\r public Sem(int i) {\r permits_ = i;\r } \r\r public void acquire() throws InterruptedException {
- if (Thread.interrupted())
- throw new InterruptedException();
-\r synchronized(this) {
- try {
- while (permits_ <= 0)
- wait();
- --permits_;
- }
- catch(InterruptedException ex) {
- notify();
- throw ex;
- }
- }
- }
-\r public synchronized void release() {
- ++(this.permits_);
- notify();
- } \r} \r