Main Page   Modules   Namespace List   Class Hierarchy   Compound List   File List   Namespace Members   Compound Members   File Members  

at_atomic.h

Go to the documentation of this file.
00001 //
00002 // The Austria library is copyright (c) Gianni Mariani 2004.
00003 // 
00004 // Grant Of License.  Grants to LICENSEE the non-exclusive right to use the Austria
00005 // library subject to the terms of the LGPL.
00006 // 
00007 // A copy of the license is available in this directory or one may be found at this URL:
00008 //      http://www.gnu.org/copyleft/lesser.txt
00009 // 
00015 #ifndef x_at_atomic_h_x
00016 #define x_at_atomic_h_x 1
00017 
00018 #include "at_exports.h"
00019 #include "at_os.h"
00020 
00021 //
00022 // AT_ATOMIC_H is defined in at_os.h and provides a platform specific
00023 // header file name. (at_gx86_atomic.h or at_win32_atomic.h)
00024 #include AT_ATOMIC_H
00025 
00026 // Austria namespace
00027 namespace at
00028 {
00029 
00030 // ======== AtomicCount ===============================================
00036 class AUSTRIA_EXPORT AtomicCount
00037 {
00038 
00043     volatile AtomicCountType                m_atomic_count;
00044 
00045 public:
00046 
00047     // ======== AtomicCount ===========================================
00054     inline AtomicCount( AtomicCountType l_atomic_count = 0 )
00055       : m_atomic_count( l_atomic_count )
00056     {
00057     }
00058 
00059 
00060     // ======== operator ++() =========================================
00066     inline AtomicCountType operator ++()
00067     {
00068         return AtomicIncrement( & m_atomic_count ) + 1;
00069     }
00070 
00071     // ======== operator --() =========================================
00077     inline AtomicCountType operator --()
00078     {
00079         return AtomicDecrement( & m_atomic_count ) - 1;
00080     }
00081     
00082 
00083     // ======== operator ++(int) ======================================
00089     inline AtomicCountType operator ++(int)
00090     {
00091         return AtomicIncrement( & m_atomic_count );
00092     }
00093 
00094     
00095     // ======== operator --(int) ======================================
00101     inline AtomicCountType operator --(int)
00102     {
00103         return AtomicDecrement( & m_atomic_count );
00104     }
00105 
00106 
00107     // ======== Get ===================================================
00117     inline AtomicCountType Get() const
00118     {
00119         return m_atomic_count;
00120     }
00121 
00122 
00123     // ======== Bump ==================================================
00131     inline AtomicCountType Bump(
00132         AtomicCountType         i_add_val
00133     ) {
00134         return AtomicBump( & m_atomic_count, i_add_val );
00135     }
00136 
00137 
00138     // ======== Exchange ==============================================
00147     inline AtomicCountType Exchange(
00148         AtomicCountType         i_new_val
00149     ) {
00150         return AtomicExchange(
00151             & m_atomic_count,
00152             i_new_val
00153         );
00154     }
00155 
00156 
00157     // ======== CompareExchange =======================================
00168     inline AtomicCountType CompareExchange(
00169         AtomicCountType         i_new_val,
00170         AtomicCountType         i_compare_val
00171     ) {
00172         return AtomicCompareExchange(
00173             & m_atomic_count,
00174             i_new_val,
00175             i_compare_val
00176         );
00177     }
00178 
00179     
00180 };
00181 
00182 
00183 // ======== AtomicExchangePtr =========================================
00190 template <typename w_type>
00191 class AtomicExchange_Ptr
00192 {
00193     volatile AtomicExchangeablePointer      m_data;
00194     public:
00195 
00196 
00197     // ======== AtomicExchange_Ptr ====================================
00204     AtomicExchange_Ptr( w_type i_init_val )
00205       : m_data( static_cast<w_type>( i_init_val ) )
00206     {
00207     }
00208 
00209     AtomicExchange_Ptr()
00210       : m_data( 0 )
00211     {
00212     }
00213 
00214     // ======== Get ===================================================
00221     inline w_type Get() const
00222     {
00223         return static_cast<w_type>( m_data );
00224     }
00225 
00226     // ======== Exchange =============================================
00235     inline w_type Exchange( w_type i_val )
00236     {
00237         return static_cast<w_type>(
00238             AtomicExchange(
00239                 & m_data,
00240                 static_cast<AtomicExchangeablePointer>( i_val )
00241             )
00242         );
00243     }
00244 
00245     // ======== CompareExchange =======================================
00256     inline w_type CompareExchange(
00257         w_type                  i_val,
00258         w_type                  i_compare
00259     ) {
00260         return static_cast<w_type>(
00261             AtomicCompareExchange(
00262                 & m_data,
00263                 static_cast<AtomicExchangeablePointer>( i_val ),
00264                 static_cast<AtomicExchangeablePointer>( i_compare )
00265             )
00266         );
00267     }    
00268     
00269 };
00270 
00271 // ======== AtomicExchange_Val =========================================
00278 template <typename w_type>
00279 class AtomicExchange_Val
00280 {
00281     volatile AtomicExchangeableValue        m_data;
00282     public:
00283 
00284 
00285     // ======== AtomicExchange_Val ====================================
00292     AtomicExchange_Val( w_type i_init_val )
00293       : m_data( AtomicExchangeableValue( i_init_val ) )
00294     {
00295     }
00296 
00297     AtomicExchange_Val()
00298       : m_data( 0 )
00299     {
00300     }
00301 
00302     // ======== Get ===================================================
00309     inline w_type Get() const
00310     {
00311         return m_data;
00312     }
00313 
00314     // ======== Exchange =============================================
00323     inline w_type Exchange( w_type i_val )
00324     {
00325         return w_type(
00326             AtomicExchange(
00327                 & m_data,
00328                 AtomicExchangeableValue( i_val )
00329             )
00330         );
00331     }
00332     
00333     // ======== CompareExchange =======================================
00344     inline w_type CompareExchange(
00345         w_type                  i_val,
00346         w_type                  i_compare
00347     ) {
00348         return w_type(
00349             AtomicCompareExchange(
00350                 & m_data,
00351                 AtomicExchangeableValue( i_val ),
00352                 AtomicExchangeableValue( i_compare )
00353             )
00354         );
00355     }    
00356     
00357 };
00358 
00359 }; // namespace
00360 
00361 #endif // x_at_atomic_h_x
00362 
00363 

Generated for Austria by doxygen and MakeXS at Sun Oct 24 17:35:34 PDT 2004