diff options
author | dhinton <dhinton@ae88bc3d-4319-0410-8dbf-d08b4c9d3795> | 2003-08-04 03:53:54 +0000 |
---|---|---|
committer | dhinton <dhinton@ae88bc3d-4319-0410-8dbf-d08b4c9d3795> | 2003-08-04 03:53:54 +0000 |
commit | 937a0506cb1c0980eab5bcfdf266139e1c93e80c (patch) | |
tree | 12103be26b2e9b0cd1869d7fd72a1f8a8ec362e6 /ace/Reverse_Lock_T.h | |
parent | 868bea2cbe0807f9db59c1997ede86af27fbc8e3 (diff) | |
download | ATCD-937a0506cb1c0980eab5bcfdf266139e1c93e80c.tar.gz |
ChangeLogTag:Mon Aug 4 03:26:30 UTC 2003 Don Hinton <dhinton@dresystems.com>
Diffstat (limited to 'ace/Reverse_Lock_T.h')
-rw-r--r-- | ace/Reverse_Lock_T.h | 136 |
1 files changed, 136 insertions, 0 deletions
diff --git a/ace/Reverse_Lock_T.h b/ace/Reverse_Lock_T.h new file mode 100644 index 00000000000..29f23b08c08 --- /dev/null +++ b/ace/Reverse_Lock_T.h @@ -0,0 +1,136 @@ +// -*- C++ -*- + +//========================================================================== +/** + * @file Reverse_Lock_T.h + * + * $Id$ + * + * Moved from Synch.h. + * + * @author Douglas C. Schmidt <schmidt@cs.wustl.edu> + */ +//========================================================================== + +#ifndef ACE_REVERSE_LOCK_T_H +#define ACE_REVERSE_LOCK_T_H +#include /**/ "ace/pre.h" + +#include "ace/Lock.h" + +#if !defined (ACE_LACKS_PRAGMA_ONCE) +# pragma once +#endif /* ACE_LACKS_PRAGMA_ONCE */ + +/** + * @class ACE_Acquire_Method + * + * @brief An enum class. + * + * These enums should have been inside the reverse lock class, but + * some lame compilers cannot handle enums inside template classes. + * + * The METHOD_TYPE is used to indicate which acquire() method will be + * called on the real lock when the release() method is called on the + * reverse lock. REGULAR indicated the acquire() method, READ + * indicates the acquire_read() method, and WRITE indicates the + * acquire_write() method. Note that the try_*() methods are not + * represented here because we have to make sure that the release() + * method on the reverse lock acquires a lock on the real lock. + **/ +class ACE_Acquire_Method +{ +public: + enum METHOD_TYPE + { + ACE_REGULAR, + ACE_READ, + ACE_WRITE + }; +}; + +/** + * @class ACE_Reverse_Lock + * + * @brief A reverse (or anti) lock. + * + * This is an interesting adapter class that changes a lock into + * a reverse lock, i.e., <acquire> on this class calls <release> + * on the lock, and <release> on this class calls <acquire> on + * the lock. + * One motivation for this class is when we temporarily want to + * release a lock (which we have already acquired) but then + * reacquire it soon after. An alternative design would be to + * add a Anti_Guard or Reverse_Guard class which would <release> + * on construction and <acquire> destruction. However, there + * are *many* varieties of the Guard class and this design + * choice would lead to at least 6 new classes. One new + * ACE_Reverse_Lock class seemed more reasonable. + */ +template <class ACE_LOCKING_MECHANISM> +class ACE_Reverse_Lock : public ACE_Lock +{ +public: + + typedef ACE_LOCKING_MECHANISM ACE_LOCK; + + // = Initialization/Finalization methods. + + /// Constructor. All locking requests will be forwarded to <lock>. + ACE_Reverse_Lock (ACE_LOCKING_MECHANISM &lock, + ACE_Acquire_Method::METHOD_TYPE acquire_method = ACE_Acquire_Method::ACE_REGULAR); + + /// Destructor. If <lock_> was not passed in by the user, it will be + /// deleted. + virtual ~ACE_Reverse_Lock (void); + + // = Lock accessors. + /// Release the lock. + virtual int acquire (void); + + /// Release the lock. + virtual int tryacquire (void); + + /// Acquire the lock. + virtual int release (void); + + /// Release the lock. + virtual int acquire_read (void); + + /// Release the lock. + virtual int acquire_write (void); + + /// Release the lock. + virtual int tryacquire_read (void); + + /// Release the lock. + virtual int tryacquire_write (void); + + /// Release the lock. + virtual int tryacquire_write_upgrade (void); + + /// Explicitly destroy the lock. + virtual int remove (void); + +private: + /// The concrete locking mechanism that all the methods delegate to. + ACE_LOCKING_MECHANISM &lock_; + + /// This indicates what kind of acquire method will be called. + ACE_Acquire_Method::METHOD_TYPE acquire_method_; +}; + +#if defined (__ACE_INLINE__) +#include "ace/Reverse_Lock_T.inl" +#endif /* __ACE_INLINE__ */ + +#if defined (ACE_TEMPLATES_REQUIRE_SOURCE) +#include "ace/Reverse_Lock_T.cpp" +#endif /* ACE_TEMPLATES_REQUIRE_SOURCE */ + +#if defined (ACE_TEMPLATES_REQUIRE_PRAGMA) +#pragma implementation ("Reverse_Lock_T.cpp") +#endif /* ACE_TEMPLATES_REQUIRE_PRAGMA */ + +#include /**/ "ace/post.h" +#endif /* ACE_REVERSE_LOCK_T_H */ |