summaryrefslogtreecommitdiff
path: root/ACE/ace/Condition_Thread_Mutex.cpp
blob: 59a8a7f4de6e5bd55dc7c90457df1a5c250ae442 (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
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
/* -*- C++ -*- */
/**
 * @file Condition_Thread_Mutex.cpp
 *
 * @author Douglas C. Schmidt <d.schmidt@vanderbilt.edu>
 */

#include "ace/Condition_Thread_Mutex.h"

#if defined (ACE_HAS_THREADS)

#if !defined (__ACE_INLINE__)
#include "ace/Condition_Thread_Mutex.inl"
#endif /* __ACE_INLINE__ */

#include "ace/Log_Category.h"

ACE_BEGIN_VERSIONED_NAMESPACE_DECL

ACE_ALLOC_HOOK_DEFINE(ACE_Condition<ACE_Thread_Mutex>)

void
ACE_Condition<ACE_Thread_Mutex>::dump () const
{
#if defined (ACE_HAS_DUMP)
// ACE_TRACE ("ACE_Condition<ACE_Thread_Mutex>::dump");

  ACELIB_DEBUG ((LM_DEBUG, ACE_BEGIN_DUMP, this));
  ACELIB_DEBUG ((LM_DEBUG, ACE_TEXT ("\n")));
#if defined (ACE_WIN32)
  ACELIB_DEBUG ((LM_DEBUG,
              ACE_TEXT ("waiters = %d\n"),
              this->cond_.waiters ()));
#endif /* ACE_WIN32 */
  ACELIB_DEBUG ((LM_DEBUG, ACE_END_DUMP));
#endif /* ACE_HAS_DUMP */
}

ACE_Condition<ACE_Thread_Mutex>::ACE_Condition (ACE_Thread_Mutex &m,
                                                const ACE_TCHAR *name,
                                                void *arg)
  : mutex_ (m),
    removed_ (false)
{
// ACE_TRACE ("ACE_Condition<ACE_Thread_Mutex>::ACE_Condition<ACE_Thread_Mutex>");
  if (ACE_OS::cond_init (&this->cond_,
                         (short) USYNC_THREAD,
                         name,
                         arg) != 0)
    ACELIB_ERROR ((LM_ERROR,
                ACE_TEXT ("%p\n"),
                ACE_TEXT ("ACE_Condition<ACE_Thread_Mutex>::ACE_Condition<ACE_Thread_Mutex>")));
}

ACE_Condition<ACE_Thread_Mutex>::ACE_Condition (ACE_Thread_Mutex &m,
                                                const ACE_Condition_Attributes &attributes,
                                                const ACE_TCHAR *name,
                                                void *arg)
  : mutex_ (m),
    removed_ (false)
{
// ACE_TRACE ("ACE_Condition<ACE_Thread_Mutex>::ACE_Condition<ACE_Thread_Mutex>");
  if (ACE_OS::cond_init (&this->cond_,
                         const_cast<ACE_condattr_t &> (attributes.attributes ()),
                         name, arg) != 0)
    ACELIB_ERROR ((LM_ERROR, ACE_TEXT ("%p\n"),
                ACE_TEXT ("ACE_Condition<ACE_Thread_Mutex>::ACE_Condition<ACE_Thread_Mutex>")));
}

ACE_Condition<ACE_Thread_Mutex>::~ACE_Condition ()
{
// ACE_TRACE ("ACE_Condition<ACE_Thread_Mutex>::~ACE_Condition<ACE_Thread_Mutex>");
  this->remove ();
}

// Peform an "alertable" timed wait.  If the argument <abstime> == 0
// then we do a regular <cond_wait>, else we do a timed wait for up to
// <abstime> using the <cond_timedwait> function.

int
ACE_Condition<ACE_Thread_Mutex>::wait ()
{
// ACE_TRACE ("ACE_Condition<ACE_Thread_Mutex>::wait");
  return ACE_OS::cond_wait (&this->cond_, &this->mutex_.lock ());
}

int
ACE_Condition<ACE_Thread_Mutex>::wait (ACE_Thread_Mutex &mutex,
                                  const ACE_Time_Value *abstime)
{
// ACE_TRACE ("ACE_Condition<ACE_Thread_Mutex>::wait");
  return ACE_OS::cond_timedwait (&this->cond_,
                                 &mutex.lock (),
                                 const_cast <ACE_Time_Value *> (abstime));
}

int
ACE_Condition<ACE_Thread_Mutex>::wait (const ACE_Time_Value *abstime)
{
// ACE_TRACE ("ACE_Condition<ACE_Thread_Mutex>::wait");
  return this->wait (this->mutex_, abstime);
}

int
ACE_Condition<ACE_Thread_Mutex>::signal ()
{
// ACE_TRACE ("ACE_Condition<ACE_Thread_Mutex>::signal");
  return ACE_OS::cond_signal (&this->cond_);
}

int
ACE_Condition<ACE_Thread_Mutex>::broadcast ()
{
// ACE_TRACE ("ACE_Condition<ACE_Thread_Mutex>::broadcast");
  return ACE_OS::cond_broadcast (&this->cond_);
}

ACE_END_VERSIONED_NAMESPACE_DECL

#endif /* ACE_HAS_THREADS */