* 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
- \r
-package simgrid.msg;\r
-\r
-public class Sem { \r
- \r
- /******************************************************************/\r
- /* Simple semaphore implementation, from Doug Lea (public domain) */\r
- /******************************************************************/\r
- private int permits_;\r
- \r
- public Sem(int i) {\r
- permits_ = i;\r
- }\r
- \r
- public void acquire() throws InterruptedException {\r
- \r
- if (Thread.interrupted()) \r
- throw new InterruptedException();\r
- \r
- synchronized(this) {\r
- \r
- try {\r
- while (permits_ <= 0) \r
- wait();\r
- \r
- --permits_;\r
- }\r
- catch (InterruptedException ex) {\r
- notify();\r
- throw ex;\r
- }\r
- }\r
- }\r
-\r
- public synchronized void release() {\r
- ++(this.permits_);\r
- notify();\r
- }\r
-}\r
+ */ \r
+ \rpackage simgrid.msg;
+\r\rpublic class Sem {
+ \r\r
+ /******************************************************************/ \r
+ /* Simple semaphore implementation, from Doug Lea (public domain) */ \r
+ /******************************************************************/ \r
+ private int permits_;
+ \r\rpublic Sem(int i) {
+ \rpermits_ = i;
+ \r} \r\rpublic void acquire() throws InterruptedException {
+ \r \r if (Thread.interrupted())
+ \rthrow new InterruptedException();
+ \r\rsynchronized(this) {
+ \r\rtry {
+ \rwhile (permits_ <= 0)
+ \rwait();
+ \r\r--permits_;
+ \r}
+ \rcatch(InterruptedException ex) {
+ \rnotify();
+ \rthrow ex;
+ \r}
+ \r}
+ \r}
+ \r\rpublic synchronized void release() {
+ \r++(this.permits_);
+ \rnotify();
+\r} \r} \r