Test_and_Set.h

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

Generated on Thu Nov 9 09:42:06 2006 for ACE by doxygen 1.3.6