Null_Mutex.h

Go to the documentation of this file.
00001 // -*- C++ -*-
00002 
00003 //==========================================================================
00004 /**
00005  *  @file    Null_Mutex.h
00006  *
00007  *  Null_Mutex.h,v 4.8 2006/02/10 10:08:25 jwillemsen Exp
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 #include "ace/os_include/os_errno.h"
00022 
00023 #if !defined (ACE_LACKS_PRAGMA_ONCE)
00024 # pragma once
00025 #endif /* ACE_LACKS_PRAGMA_ONCE */
00026 
00027 #include "ace/Global_Macros.h"
00028 #include "ace/OS_Memory.h"
00029 
00030 
00031 ACE_BEGIN_VERSIONED_NAMESPACE_DECL
00032 
00033 class ACE_Time_Value;
00034 
00035 /**
00036  * @class ACE_Null_Mutex
00037  *
00038  * @brief Implement a do nothing <ACE_Mutex>, i.e., all the methods are
00039  * no ops.
00040  */
00041 class ACE_Null_Mutex
00042 {
00043 public:
00044   ACE_Null_Mutex (const ACE_TCHAR * = 0)
00045     : lock_ (0) {}
00046   ~ACE_Null_Mutex (void) {}
00047   /// Return 0.
00048   int remove (void) {return 0;}
00049 
00050   /// Return 0.
00051   int acquire (void) {return 0;}
00052 
00053   /// Return -1 with <errno> == <ETIME>.
00054   int acquire (ACE_Time_Value &) {errno = ETIME; return -1;}
00055 
00056   /// Return -1 with <errno> == <ETIME>.
00057   int acquire (ACE_Time_Value *) {errno = ETIME; return -1;}
00058 
00059   /// Return 0.
00060   int tryacquire (void) {return 0;}
00061 
00062   /// Return 0.
00063   int release (void) {return 0;}
00064 
00065   /// Return 0.
00066   int acquire_write (void) {return 0;}
00067 
00068   /// Return 0.
00069   int tryacquire_write (void) {return 0;}
00070 
00071   /// Return 0.
00072   int tryacquire_write_upgrade (void) {return 0;}
00073 
00074   /// Return 0.
00075   int acquire_read (void) {return 0;}
00076 
00077   /// Return 0.
00078   int tryacquire_read (void) {return 0;}
00079 
00080   /// Dump the state of an object.
00081   void dump (void) const {}
00082 
00083   /// Declare the dynamic allocation hooks.
00084   //ACE_ALLOC_HOOK_DECLARE;
00085 
00086   int lock_; // A dummy lock.
00087 };
00088 
00089 #if defined (ACE_USES_OBSOLETE_GUARD_CLASSES)
00090 /**
00091  * @class ACE_Null_Mutex_Guard
00092  *
00093  * @brief This data structure is meant to be used within a method or
00094  * function...  It performs automatic aquisition and release of
00095  * an ACE_Null_Mutex.
00096  *
00097  * This class is obsolete and should be replaced by
00098  * ACE_Guard<ACE_Null_Mutex>.
00099  */
00100 class ACE_Null_Mutex_Guard
00101 {
00102 public:
00103   ACE_Null_Mutex_Guard (ACE_Null_Mutex &) {}
00104   ~ACE_Null_Mutex_Guard (void) {}
00105   int remove (void) {return 0;}
00106   int locked (void) {return 1;}
00107   int acquire (void) {return 0;}
00108   int tryacquire (void) {return 0;}
00109   int release (void) {return 0:}
00110   void dump (void) const {}
00111 
00112 private:
00113   // = Prevent assignment and initialization.
00114   void operator= (const ACE_Null_Mutex_Guard &);
00115   ACE_Null_Mutex_Guard (const ACE_Null_Mutex_Guard &);
00116 };
00117 #endif /* ACE_USES_OBSOLETE_GUARD_CLASSES */
00118 
00119 template <class ACE_LOCK>
00120 class ACE_Guard;
00121 
00122 /**
00123  * @class ACE_Guard<ACE_Null_Mutex>
00124  *
00125  * @brief Template specialization of ACE_Guard for the
00126  * ACE_Null_Mutex.
00127  *
00128  * This specialization is useful since it helps to speedup
00129  * performance of the "Null_Mutex" considerably.
00130  */
00131 template<>
00132 class ACE_Guard<ACE_Null_Mutex>
00133 {
00134 public:
00135   // = Initialization and termination methods.
00136   ACE_Guard (ACE_Null_Mutex &) {}
00137   ACE_Guard (ACE_Null_Mutex &, int) {}
00138   ACE_Guard (ACE_Null_Mutex &, int, int) {}
00139 #if defined (ACE_WIN32)
00140   ~ACE_Guard (void) {}
00141 #endif /* ACE_WIN32 */
00142 
00143   int acquire (void) { return 0; }
00144   int tryacquire (void) { return 0; }
00145   int release (void) { return 0; }
00146   void disown (void) {}
00147   int locked (void) { return 1; }
00148   int remove (void) { return 0; }
00149   void dump (void) const {}
00150 
00151 private:
00152 
00153   // Disallow copying and assignment.
00154   ACE_Guard (const ACE_Guard<ACE_Null_Mutex> &);
00155   void operator= (const ACE_Guard<ACE_Null_Mutex> &);
00156 
00157 };
00158 
00159 template <class ACE_LOCK>
00160 class ACE_Write_Guard;
00161 
00162 /**
00163  * @class ACE_Write_Guard<ACE_Null_Mutex>
00164  *
00165  */
00166 template<>
00167 class ACE_Write_Guard<ACE_Null_Mutex> : public ACE_Guard<ACE_Null_Mutex>
00168 {
00169 public:
00170   ACE_Write_Guard (ACE_Null_Mutex &m)
00171     : ACE_Guard<ACE_Null_Mutex> (m) {}
00172   ACE_Write_Guard (ACE_Null_Mutex &m, int blocked)
00173     : ACE_Guard<ACE_Null_Mutex> (m, blocked) {}
00174 
00175   int acquire_write (void) { return 0; }
00176   int acquire (void) { return 0; }
00177   int tryacquire_write (void) { return 0; }
00178   int tryacquire (void) { return 0; }
00179   void dump (void) const {}
00180 };
00181 
00182 template <class ACE_LOCK>
00183 class ACE_Read_Guard;
00184 
00185 /**
00186  * @class ACE_Read_Guard<ACE_Null_Mutex>
00187  *
00188  */
00189 template<>
00190 class ACE_Read_Guard<ACE_Null_Mutex> : public ACE_Guard<ACE_Null_Mutex>
00191 {
00192 public:
00193   ACE_Read_Guard (ACE_Null_Mutex &m)
00194     : ACE_Guard<ACE_Null_Mutex> (m) {}
00195   ACE_Read_Guard (ACE_Null_Mutex &m, int blocked)
00196     : ACE_Guard<ACE_Null_Mutex> (m, blocked) {}
00197 
00198   int acquire_read (void) { return 0; }
00199   int acquire (void) { return 0; }
00200   int tryacquire_read (void) { return 0; }
00201   int tryacquire (void) { return 0; }
00202   void dump (void) const {}
00203 };
00204 
00205 template <class T> class ACE_Malloc_Lock_Adapter_T;
00206 
00207 /**
00208  * @class ACE_Malloc_Lock_Adapter_T<ACE_Null_Mutex>
00209  *
00210  */
00211 template<>
00212 class ACE_Malloc_Lock_Adapter_T<ACE_Null_Mutex>
00213 {
00214 public:
00215   ACE_Null_Mutex * operator () (const ACE_TCHAR *name)
00216   {
00217     ACE_Null_Mutex *p;
00218     ACE_NEW_RETURN (p, ACE_Null_Mutex (name), 0);
00219     return p;
00220   }
00221 };
00222 
00223 ACE_END_VERSIONED_NAMESPACE_DECL
00224 
00225 #include /**/ "ace/post.h"
00226 #endif /* ACE_NULL_MUTEX_H */

Generated on Thu Nov 9 09:41:57 2006 for ACE by doxygen 1.3.6