Null_Mutex.h

Go to the documentation of this file.
00001 // -*- C++ -*-
00002 
00003 //==========================================================================
00004 /**
00005  *  @file    Null_Mutex.h
00006  *
00007  *  $Id: Null_Mutex.h 80826 2008-03-04 14:51:23Z wotte $
00008  *
00009  *   Moved from Synch.h.
00010  *
00011  *  @author Douglas C. Schmidt <schmidt@cs.wustl.edu>
00012  */
00013 //==========================================================================
00014 
00015 #ifndef ACE_NULL_MUTEX_H
00016 #define ACE_NULL_MUTEX_H
00017 #include /**/ "ace/pre.h"
00018 
00019 // All methods in this class are inline, so there is no
00020 // need to import or export on Windows. -- CAE 12/18/2003
00021 // Update... leaving off the ACE_Export causes compile warnings in some
00022 // cases with Microsoft Visual Studio .NET 2005, so I added the ACE_Export
00023 // to these class declarations.  Steve Huston, 12/8/2006.
00024 
00025 #include "ace/os_include/os_errno.h"
00026 
00027 #if !defined (ACE_LACKS_PRAGMA_ONCE)
00028 # pragma once
00029 #endif /* ACE_LACKS_PRAGMA_ONCE */
00030 
00031 #include "ace/Global_Macros.h"
00032 #include "ace/OS_Memory.h"
00033 
00034 
00035 ACE_BEGIN_VERSIONED_NAMESPACE_DECL
00036 
00037 class ACE_Time_Value;
00038 
00039 /**
00040  * @class ACE_Null_Mutex
00041  *
00042  * @brief Implement a do nothing ACE_Mutex, i.e., all the methods are
00043  * no ops.
00044  */
00045 class ACE_Export ACE_Null_Mutex
00046 {
00047 public:
00048   ACE_Null_Mutex (const ACE_TCHAR * = 0)
00049     : lock_ (0) {}
00050   ~ACE_Null_Mutex (void) {}
00051   /// Return 0.
00052   int remove (void) {return 0;}
00053 
00054   /// Return 0.
00055   int acquire (void) {return 0;}
00056 
00057   /// Return -1 with @c errno == @c ETIME.
00058   int acquire (ACE_Time_Value &) {errno = ETIME; return -1;}
00059 
00060   /// Return -1 with @c errno == @c ETIME.
00061   int acquire (ACE_Time_Value *) {errno = ETIME; return -1;}
00062 
00063   /// Return 0.
00064   int tryacquire (void) {return 0;}
00065 
00066   /// Return 0.
00067   int release (void) {return 0;}
00068 
00069   /// Return 0.
00070   int acquire_write (void) {return 0;}
00071 
00072   /// Return 0.
00073   int tryacquire_write (void) {return 0;}
00074 
00075   /// Return 0.
00076   int tryacquire_write_upgrade (void) {return 0;}
00077 
00078   /// Return 0.
00079   int acquire_read (void) {return 0;}
00080 
00081   /// Return 0.
00082   int tryacquire_read (void) {return 0;}
00083 
00084   /// Dump the state of an object.
00085   void dump (void) const {}
00086 
00087   /// Declare the dynamic allocation hooks.
00088   //ACE_ALLOC_HOOK_DECLARE;
00089 
00090   int lock_; // A dummy lock.
00091 };
00092 
00093 #if defined (ACE_USES_OBSOLETE_GUARD_CLASSES)
00094 /**
00095  * @class ACE_Null_Mutex_Guard
00096  *
00097  * @brief This data structure is meant to be used within a method or
00098  * function...  It performs automatic aquisition and release of
00099  * an ACE_Null_Mutex.
00100  *
00101  * This class is obsolete and should be replaced by
00102  * ACE_Guard<ACE_Null_Mutex>.
00103  */
00104 class ACE_Export ACE_Null_Mutex_Guard
00105 {
00106 public:
00107   ACE_Null_Mutex_Guard (ACE_Null_Mutex &) {}
00108   ~ACE_Null_Mutex_Guard (void) {}
00109   int remove (void) {return 0;}
00110   int locked (void) {return 1;}
00111   int acquire (void) {return 0;}
00112   int tryacquire (void) {return 0;}
00113   int release (void) {return 0:}
00114   void dump (void) const {}
00115 
00116 private:
00117   // = Prevent assignment and initialization.
00118   void operator= (const ACE_Null_Mutex_Guard &);
00119   ACE_Null_Mutex_Guard (const ACE_Null_Mutex_Guard &);
00120 };
00121 #endif /* ACE_USES_OBSOLETE_GUARD_CLASSES */
00122 
00123 template <class ACE_LOCK>
00124 class ACE_Guard;
00125 
00126 /**
00127  * @class ACE_Guard<ACE_Null_Mutex>
00128  *
00129  * @brief Template specialization of ACE_Guard for the
00130  * ACE_Null_Mutex.
00131  *
00132  * This specialization is useful since it helps to speedup
00133  * performance of the "Null_Mutex" considerably.
00134  */
00135 template<>
00136 class ACE_Export ACE_Guard<ACE_Null_Mutex>
00137 {
00138 public:
00139   // = Initialization and termination methods.
00140   ACE_Guard (ACE_Null_Mutex &) {}
00141   ACE_Guard (ACE_Null_Mutex &, int) {}
00142   ACE_Guard (ACE_Null_Mutex &, int, int) {}
00143 #if defined (ACE_WIN32)
00144   ~ACE_Guard (void) {}
00145 #endif /* ACE_WIN32 */
00146 
00147   int acquire (void) { return 0; }
00148   int tryacquire (void) { return 0; }
00149   int release (void) { return 0; }
00150   void disown (void) {}
00151   int locked (void) { return 1; }
00152   int remove (void) { return 0; }
00153   void dump (void) const {}
00154 
00155 private:
00156 
00157   // Disallow copying and assignment.
00158   ACE_Guard (const ACE_Guard<ACE_Null_Mutex> &);
00159   void operator= (const ACE_Guard<ACE_Null_Mutex> &);
00160 
00161 };
00162 
00163 template <class ACE_LOCK>
00164 class ACE_Write_Guard;
00165 
00166 /**
00167  * @class ACE_Write_Guard<ACE_Null_Mutex>
00168  *
00169  */
00170 template<>
00171 class ACE_Export ACE_Write_Guard<ACE_Null_Mutex>
00172   : public ACE_Guard<ACE_Null_Mutex>
00173 {
00174 public:
00175   ACE_Write_Guard (ACE_Null_Mutex &m)
00176     : ACE_Guard<ACE_Null_Mutex> (m) {}
00177   ACE_Write_Guard (ACE_Null_Mutex &m, int blocked)
00178     : ACE_Guard<ACE_Null_Mutex> (m, blocked) {}
00179 
00180   int acquire_write (void) { return 0; }
00181   int acquire (void) { return 0; }
00182   int tryacquire_write (void) { return 0; }
00183   int tryacquire (void) { return 0; }
00184   void dump (void) const {}
00185 };
00186 
00187 template <class ACE_LOCK>
00188 class ACE_Read_Guard;
00189 
00190 /**
00191  * @class ACE_Read_Guard<ACE_Null_Mutex>
00192  *
00193  */
00194 template<>
00195 class ACE_Export ACE_Read_Guard<ACE_Null_Mutex>
00196   : public ACE_Guard<ACE_Null_Mutex>
00197 {
00198 public:
00199   ACE_Read_Guard (ACE_Null_Mutex &m)
00200     : ACE_Guard<ACE_Null_Mutex> (m) {}
00201   ACE_Read_Guard (ACE_Null_Mutex &m, int blocked)
00202     : ACE_Guard<ACE_Null_Mutex> (m, blocked) {}
00203 
00204   int acquire_read (void) { return 0; }
00205   int acquire (void) { return 0; }
00206   int tryacquire_read (void) { return 0; }
00207   int tryacquire (void) { return 0; }
00208   void dump (void) const {}
00209 };
00210 
00211 template <class T> class ACE_Malloc_Lock_Adapter_T;
00212 
00213 /**
00214  * @class ACE_Malloc_Lock_Adapter_T<ACE_Null_Mutex>
00215  *
00216  */
00217 template<>
00218 class ACE_Export ACE_Malloc_Lock_Adapter_T<ACE_Null_Mutex>
00219 {
00220 public:
00221   ACE_Null_Mutex * operator () (const ACE_TCHAR *name)
00222   {
00223     ACE_Null_Mutex *p;
00224     ACE_NEW_RETURN (p, ACE_Null_Mutex (name), 0);
00225     return p;
00226   }
00227 };
00228 
00229 ACE_END_VERSIONED_NAMESPACE_DECL
00230 
00231 #include /**/ "ace/post.h"
00232 #endif /* ACE_NULL_MUTEX_H */

Generated on Tue Feb 2 17:18:41 2010 for ACE by  doxygen 1.4.7