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