summaryrefslogtreecommitdiff
path: root/ace/Token.inl
blob: d375789fbd1e6e50b59151fd9d57396f6f4808f4 (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
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
// -*- C++ -*-
//
// $Id$

#include "ace/config-macros.h"

#if defined (ACE_HAS_THREADS)

#include "ace/Guard_T.h"
#include "ace/Time_Value.h"

ACE_BEGIN_VERSIONED_NAMESPACE_DECL

ACE_INLINE int
ACE_Token::queueing_strategy (void)
{
  return this->queueing_strategy_;
}

ACE_INLINE void
ACE_Token::queueing_strategy (int queueing_strategy)
{
  this->queueing_strategy_ = queueing_strategy == -1 ? -1 : 0;
}

ACE_INLINE int
ACE_Token::remove (void)
{
  ACE_TRACE ("ACE_Token::remove");
  // Don't have an implementation for this yet...
  ACE_NOTSUP_RETURN (-1);
}

ACE_INLINE int
ACE_Token::tryacquire (void)
{
  ACE_TRACE ("ACE_Token::tryacquire");
  return this->shared_acquire
    (0, 0, (ACE_Time_Value *) &ACE_Time_Value::zero, ACE_Token::WRITE_TOKEN);
}

ACE_INLINE int
ACE_Token::waiters (void)
{
  ACE_TRACE ("ACE_Token::waiters");
  ACE_GUARD_RETURN (ACE_Thread_Mutex, ace_mon, this->lock_, -1);

  int const ret = this->waiters_;
  return ret;
}

ACE_INLINE ACE_thread_t
ACE_Token::current_owner (void)
{
  ACE_TRACE ("ACE_Token::current_owner");
  ACE_GUARD_RETURN (ACE_Thread_Mutex, ace_mon, this->lock_, this->owner_);

  return this->owner_;
}

ACE_INLINE int
ACE_Token::acquire_read (void)
{
  ACE_TRACE ("ACE_Token::acquire_read");
  return this->shared_acquire
    (0, 0, 0, ACE_Token::READ_TOKEN);
}

ACE_INLINE int
ACE_Token::acquire_write (void)
{
  ACE_TRACE ("ACE_Token::acquire_write");
  return this->shared_acquire
    (0, 0, 0, ACE_Token::WRITE_TOKEN);
}

ACE_INLINE int
ACE_Token::tryacquire_read (void)
{
  ACE_TRACE ("ACE_Token::tryacquire_read");
  return this->shared_acquire
    (0, 0, (ACE_Time_Value *) &ACE_Time_Value::zero, ACE_Token::READ_TOKEN);
}

ACE_INLINE int
ACE_Token::acquire_read (void (*sleep_hook_func)(void *),
                         void *arg,
                         ACE_Time_Value *timeout)
{
  ACE_TRACE ("ACE_Token::acquire_read");
  return this->shared_acquire (sleep_hook_func, arg, timeout, ACE_Token::READ_TOKEN);
}

ACE_INLINE int
ACE_Token::tryacquire_write (void)
{
  ACE_TRACE ("ACE_Token::tryacquire_write");
  return this->shared_acquire
    (0, 0, (ACE_Time_Value *) &ACE_Time_Value::zero, ACE_Token::WRITE_TOKEN);
}

ACE_INLINE int
ACE_Token::tryacquire_write_upgrade (void)
{
  ACE_TRACE ("ACE_Token::tryacquire_write_upgrade");
  return 0;
}

ACE_INLINE int
ACE_Token::acquire_write (void (*sleep_hook_func)(void *),
                          void *arg,
                          ACE_Time_Value *timeout)
{
  ACE_TRACE ("ACE_Token::acquire_write");
  return this->shared_acquire (sleep_hook_func, arg, timeout, ACE_Token::WRITE_TOKEN);
}

ACE_INLINE int
ACE_Token::ACE_Token_Queue_Entry::wait (ACE_Time_Value *timeout, ACE_Thread_Mutex &lock)
{
#if defined (ACE_TOKEN_USES_SEMAPHORE)
  lock.release ();
  int const retv = (timeout == 0 ?
                    this->cv_.acquire () :
                    this->cv_.acquire (*timeout));
  lock.acquire ();
  return retv;
#else
  ACE_UNUSED_ARG (lock);
  return this->cv_.wait (timeout);
#endif /* ACE_TOKEN_USES_SEMAPHORE */
}

ACE_INLINE int
ACE_Token::ACE_Token_Queue_Entry::signal (void)
{
  return
#if defined (ACE_TOKEN_USES_SEMAPHORE)
    this->cv_.release ();
#else
    this->cv_.signal ();
#endif /* ACE_TOKEN_USES_SEMAPHORE */
}

ACE_END_VERSIONED_NAMESPACE_DECL

#endif /* ACE_HAS_THREADS */

/*****************************************************************************/

ACE_BEGIN_VERSIONED_NAMESPACE_DECL

ACE_INLINE int
ACE_Noop_Token::queueing_strategy (void)
{
  return -1;
}

ACE_INLINE void
ACE_Noop_Token::queueing_strategy (int /* queueing_strategy */)
{
}

ACE_INLINE int
ACE_Noop_Token::renew (int, ACE_Time_Value *)
{
  return 0;
}

ACE_INLINE void
ACE_Noop_Token::dump (void) const
{
}

ACE_END_VERSIONED_NAMESPACE_DECL