00001 // -*- C++ -*- 00002 00003 //========================================================================== 00004 /** 00005 * @file Null_Mutex.h 00006 * 00007 * $Id: Null_Mutex.h 86731 2009-09-17 12:23:48Z johnnyw $ 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 * @brief Template specialization of ACE_Guard for the 00128 * ACE_Null_Mutex. 00129 * 00130 * This specialization is useful since it helps to speedup 00131 * performance of the "Null_Mutex" considerably. 00132 */ 00133 template<> 00134 class ACE_Export ACE_Guard<ACE_Null_Mutex> 00135 { 00136 public: 00137 // = Initialization and termination methods. 00138 ACE_Guard (ACE_Null_Mutex &) {} 00139 ACE_Guard (ACE_Null_Mutex &, int) {} 00140 ACE_Guard (ACE_Null_Mutex &, int, int) {} 00141 #if defined (ACE_WIN32) 00142 ~ACE_Guard (void) {} 00143 #endif /* ACE_WIN32 */ 00144 00145 int acquire (void) { return 0; } 00146 int tryacquire (void) { return 0; } 00147 int release (void) { return 0; } 00148 void disown (void) {} 00149 int locked (void) { return 1; } 00150 int remove (void) { return 0; } 00151 void dump (void) const {} 00152 00153 private: 00154 00155 // Disallow copying and assignment. 00156 ACE_Guard (const ACE_Guard<ACE_Null_Mutex> &); 00157 void operator= (const ACE_Guard<ACE_Null_Mutex> &); 00158 00159 }; 00160 00161 template <class ACE_LOCK> 00162 class ACE_Write_Guard; 00163 00164 /** 00165 * @brief Template specialization of ACE_Write_Guard for the 00166 * ACE_Null_Mutex. 00167 */ 00168 template<> 00169 class ACE_Export ACE_Write_Guard<ACE_Null_Mutex> 00170 : public ACE_Guard<ACE_Null_Mutex> 00171 { 00172 public: 00173 ACE_Write_Guard (ACE_Null_Mutex &m) 00174 : ACE_Guard<ACE_Null_Mutex> (m) {} 00175 ACE_Write_Guard (ACE_Null_Mutex &m, int blocked) 00176 : ACE_Guard<ACE_Null_Mutex> (m, blocked) {} 00177 00178 int acquire_write (void) { return 0; } 00179 int acquire (void) { return 0; } 00180 int tryacquire_write (void) { return 0; } 00181 int tryacquire (void) { return 0; } 00182 void dump (void) const {} 00183 }; 00184 00185 template <class ACE_LOCK> 00186 class ACE_Read_Guard; 00187 00188 /** 00189 * @brief Template specialization of ACE_Read)Guard for the 00190 * ACE_Null_Mutex. 00191 */ 00192 template<> 00193 class ACE_Export ACE_Read_Guard<ACE_Null_Mutex> 00194 : public ACE_Guard<ACE_Null_Mutex> 00195 { 00196 public: 00197 ACE_Read_Guard (ACE_Null_Mutex &m) 00198 : ACE_Guard<ACE_Null_Mutex> (m) {} 00199 ACE_Read_Guard (ACE_Null_Mutex &m, int blocked) 00200 : ACE_Guard<ACE_Null_Mutex> (m, blocked) {} 00201 00202 int acquire_read (void) { return 0; } 00203 int acquire (void) { return 0; } 00204 int tryacquire_read (void) { return 0; } 00205 int tryacquire (void) { return 0; } 00206 void dump (void) const {} 00207 }; 00208 00209 template <class T> class ACE_Malloc_Lock_Adapter_T; 00210 00211 /** 00212 * @brief Template specialization of ACE_Malloc_Lock_Adapter_T for the 00213 * ACE_Null_Mutex. 00214 */ 00215 template<> 00216 class ACE_Export ACE_Malloc_Lock_Adapter_T<ACE_Null_Mutex> 00217 { 00218 public: 00219 ACE_Null_Mutex * operator () (const ACE_TCHAR *name) 00220 { 00221 ACE_Null_Mutex *p; 00222 ACE_NEW_RETURN (p, ACE_Null_Mutex (name), 0); 00223 return p; 00224 } 00225 }; 00226 00227 ACE_END_VERSIONED_NAMESPACE_DECL 00228 00229 #include /**/ "ace/post.h" 00230 #endif /* ACE_NULL_MUTEX_H */