Event.h

Go to the documentation of this file.
00001 // -*- C++ -*-
00002 
00003 //==========================================================================
00004 /**
00005  *  @file    Event.h
00006  *
00007  *  $Id: Event.h 77828 2007-03-28 10:47:04Z johnnyw $
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              LPSECURITY_ATTRIBUTES sa = 0);
00049 
00050   /// Implicitly destroy the event variable.
00051   ~ACE_Event (void);
00052 
00053   /**
00054    * Explicitly destroy the event variable.  Note that only one thread
00055    * should call this method since it doesn't protect against race
00056    * conditions.
00057    */
00058   int remove (void);
00059 
00060   /// Underlying handle to event.
00061   ACE_event_t handle (void) const;
00062 
00063   /**
00064    * Set the underlying handle to event. Note that this method assumes
00065    * ownership of the <handle> and will close it down in <remove>.  If
00066    * you want the <handle> to stay open when <remove> is called make
00067    * sure to call <dup> on the <handle> before closing it.  You are
00068    * responsible for the closing the existing <handle> before
00069    * overwriting it.
00070    */
00071   void handle (ACE_event_t new_handle);
00072 
00073   /**
00074    * if MANUAL reset
00075    *    sleep till the event becomes signaled
00076    *    event remains signaled after wait() completes.
00077    * else AUTO reset
00078    *    sleep till the event becomes signaled
00079    *    event resets wait() completes.
00080    */
00081   int wait (void);
00082 
00083   /// Same as wait() above, but this one can be timed
00084   /// @a abstime is absolute time-of-day if if @a use_absolute_time
00085   /// is non-0, else it is relative time.
00086   int wait (const ACE_Time_Value *abstime,
00087             int use_absolute_time = 1);
00088 
00089   /**
00090    * if MANUAL reset
00091    *    wake up all waiting threads
00092    *    set to signaled state
00093    * else AUTO reset
00094    *    if no thread is waiting, set to signaled state
00095    *    if thread(s) are waiting, wake up one waiting thread and
00096    *    reset event
00097    */
00098   int signal (void);
00099 
00100   /**
00101    * if MANUAL reset
00102    *    wakeup all waiting threads and
00103    *    reset event
00104    * else AUTO reset
00105    *    wakeup one waiting thread (if present) and
00106    *    reset event
00107    */
00108   int pulse (void);
00109 
00110   /// Set to nonsignaled state.
00111   int reset (void);
00112 
00113   /// Dump the state of an object.
00114   void dump (void) const;
00115 
00116   /// Declare the dynamic allocation hooks
00117   ACE_ALLOC_HOOK_DECLARE;
00118 
00119 protected:
00120   /// The underlying handle.
00121   ACE_event_t handle_;
00122 
00123   /// Keeps track of whether <remove> has been called yet to avoid
00124   /// multiple <remove> calls, e.g., explicitly and implicitly in the
00125   /// destructor.  This flag isn't protected by a lock, so make sure
00126   /// that you don't have multiple threads simultaneously calling
00127   /// <remove> on the same object, which is a bad idea anyway...
00128   bool removed_;
00129 
00130 private:
00131   // = Prevent copying.
00132   ACE_Event (const ACE_Event& event);
00133   const ACE_Event &operator= (const ACE_Event &rhs);
00134 };
00135 
00136 ACE_END_VERSIONED_NAMESPACE_DECL
00137 
00138 #if defined (__ACE_INLINE__)
00139 #include "ace/Event.inl"
00140 #endif /* __ACE_INLINE__ */
00141 
00142 #include /**/ "ace/post.h"
00143 #endif /* ACE_EVENT_H */

Generated on Sun Jan 27 12:05:25 2008 for ACE by doxygen 1.3.6