00001 /* -*- C++ -*- */ 00002 00003 //============================================================================= 00004 /** 00005 * @file RW_Process_Mutex.h 00006 * 00007 * $Id: RW_Process_Mutex.h,v 1.1.1.1 2001/12/04 14:33:07 chad Exp $ 00008 * 00009 * @author Douglas C. Schmidt <schmidt@cs.wustl.edu> 00010 */ 00011 //============================================================================= 00012 00013 #ifndef ACE_RW_PROCESS_MUTEX_H 00014 #define ACE_RW_PROCESS_MUTEX_H 00015 #include "ace/pre.h" 00016 00017 #include "ace/File_Lock.h" 00018 00019 #if !defined (ACE_LACKS_PRAGMA_ONCE) 00020 # pragma once 00021 #endif /* ACE_LACKS_PRAGMA_ONCE */ 00022 00023 /** 00024 * @class ACE_RW_Process_Mutex 00025 * 00026 * @brief Wrapper for readers/writer locks that exist across processes. 00027 * 00028 * Note that because this class uses the 00029 * <ACE_File_Lock> as its implementation it only can be reliably 00030 * used between separate processes, rather than threads in the 00031 * same process. This isn't a limitation of ACE, it's simply 00032 * the file lock semantics on UNIX and Win32. 00033 */ 00034 class ACE_Export ACE_RW_Process_Mutex 00035 { 00036 public: 00037 /// Create a readers/writer <Process_Mutex>, passing in the optional 00038 /// <name>. If not specified, a name is generated. 00039 ACE_RW_Process_Mutex (const ACE_TCHAR *name = 0, 00040 int flags = O_CREAT|O_RDWR); 00041 00042 ~ACE_RW_Process_Mutex (void); 00043 00044 /** 00045 * Explicitly destroy the mutex. Note that only one thread should 00046 * call this method since it doesn't protect against race 00047 * conditions. 00048 */ 00049 int remove (void); 00050 00051 /// Acquire lock ownership (wait on queue if necessary). 00052 int acquire (void); 00053 00054 /** 00055 * Conditionally acquire lock (i.e., don't wait on queue). Returns 00056 * -1 on failure. If we "failed" because someone else already had 00057 * the lock, <errno> is set to <EBUSY>. 00058 */ 00059 int tryacquire (void); 00060 00061 /// Release lock and unblock a thread at head of queue. 00062 int release (void); 00063 00064 /// Acquire lock ownership (wait on queue if necessary). 00065 int acquire_read (void); 00066 00067 /// Acquire lock ownership (wait on queue if necessary). 00068 int acquire_write (void); 00069 00070 /** 00071 * Conditionally acquire a lock (i.e., won't block). Returns -1 on 00072 * failure. If we "failed" because someone else already had the 00073 * lock, <errno> is set to <EBUSY>. 00074 */ 00075 int tryacquire_read (void); 00076 00077 /** 00078 * Conditionally acquire a lock (i.e., won't block). Returns -1 on 00079 * failure. If we "failed" because someone else already had the 00080 * lock, <errno> is set to <EBUSY>. 00081 */ 00082 int tryacquire_write (void); 00083 00084 /// Attempt to upgrade a read lock to a write lock. Returns 0 on 00085 /// success, -1 on failure. 00086 int tryacquire_write_upgrade (void); 00087 00088 /// Return the underlying lock. 00089 const ACE_File_Lock &lock (void) const; 00090 00091 /// Dump the state of an object. 00092 void dump (void) const; 00093 00094 /// Declare the dynamic allocation hooks. 00095 ACE_ALLOC_HOOK_DECLARE; 00096 00097 private: 00098 /// If the user does not provide a name we generate a unique name in 00099 /// this buffer. 00100 ACE_TCHAR name_[ACE_UNIQUE_NAME_LEN]; 00101 00102 /// Create and return the unique name. 00103 const ACE_TCHAR *unique_name (void); 00104 00105 /// We need this to get the readers/writer semantics... 00106 ACE_File_Lock lock_; 00107 }; 00108 00109 #if defined (__ACE_INLINE__) 00110 #include "ace/RW_Process_Mutex.inl" 00111 #endif /* __ACE_INLINE__ */ 00112 00113 #include "ace/post.h" 00114 #endif /* ACE_RW_PROCESS_MUTEX_H */
1.2.14 written by Dimitri van Heesch,
© 1997-2002