Logo
Distributed Genetic Programming Framework
print print

File org.sfc.parallel.SyncPoint.java

Here you can find all the information about the file org.sfc.parallel.SyncPoint.java. You may explore it here or download it onto your local disk.
/*
 * Copyright (c) 2005 Thomas Weise
 * 
 * E-Mail           : tweise@gmx.de
 * Creation Date    : 2005-09-05 09:20:02
 * Original Filename: org.sfc.parallel.SyncPoint.java
 * Version          : 1.0.2
 * Last modification: 2006-03-07
 *                by: Thomas Weise
 * 
 * License          : GNU LESSER GENERAL PUBLIC LICENSE
 *                    Version 2.1, February 1999
 *                    You should have received a copy of this license along
 *                    with this library; if not, write to the Free Software
 *                    Foundation, Inc., 59 Temple Place, Suite 330, Boston,
 *                    MA 02111-1307, USA or download the license under
 *                    http://www.gnu.org/copyleft/lesser.html.
 *                    
 * Warranty         : This software is provided "as is" without any
 *                    warranty; without even the implied warranty of
 *                    merchantability or fitness for a particular purpose.
 *                    See the Gnu Lesser General Public License for more
 *                    details.
 */

 
package org.sfc.parallel;

/**
 * A synchronization point for any count of threads.
 *
 * @author Thomas Weise
 */

public final  class SyncPoint implements  IWaitable
  {
/**
 * The internal sync object.
 */

  private final     Object  m_sync;
/**
 * <code>true</code> if the waiters have been released.
 */

  private volatile  boolean m_wait  ;
/**
 * The count of threads currently waiting.
 */

  private volatile  int     m_waiters ;
  
/**
 * Create a new sync-point.
 */

  public  SyncPoint ()
    {
    this(true);
    }
  
/**
 * Create a new sync-point.
 * @param p_wait  The initial wait value.
 */

  SyncPoint (final boolean p_wait)
    {
    super();
    this.m_sync = new Object();
    this.m_wait = p_wait;
    }
  
/**
 * Internally set the wait-value.
 * @param p_wait  The new wait value.
 */

  final void  set_wait  (final  boolean p_wait)
    {    
    synchronized(this.m_sync)
      {
      this.m_wait = p_wait;
      }
    }
  
/**
 * Wait for this object.
 */

  public  final void  wait_for  ()
    {
    boolean l_b;
    Object  l_o;
    
    l_o = this.m_sync;
    synchronized(l_o)
      {
      if(this.m_wait)
        {       
        this.m_waiters++;
        
        for(;;)
          {
          l_b = true;
          try
            {
            l_o.wait();
            }
          catch(InterruptedException l_ies)
            {
            l_b = false;
            }
          if(l_b)
            {
            this.m_waiters--;          
            l_o.notify();
            return;
            }
          }
        }
      }
    }
  
/**
 * Release all threads waiting for this synchronization point.
 * @param p_reset If you want to re-use this synchronization point,
 *                meaning if you want to allow threads to wait again,
 *                set this parameter to <code>true</code>. If set to
 *                <code>false</code>, the sync-point cannot be reused.
 */

  public  final void  release   (final boolean  p_reset)
    {
    Object  l_o;
    
    l_o = this.m_sync;
    synchronized(l_o)
      {
      if(this.m_wait)
        {        
        this.m_wait = p_reset;
        }
      
      while(this.m_waiters > 0)
        {
        l_o.notify();
        try
          {
          l_o.wait();
          }
        catch(Throwable l_t)
          {
          //
          }
        l_o.notify();
        }
      }
    }
  
  }

File Information:

file name:SyncPoint.java
package:org.sfc.parallel
qualified name:org.sfc.parallel.SyncPoint.java
file type:Java Source File
download location:download http://dgpf.sourceforge.net/source/org/sfc/parallel/SyncPoint.java
size:3.541 KB (3627 B)
uploaded: 2015-07-22 04:11:13 GMT+0000
last update: 2006-03-07 04:20:28 GMT+0000
last access: 2018-01-22 23:59:25 GMT+0000

statistics online since 2006-01-02.   RSS Feed
Contact us by sending an email to tweise@gmx.de to receive further information, to report errors, or to join our project.
All content on this site (http://dgpf.sourceforge.net/) is LGPL-licensed.
http://dgpf.sourceforge.net/scripts/source/source.php last modified at 2015-07-22 04:10:53 GMT+0000 served at 2018-01-22 23:59:25 GMT+0000.
Valid CSS Valid XHTML 1.1
Valid RSS SourceForge.net Logo