/[escript]/branches/arrexp_2137_win_merge/escript/src/Data.h
ViewVC logotype

Diff of /branches/arrexp_2137_win_merge/escript/src/Data.h

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 2220 by jfenwick, Wed Jan 14 05:59:25 2009 UTC revision 2221 by jfenwick, Mon Jan 19 06:11:25 2009 UTC
# Line 143  class Data { Line 143  class Data {
143    Data(const Data& inData,    Data(const Data& inData,
144         const DataTypes::RegionType& region);         const DataTypes::RegionType& region);
145    
 //  /**  
 //     \brief  
 //     Constructor which copies data from a python numarray.  
 //  
 //     \param value - Input - Data value for a single point.  
 //     \param what - Input - A description of what this data represents.  
 //     \param expanded - Input - Flag, if true fill the entire container with  
 //                       the value. Otherwise a more efficient storage  
 //                       mechanism will be used.  
 //  */  
 //   ESCRIPT_DLL_API  
 //   Data(const boost::python::numeric::array& value,  
 //        const FunctionSpace& what=FunctionSpace(),  
 //        bool expanded=false);  
   
146    /**    /**
147       \brief       \brief
148       Constructor which copies data from any object that can be converted into       Constructor which copies data from any object that can be converted into
# Line 1586  ESCRIPT_DLL_API void freeSampleBuffer(Da Line 1571  ESCRIPT_DLL_API void freeSampleBuffer(Da
1571    //    //
1572    // flag to protect the data object against any update    // flag to protect the data object against any update
1573    bool m_protected;    bool m_protected;
1574      mutable bool m_shared;
1575      bool m_lazy;
1576    
1577    //    //
1578    // pointer to the actual data object    // pointer to the actual data object
# Line 1610  ESCRIPT_DLL_API void freeSampleBuffer(Da Line 1597  ESCRIPT_DLL_API void freeSampleBuffer(Da
1597    const_DataReady_ptr    const_DataReady_ptr
1598    getReadyPtr() const;    getReadyPtr() const;
1599    
1600    
1601      /**
1602       \brief Update the Data's shared flag
1603       This indicates that the DataAbstract used by this object is now shared (or no longer shared).
1604       For internal use only.
1605      */
1606      void updateShareStatus(bool nowshared) const
1607      {
1608        m_shared=nowshared;     // m_shared is mutable
1609      }
1610    
1611      // In the isShared() method below:
1612      // A problem would occur if m_data (the address pointed to) were being modified
1613      // while the call m_data->is_shared is being executed.
1614      //
1615      // Q: So why do I think this code can be thread safe/correct?
1616      // A: We need to make some assumptions.
1617      // 1. We assume it is acceptable to return true under some conditions when we aren't shared.
1618      // 2. We assume that no constructions or assignments which will share previously unshared
1619      //    will occur while this call is executing. This is consistent with the way Data:: and C are written.
1620      //
1621      // This means that the only transition we need to consider, is when a previously shared object is
1622      // not shared anymore. ie. the other objects have been destroyed or a deep copy has been made.
1623      // In those cases the m_shared flag changes to false after m_data has completed changing.
1624      // For any threads executing before the flag switches they will assume the object is still shared.
1625      bool isShared() const
1626      {
1627        if (m_shared) return true;
1628        if (m_data->isShared())        
1629        {                  
1630            updateShareStatus(true);
1631            return true;
1632        }
1633        return false;
1634      }
1635    
1636    /**    /**
1637    \brief if another object is sharing out member data make a copy to work with instead.    \brief if another object is sharing out member data make a copy to work with instead.
1638    */    */
1639    void exclusiveWrite()    void exclusiveWrite()
1640    {    {
1641      if (!m_data.unique())  //  if (!m_data.unique())
1642    //  {
1643    //     DataAbstract* t=m_data->deepCopy();
1644    // //      m_data=DataAbstract_ptr(t);
1645    //         set_m_data(DataAbstract_ptr(t));
1646    //  }
1647        if (isShared())
1648      {      {
1649         DataAbstract* t=m_data->deepCopy();         #pragma OMP CRITICAL
1650         m_data=DataAbstract_ptr(t);         {
1651            if (isShared())
1652            {
1653                DataAbstract* t=m_data->deepCopy();
1654                set_m_data(DataAbstract_ptr(t));
1655            }
1656           }
1657      }      }
1658    }    }
1659    
1660    
1661    
1662    
1663    
1664      /**
1665      \brief Modify the data abstract hosted by this Data object
1666      For internal use only.
1667      Passing a pointer to null is permitted (do this in the destructor)
1668      \warning Only to be called in single threaded code or inside a single/critical section. This method needs to be atomic.
1669      */
1670      void set_m_data(DataAbstract_ptr p);
1671    
1672      friend class DataAbstract;        // To allow calls to updateShareStatus
1673    
1674    // public:
1675    //    void JDebug()
1676    // {
1677    // std::cerr << "UC=" << m_data.use_count() << " O=" << m_data->m_owners.size() << std::endl;
1678    // for (int i=0;i<m_data->m_owners.size();++i)
1679    // std::cerr << m_data->m_owners[i] << " ";
1680    // std::cerr << std::endl;
1681    // }
1682    
1683  };  };
1684    
1685  }   // end namespace escript  }   // end namespace escript
# Line 1870  Data::binaryOp(const Data& right, Line 1928  Data::binaryOp(const Data& right,
1928         //         //
1929         // interpolate onto the RHS function space         // interpolate onto the RHS function space
1930         Data tempLeft(*this,right.getFunctionSpace());         Data tempLeft(*this,right.getFunctionSpace());
1931         m_data=tempLeft.m_data;  //        m_data=tempLeft.m_data;
1932           set_m_data(tempLeft.m_data);
1933       }       }
1934     }     }
1935     operandCheck(tempRight);     operandCheck(tempRight);

Legend:
Removed from v.2220  
changed lines
  Added in v.2221

  ViewVC Help
Powered by ViewVC 1.1.26