00001 // -*- C++ -*- 00002 00003 //========================================================================== 00004 /** 00005 * @file Event.h 00006 * 00007 * Event.h,v 4.4 2005/10/28 16:14:52 ossama Exp 00008 * 00009 * Moved from Synch.h. 00010 * 00011 * @author Douglas C. Schmidt <schmidt@cs.wustl.edu> 00012 */ 00013 //========================================================================== 00014 00015 #ifndef ACE_EVENT_H 00016 #define ACE_EVENT_H 00017 #include /**/ "ace/pre.h" 00018 00019 #include "ace/ACE_export.h" 00020 00021 #if !defined (ACE_LACKS_PRAGMA_ONCE) 00022 # pragma once 00023 #endif /* ACE_LACKS_PRAGMA_ONCE */ 00024 00025 #include "ace/OS_NS_Thread.h" 00026 00027 ACE_BEGIN_VERSIONED_NAMESPACE_DECL 00028 00029 /** 00030 * @class ACE_Event 00031 * 00032 * @brief A wrapper around the Win32 event locking mechanism. 00033 * 00034 * Portable implementation of an Event mechanism, which is native to 00035 * Win32, but must be emulated on UNIX. All platforms support 00036 * process-scope locking support. However, only Win32 platforms 00037 * support global naming and system-scope locking support. 00038 */ 00039 class ACE_Export ACE_Event 00040 { 00041 public: 00042 /// Constructor that creates event. 00043 ACE_Event (int manual_reset = 0, 00044 int initial_state = 0, 00045 int type = USYNC_THREAD, 00046 const ACE_TCHAR *name = 0, 00047 void *arg = 0); 00048 00049 /// Implicitly destroy the event variable. 00050 ~ACE_Event (void); 00051 00052 /** 00053 * Explicitly destroy the event variable. Note that only one thread 00054 * should call this method since it doesn't protect against race 00055 * conditions. 00056 */ 00057 int remove (void); 00058 00059 /// Underlying handle to event. 00060 ACE_event_t handle (void) const; 00061 00062 /** 00063 * Set the underlying handle to event. Note that this method assumes 00064 * ownership of the <handle> and will close it down in <remove>. If 00065 * you want the <handle> to stay open when <remove> is called make 00066 * sure to call <dup> on the <handle> before closing it. You are 00067 * responsible for the closing the existing <handle> before 00068 * overwriting it. 00069 */ 00070 void handle (ACE_event_t new_handle); 00071 00072 /** 00073 * if MANUAL reset 00074 * sleep till the event becomes signaled 00075 * event remains signaled after wait() completes. 00076 * else AUTO reset 00077 * sleep till the event becomes signaled 00078 * event resets wait() completes. 00079 */ 00080 int wait (void); 00081 00082 /// Same as wait() above, but this one can be timed 00083 /// @a abstime is absolute time-of-day if if @a use_absolute_time 00084 /// is non-0, else it is relative time. 00085 int wait (const ACE_Time_Value *abstime, 00086 int use_absolute_time = 1); 00087 00088 /** 00089 * if MANUAL reset 00090 * wake up all waiting threads 00091 * set to signaled state 00092 * else AUTO reset 00093 * if no thread is waiting, set to signaled state 00094 * if thread(s) are waiting, wake up one waiting thread and 00095 * reset event 00096 */ 00097 int signal (void); 00098 00099 /** 00100 * if MANUAL reset 00101 * wakeup all waiting threads and 00102 * reset event 00103 * else AUTO reset 00104 * wakeup one waiting thread (if present) and 00105 * reset event 00106 */ 00107 int pulse (void); 00108 00109 /// Set to nonsignaled state. 00110 int reset (void); 00111 00112 /// Dump the state of an object. 00113 void dump (void) const; 00114 00115 /// Declare the dynamic allocation hooks 00116 ACE_ALLOC_HOOK_DECLARE; 00117 00118 protected: 00119 /// The underlying handle. 00120 ACE_event_t handle_; 00121 00122 /// Keeps track of whether <remove> has been called yet to avoid 00123 /// multiple <remove> calls, e.g., explicitly and implicitly in the 00124 /// destructor. This flag isn't protected by a lock, so make sure 00125 /// that you don't have multiple threads simultaneously calling 00126 /// <remove> on the same object, which is a bad idea anyway... 00127 int removed_; 00128 00129 private: 00130 // = Prevent copying. 00131 ACE_Event (const ACE_Event& event); 00132 const ACE_Event &operator= (const ACE_Event &rhs); 00133 }; 00134 00135 ACE_END_VERSIONED_NAMESPACE_DECL 00136 00137 #if defined (__ACE_INLINE__) 00138 #include "ace/Event.inl" 00139 #endif /* __ACE_INLINE__ */ 00140 00141 #include /**/ "ace/post.h" 00142 #endif /* ACE_EVENT_H */