Main Page   Class Hierarchy   Alphabetical List   Compound List   File List   Compound Members   File Members   Related Pages  

Atomic_Op.h

Go to the documentation of this file.
00001 /* -*- C++ -*- */
00002 
00003 //=============================================================================
00004 /**
00005  *  @file    Atomic_Op.h
00006  *
00007  *  $Id: Atomic_Op.h,v 1.1.1.1 2003/02/21 18:36:32 chad Exp $
00008  *
00009  *  @author Douglas C. Schmidt <schmidt@uci.edu>
00010  */
00011 //=============================================================================
00012 
00013 #ifndef ACE_ATOMIC_OP_H
00014 #define ACE_ATOMIC_OP_H
00015 #include "ace/pre.h"
00016 
00017 #include "ace/config-all.h"
00018 
00019 #if !defined (ACE_LACKS_PRAGMA_ONCE)
00020 # pragma once
00021 #endif /* ACE_LACKS_PRAGMA_ONCE */
00022 
00023 #include "ace/Synch.h"
00024 
00025 
00026 // Include the templates here.
00027 #include "ace/Atomic_Op_T.h"
00028 
00029 // Determine whether builtin atomic op support is
00030 // available on this platform.
00031 #if defined (ACE_HAS_THREADS)
00032 # if defined (WIN32)
00033 #  if defined (ACE_HAS_INTERLOCKED_EXCHANGEADD)
00034 #   define ACE_HAS_BUILTIN_ATOMIC_OP
00035 #  else /* ACE_HAS_INTERLOCKED_EXCHANGEADD */
00036     // Inline assembly emulation of InterlockedExchangeAdd
00037     // is currently only implemented for MSVC (x86 only) and Borland.
00038 #   if (defined (_MSC_VER) && defined (_M_IX86)) || defined (__BORLANDC__)
00039 #    define ACE_HAS_BUILTIN_ATOMIC_OP
00040 #   endif /* _MSC_VER || __BORLANDC__ */
00041 #  endif /* ACE_HAS_INTERLOCKED_EXCHANGEADD */
00042 # elif defined (__GNUC__) && defined (ACE_HAS_PENTIUM)
00043 #  define ACE_HAS_BUILTIN_ATOMIC_OP
00044 # endif /* WIN32 */
00045 #endif /* ACE_HAS_THREADS */
00046 
00047 #if defined (ACE_HAS_BUILTIN_ATOMIC_OP)
00048 ACE_TEMPLATE_SPECIALIZATION
00049 /**
00050  * @class ACE_Atomic_Op<ACE_Thread_Mutex, long>
00051  *
00052  * @brief Specialization of ACE_Atomic_Op for platforms that
00053  * support atomic integer operations.
00054  */
00055 class ACE_Export ACE_Atomic_Op<ACE_Thread_Mutex, long>
00056 {
00057 public:
00058   /// Initialize <value_> to 0.
00059   ACE_Atomic_Op (void);
00060 
00061   /// Initialize <value_> to c.
00062   ACE_Atomic_Op (long c);
00063 
00064   /// Manage copying...
00065   ACE_Atomic_Op (const ACE_Atomic_Op<ACE_Thread_Mutex, long> &c);
00066 
00067   /// Atomically pre-increment <value_>.
00068   long operator++ (void);
00069 
00070   /// Atomically post-increment <value_>.
00071   long operator++ (int);
00072 
00073   /// Atomically increment <value_> by rhs.
00074   long operator+= (long rhs);
00075 
00076   /// Atomically pre-decrement <value_>.
00077   long operator-- (void);
00078 
00079   /// Atomically post-decrement <value_>.
00080   long operator-- (int);
00081 
00082   /// Atomically decrement <value_> by rhs.
00083   long operator-= (long rhs);
00084 
00085   /// Atomically compare <value_> with rhs.
00086   int operator== (long rhs) const;
00087 
00088   /// Atomically compare <value_> with rhs.
00089   int operator!= (long rhs) const;
00090 
00091   /// Atomically check if <value_> greater than or equal to rhs.
00092   int operator>= (long rhs) const;
00093 
00094   /// Atomically check if <value_> greater than rhs.
00095   int operator> (long rhs) const;
00096 
00097   /// Atomically check if <value_> less than or equal to rhs.
00098   int operator<= (long rhs) const;
00099 
00100   /// Atomically check if <value_> less than rhs.
00101   int operator< (long rhs) const;
00102 
00103   /// Atomically assign rhs to <value_>.
00104   void operator= (long rhs);
00105 
00106   /// Atomically assign <rhs> to <value_>.
00107   void operator= (const ACE_Atomic_Op<ACE_Thread_Mutex, long> &rhs);
00108 
00109   /// Explicitly return <value_>.
00110   long value (void) const;
00111 
00112   /// Dump the state of an object.
00113   void dump (void) const;
00114 
00115   /// Explicitly return <value_> (by reference).
00116   volatile long &value_i (void);
00117 
00118   // ACE_ALLOC_HOOK_DECLARE;
00119   // Declare the dynamic allocation hooks.
00120 
00121   /// Used during ACE object manager initialization to optimize the fast
00122   /// atomic op implementation according to the number of CPUs.
00123   static void init_functions (void);
00124 
00125 private:
00126   // This function cannot be supported by this template specialization.
00127   // If you need access to an underlying lock, use the ACE_Atomic_Op_Ex
00128   // template instead.
00129   ACE_UNIMPLEMENTED_FUNC (ACE_Thread_Mutex &mutex (void))
00130 
00131   /// Current object decorated by the atomic op.
00132   volatile long value_;
00133 
00134   // Single-cpu atomic op implementations.
00135   static long single_cpu_increment (volatile long *value);
00136   static long single_cpu_decrement (volatile long *value);
00137   static long single_cpu_exchange_add (volatile long *value, long rhs);
00138 
00139   // Multi-cpu atomic op implementations.
00140   static long multi_cpu_increment (volatile long *value);
00141   static long multi_cpu_decrement (volatile long *value);
00142   static long multi_cpu_exchange_add (volatile long *value, long rhs);
00143 
00144   // Pointers to selected atomic op implementations.
00145   static long (*increment_fn_) (volatile long *);
00146   static long (*decrement_fn_) (volatile long *);
00147   static long (*exchange_add_fn_) (volatile long *, long);
00148 };
00149 #endif /* ACE_HAS_BUILTIN_ATOMIC_OP */
00150 
00151 
00152 #if defined (__ACE_INLINE__)
00153 #include "ace/Atomic_Op.i"
00154 #endif /* __ACE_INLINE__ */
00155 
00156 #include "ace/post.h"
00157 #endif /*ACE_ATOMIC_OP_H*/

Generated on Mon Jun 16 11:19:09 2003 for ACE by doxygen1.2.14 written by Dimitri van Heesch, © 1997-2002