Main Page   Class Hierarchy   Alphabetical List   Compound List   File List   Compound Members   File Members   Related Pages  

Test_and_Set.h

Go to the documentation of this file.
00001 
00002 //=============================================================================
00003 /**
00004  *  @file   Test_and_Set.h
00005  *
00006  *  $Id: Test_and_Set.h,v 1.1.1.1 2001/12/04 14:33:10 chad Exp $
00007  *
00008  *  @author Priyanka Gontla <pgontla@ece.uci.edu>
00009  */
00010 //=============================================================================
00011 
00012 
00013 #ifndef ACE_TEST_AND_SET_H
00014 #define ACE_TEST_AND_SET_H
00015 
00016 #include "ace/pre.h"
00017 #include "ace/Event_Handler.h"
00018 
00019 #if !defined (ACE_LACKS_PRAGMA_ONCE)
00020 # pragma once
00021 #endif /* ACE_LACKS_PRAGMA_ONCE */
00022 
00023 /**
00024  * @class ACE_Test_and_Set
00025  *
00026  * @brief Implements the classic ``test and set'' operation.
00027  *
00028  *
00029  *     This class keeps track of the status of <is_set_>, which can
00030  *     be set based on various events (such as receipt of a
00031  *     signal).  This class is derived from <ACE_Event_Handler> so
00032  *     that it can be "signaled" by a Reactor when a signal occurs.
00033  *     We assume that <TYPE> is a data type that can be assigned the
00034  *     value 0 or 1.
00035  */
00036 template <class ACE_LOCK, class TYPE>
00037 class ACE_Test_and_Set : public ACE_Event_Handler
00038 {
00039 public:
00040   ACE_Test_and_Set (TYPE initial_value = 0);
00041 
00042   /// Returns true if we are set, else false.
00043   TYPE is_set (void) const;
00044 
00045   /// Sets the <is_set_> status, returning the original value of
00046   /// <is_set_>.
00047   TYPE set (TYPE);
00048 
00049   /// Called when object is signaled by OS (either via UNIX signals or
00050   /// when a Win32 object becomes signaled).
00051   virtual int handle_signal (int signum,
00052                              siginfo_t * = 0,
00053                              ucontext_t * = 0);
00054 
00055 private:
00056   /// Keeps track of our state.
00057   TYPE is_set_;
00058 
00059   /// Protect the state from race conditions.
00060   ACE_LOCK lock_;
00061 };
00062 
00063 #if defined (__ACE_INLINE__)
00064 #include "ace/Test_and_Set.i"
00065 #endif /* __ACE_INLINE__ */
00066 
00067 #if defined (ACE_TEMPLATES_REQUIRE_SOURCE)
00068 #include "ace/Test_and_Set.cpp"
00069 #endif /* ACE_TEMPLATES_REQUIRE_SOURCE */
00070 
00071 #if defined (ACE_TEMPLATES_REQUIRE_PRAGMA)
00072 #pragma implementation ("Test_and_Set.cpp")
00073 #endif /* ACE_TEMPLATES_REQUIRE_PRAGMA */
00074 
00075 #include "ace/post.h"
00076 #endif /* ACE_TEST_AND_SET_H */

Generated on Mon Jun 16 11:21:44 2003 for ACE by doxygen1.2.14 written by Dimitri van Heesch, © 1997-2002