Merge pull request #2309 from mitza-oci/warnings
[ACE_TAO.git] / TAO / tao / RTCORBA / RT_Mutex.cpp
blob5bc6f820f21be939d9a0105a568e6c1b014c4ddb
1 #include "tao/RTCORBA/RT_Mutex.h"
3 #if defined (TAO_HAS_CORBA_MESSAGING) && TAO_HAS_CORBA_MESSAGING != 0
5 #include "tao/RTCORBA/RT_ORB.h"
6 #include "tao/SystemException.h"
7 #include "ace/OS_NS_sys_time.h"
9 TAO_BEGIN_VERSIONED_NAMESPACE_DECL
11 TAO_RT_Mutex::~TAO_RT_Mutex ()
15 void
16 TAO_RT_Mutex::lock ()
18 if (this->mu_.acquire () != 0)
19 throw ::CORBA::INTERNAL ();
22 void
23 TAO_RT_Mutex::unlock ()
25 if (this->mu_.release () != 0)
26 throw ::CORBA::INTERNAL ();
29 CORBA::Boolean
30 TAO_RT_Mutex::try_lock (TimeBase::TimeT wait_time)
32 int result;
34 if (wait_time == 0)
35 // No wait.
36 result = this->mu_.tryacquire ();
37 else
39 // Wait for the specified amount of time before giving up.
40 // (wait_time units are 100ns. See TimeBase.pidl)
41 TimeBase::TimeT seconds = wait_time / 10000000u;
42 TimeBase::TimeT microseconds = (wait_time % 10000000u) / 10;
44 ACE_Time_Value relative_time (ACE_U64_TO_U32 (seconds),
45 ACE_U64_TO_U32 (microseconds));
47 ACE_Time_Value absolute_time =
48 relative_time +
49 ACE_OS::gettimeofday ();
51 result = this->mu_.acquire (absolute_time);
54 if (result == 0)
55 return 1;
56 else if (result == -1 &&
57 (errno == ETIME ||
58 errno == EBUSY))
59 return 0;
60 else
61 // Some really bad error.
62 throw ::CORBA::INTERNAL ();
65 const char *
66 TAO_RT_Mutex::name () const
68 return 0;
71 ///////////////////////////////////////////////////////////////////////////////
72 #if (TAO_HAS_NAMED_RT_MUTEXES == 1)
73 TAO_Named_RT_Mutex::TAO_Named_RT_Mutex (const char *name)
74 : name_ (name)
78 const char *
79 TAO_Named_RT_Mutex::name () const
81 return this->name_.c_str ();
83 #endif /* TAO_HAS_NAMED_RT_MUTEXES == 1 */
85 ///////////////////////////////////////////////////////////////////////////////
87 TAO_END_VERSIONED_NAMESPACE_DECL
89 #endif /* TAO_HAS_CORBA_MESSAGING && TAO_HAS_CORBA_MESSAGING != 0 */