[Tinyos-2-commits] CVS: tinyos-2.x/support/sdk/java/net/tinyos/comm TOSSerial.java, 1.1.2.2, 1.1.2.3

David Gay idgay at users.sourceforge.net
Wed Jun 14 12:49:34 PDT 2006


Update of /cvsroot/tinyos/tinyos-2.x/support/sdk/java/net/tinyos/comm
In directory sc8-pr-cvs10.sourceforge.net:/tmp/cvs-serv14365

Modified Files:
      Tag: tinyos-2_0_devel-BRANCH
	TOSSerial.java 
Log Message:
data-race fix from Cory


Index: TOSSerial.java
===================================================================
RCS file: /cvsroot/tinyos/tinyos-2.x/support/sdk/java/net/tinyos/comm/Attic/TOSSerial.java,v
retrieving revision 1.1.2.2
retrieving revision 1.1.2.3
diff -C2 -d -r1.1.2.2 -r1.1.2.3
*** TOSSerial.java	3 Feb 2006 01:27:02 -0000	1.1.2.2
--- TOSSerial.java	14 Jun 2006 19:49:32 -0000	1.1.2.3
***************
*** 34,53 ****
    {
      boolean m_run;
-     TOSSerial m_serial;
  
!     public EventDispatcher( TOSSerial serial )
      {
        m_run = true;
-       m_serial = serial;
      }
  
      void dispatch_event( int event )
      {
!       if( m_serial.didEventOccur(event) )
        {
! 	SerialPortEvent ev = new SerialPortEvent( m_serial, event );
! 	Iterator i = m_serial.m_listeners.iterator();
! 	while( i.hasNext() )
! 	  ((SerialPortListener)i.next()).serialEvent( ev );
        }
      }
--- 34,53 ----
    {
      boolean m_run;
  
!     public EventDispatcher()
      {
        m_run = true;
      }
  
      void dispatch_event( int event )
      {
!       if( didEventOccur(event) )
        {
! 	SerialPortEvent ev = new SerialPortEvent( TOSSerial.this, event );
!         synchronized(m_listeners) {
!           Iterator i = m_listeners.iterator();
!           while( i.hasNext() )
!             ((SerialPortListener)i.next()).serialEvent( ev );
!         }
        }
      }
***************
*** 57,61 ****
        while( m_run )
        {
! 	if( m_serial.waitForEvent() )
  	{
  	  if( m_run )
--- 57,61 ----
        while( m_run )
        {
! 	if( waitForEvent() )
  	{
  	  if( m_run )
***************
*** 79,83 ****
      {
        m_run = false;
!       m_serial.cancelWait();
      }
    }
--- 79,83 ----
      {
        m_run = false;
!       cancelWait();
      }
    }
***************
*** 86,107 ****
    class SerialInputStream extends InputStream
    {
-     NativeSerial serial;
      ByteQueue bq = new ByteQueue(128);
  
      protected void gather()
      {
!       int navail = serial.available();
        if( navail > 0 )
        {
          byte buffer[] = new byte[navail];
!         bq.push_back( buffer, 0, serial.read( buffer, 0, navail ) );
        }
      }
  
-     public SerialInputStream( NativeSerial _serial )
-     {
-       serial = _serial;
-     }
- 
      public int read()
      {
--- 86,101 ----
    class SerialInputStream extends InputStream
    {
      ByteQueue bq = new ByteQueue(128);
  
      protected void gather()
      {
!       int navail = TOSSerial.this.available();
        if( navail > 0 )
        {
          byte buffer[] = new byte[navail];
!         bq.push_back( buffer, 0, TOSSerial.this.read( buffer, 0, navail ) );
        }
      }
  
      public int read()
      {
***************
*** 132,150 ****
    class SerialOutputStream extends OutputStream
    {
-     NativeSerial serial;
- 
-     public SerialOutputStream( NativeSerial _serial )
-     {
-       serial = _serial;
-     }
- 
      public void write( int b )
      {
!       serial.write(b);
      }
  
      public void write( byte[] b )
      {
!       write(b,0,b.length);
      }
  
--- 126,137 ----
    class SerialOutputStream extends OutputStream
    {
      public void write( int b )
      {
!       TOSSerial.this.write(b);
      }
  
      public void write( byte[] b )
      {
!       TOSSerial.this.write(b,0,b.length);
      }
  
***************
*** 153,157 ****
        int nwritten = 0;
        while( nwritten < len )
! 	nwritten += serial.write( b, nwritten, len-nwritten );
      }
    }
--- 140,144 ----
        int nwritten = 0;
        while( nwritten < len )
! 	nwritten += TOSSerial.this.write( b, nwritten, len-nwritten );
      }
    }
***************
*** 233,239 ****
    {
      super( map_portname( NativeSerial.getTOSCommMap(), portname ) );
!     m_in = new SerialInputStream( this );
!     m_out = new SerialOutputStream( this );
!     m_dispatch = new EventDispatcher( this );
      m_dispatch.start();
    }
--- 220,226 ----
    {
      super( map_portname( NativeSerial.getTOSCommMap(), portname ) );
!     m_in = new SerialInputStream();
!     m_out = new SerialOutputStream();
!     m_dispatch = new EventDispatcher();
      m_dispatch.start();
    }
***************
*** 241,251 ****
    public void addListener( SerialPortListener l )
    {
!     if( !m_listeners.contains(l) )
!       m_listeners.add(l);
    }
  
    public void removeListener( SerialPortListener l )
    {
!     m_listeners.remove(l);
    }
  
--- 228,242 ----
    public void addListener( SerialPortListener l )
    {
!     synchronized(m_listeners) {
!       if( !m_listeners.contains(l) )
!         m_listeners.add(l);
!     }
    }
  
    public void removeListener( SerialPortListener l )
    {
!     synchronized(m_listeners) {
!       m_listeners.remove(l);
!     }
    }
  



More information about the Tinyos-2-commits mailing list