X-Git-Url: http://info.iut-bm.univ-fcomte.fr/pub/gitweb/simgrid.git/blobdiff_plain/a8030f60ea5bf6dce3737f946ad27eae788d85b8..964fa7d1a4b0fb183a02d8b0020d74b1255312e0:/src/java/simgrid/msg/Sem.java diff --git a/src/java/simgrid/msg/Sem.java b/src/java/simgrid/msg/Sem.java index 21364a7251..e71317ff5d 100644 --- a/src/java/simgrid/msg/Sem.java +++ b/src/java/simgrid/msg/Sem.java @@ -1,34 +1,38 @@ -package simgrid.msg; - -public class Sem { - private int permits_; - - public Sem(int i) { - permits_ = i; - } - - public void acquire() throws InterruptedException { - - if (Thread.interrupted()) - throw new InterruptedException(); - - synchronized(this) { - - try { - while (permits_ <= 0) - wait(); - - --permits_; - } - catch (InterruptedException ex) { - notify(); - throw ex; - } - } - } - - public synchronized void release() { - ++(this.permits_); - notify(); - } -} +/* + * $Id$ + * + * Copyright 2006,2007 Martin Quinson, Malek Cherier + * All right reserved. + * + * This program is free software; you can redistribute + * it and/or modify it under the terms of the license + *(GNU LGPL) which comes with this package. + */ + package simgrid.msg; + public class Sem { + + /******************************************************************/ + /* Simple semaphore implementation, from Doug Lea (public domain) */ + /******************************************************************/ + private int permits_; + public Sem(int i) { + permits_ = i; + } public void acquire() throws InterruptedException { + if (Thread.interrupted()) + throw new InterruptedException(); + synchronized(this) { + try { + while (permits_ <= 0) + wait(); + --permits_; + } + catch(InterruptedException ex) { + notify(); + throw ex; + } + } + } + public synchronized void release() { + ++(this.permits_); + notify(); + } }