RT_Mutex.cpp

Go to the documentation of this file.
00001 // RT_Mutex.cpp,v 1.11 2006/03/10 07:19:16 jtc Exp
00002 #include "tao/RTCORBA/RT_Mutex.h"
00003 
00004 #if defined (TAO_HAS_CORBA_MESSAGING) && TAO_HAS_CORBA_MESSAGING != 0
00005 
00006 #include "tao/RTCORBA/RT_ORB.h"
00007 #include "ace/OS_NS_sys_time.h"
00008 
00009 ACE_RCSID(RTCORBA,
00010           RT_Mutex,
00011           "RT_Mutex.cpp,v 1.11 2006/03/10 07:19:16 jtc Exp")
00012 
00013 TAO_BEGIN_VERSIONED_NAMESPACE_DECL
00014 
00015 TAO_RT_Mutex::~TAO_RT_Mutex (void)
00016 {
00017 }
00018 
00019 void
00020 TAO_RT_Mutex::lock (ACE_ENV_SINGLE_ARG_DECL)
00021   ACE_THROW_SPEC ((CORBA::SystemException))
00022 {
00023   if (this->mu_.acquire () != 0)
00024     ACE_THROW (CORBA::INTERNAL ());
00025 }
00026 
00027 void
00028 TAO_RT_Mutex::unlock (ACE_ENV_SINGLE_ARG_DECL)
00029   ACE_THROW_SPEC ((CORBA::SystemException))
00030 {
00031   if (this->mu_.release () != 0)
00032     ACE_THROW (CORBA::INTERNAL ());
00033 }
00034 
00035 CORBA::Boolean
00036 TAO_RT_Mutex::try_lock (TimeBase::TimeT wait_time
00037                         ACE_ENV_ARG_DECL)
00038   ACE_THROW_SPEC ((CORBA::SystemException))
00039 {
00040   int result;
00041 
00042   if (wait_time == 0)
00043     // No wait.
00044     result = this->mu_.tryacquire ();
00045   else
00046     {
00047       // Wait for the specified amount of time before giving up.
00048       // (wait_time units are 100ns.  See TimeBase.pidl)
00049       TimeBase::TimeT seconds = wait_time / 10000000u;
00050       TimeBase::TimeT microseconds = (wait_time % 10000000u) / 10;
00051 
00052       ACE_Time_Value relative_time (ACE_U64_TO_U32 (seconds),
00053                                     ACE_U64_TO_U32 (microseconds));
00054 
00055       ACE_Time_Value absolute_time =
00056         relative_time +
00057         ACE_OS::gettimeofday ();
00058 
00059       result = this->mu_.acquire (absolute_time);
00060     }
00061 
00062   if (result == 0)
00063     return 1;
00064   else if (result == -1 &&
00065            (errno == ETIME ||
00066             errno == EBUSY))
00067     return 0;
00068   else
00069     // Some really bad error.
00070     ACE_THROW_RETURN (CORBA::INTERNAL (), 0);
00071 }
00072 
00073 const char *
00074 TAO_RT_Mutex::name (void) const
00075 {
00076   return 0;
00077 }
00078 
00079 ///////////////////////////////////////////////////////////////////////////////
00080 #if (TAO_HAS_NAMED_RT_MUTEXES == 1)
00081 TAO_Named_RT_Mutex::TAO_Named_RT_Mutex (const char *name)
00082   : name_ (name)
00083 {
00084 }
00085 
00086 const char *
00087 TAO_Named_RT_Mutex::name (void) const
00088 {
00089   return this->name_.c_str ();
00090 }
00091 #endif /* TAO_HAS_NAMED_RT_MUTEXES == 1 */
00092 
00093 ///////////////////////////////////////////////////////////////////////////////
00094 
00095 TAO_END_VERSIONED_NAMESPACE_DECL
00096 
00097 #endif /* TAO_HAS_CORBA_MESSAGING && TAO_HAS_CORBA_MESSAGING != 0 */

Generated on Thu Nov 9 12:58:00 2006 for TAO_RTCORBA by doxygen 1.3.6