summaryrefslogtreecommitdiff
path: root/TAO/tao/RT_Mutex.cpp
blob: 29433487e8cfe5f51cb71ee7ee5ff7ff9cf02c69 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
// $Id$
#include "tao/RT_Mutex.h"
#include "tao/RT_ORB.h"

ACE_RCSID(TAO, RT_Mutex, "$Id$")

#if (TAO_HAS_RT_CORBA == 1)

TAO_RT_Mutex::TAO_RT_Mutex (void)
{
}

TAO_RT_Mutex::~TAO_RT_Mutex (void)
{
}

void
TAO_RT_Mutex::lock (CORBA::Environment &ACE_TRY_ENV)
  ACE_THROW_SPEC ((CORBA::SystemException))
{
  if (this->mu_.acquire () != 0)
    ACE_THROW (CORBA::INTERNAL ());
}

void
TAO_RT_Mutex::unlock (CORBA::Environment &ACE_TRY_ENV)
  ACE_THROW_SPEC ((CORBA::SystemException))
{
  if (this->mu_.release () != 0)
    ACE_THROW (CORBA::INTERNAL ());
}

CORBA::Boolean
TAO_RT_Mutex::try_lock (TimeBase::TimeT wait_time,
                        CORBA::Environment &ACE_TRY_ENV)
  ACE_THROW_SPEC ((CORBA::SystemException))
{
  int result;

  if (wait_time == 0)
    {
      // No wait.
      result = this->mu_.tryacquire ();
    }
  else
    {
      // Wait for the specified amount of time before giving up.
      // (wait_time units are 100ns.  See TimeBase.pidl)
      TimeBase::TimeT seconds = wait_time / 10000000u;
      TimeBase::TimeT microseconds = (wait_time % 10000000u) / 10;

      ACE_Time_Value relative_time (ACE_U64_TO_U32 (seconds),
                                    ACE_U64_TO_U32 (microseconds));

      ACE_Time_Value absolute_time =
        relative_time +
        ACE_OS::gettimeofday ();

      result = this->mu_.acquire (absolute_time);
    }

  // Check result.
  if (result == 0 )
    return 1;
  else
  if (result == -1
      && (errno == EBUSY || errno == ETIMEDOUT))
    return 0;
  else
    {
      // Some really bad error.
      ACE_THROW_RETURN (CORBA::INTERNAL (), 0);
    }
}

const char *
TAO_RT_Mutex::name (void) const
{
  return 0;
}

////////////////////////////////////////////////////////////////////////////////
#if (TAO_HAS_NAMED_RT_MUTEXES == 1)
TAO_Named_RT_Mutex::TAO_Named_RT_Mutex (const char *name)
  : name_ (name)
{
}

const char *
TAO_Named_RT_Mutex::name (void) const
{
  return this->name_.c_str ();
}
#endif /* TAO_HAS_NAMED_RT_MUTEXES == 1 */

#endif /* TAO_HAS_RT_CORBA == 1 */

////////////////////////////////////////////////////////////////////////////////

#if defined (ACE_HAS_EXPLICIT_TEMPLATE_INSTANTIATION)

#elif defined(ACE_HAS_TEMPLATE_INSTANTIATION_PRAGMA)

#endif /* ACE_HAS_EXPLICIT_TEMPLATE_INSTANTIATION */