Fixed typos
[ACE_TAO.git] / ACE / ace / Remote_Tokens.h
blob582e63ee449fb00d65b5807b4a57ccd540be3e38
1 // -*- C++ -*-
3 //=============================================================================
4 /**
5 * @file Remote_Tokens.h
7 * @author Douglas C. Schmidt (d.schmidt@vanderbilt.edu)
8 * @author Tim Harrison (harrison@cs.wustl.edu)
9 */
10 //=============================================================================
12 #ifndef ACE_REMOTE_MUTEX_H
13 #define ACE_REMOTE_MUTEX_H
15 #include /**/ "ace/pre.h"
17 #include "ace/INET_Addr.h"
19 #if !defined (ACE_LACKS_PRAGMA_ONCE)
20 # pragma once
21 #endif /* ACE_LACKS_PRAGMA_ONCE */
23 #include "ace/SOCK_Connector.h"
24 #include "ace/SOCK_Stream.h"
25 #include "ace/Synch_Options.h"
26 #include "ace/Local_Tokens.h"
27 #include "ace/Token_Request_Reply.h"
29 #if defined (ACE_HAS_TOKENS_LIBRARY)
31 ACE_BEGIN_VERSIONED_NAMESPACE_DECL
33 /**
34 * @class ACE_Remote_Token_Proxy
36 * @brief Proxy for acquiring, renewing, and releasing a distributed
37 * synchronization token.
39 * The Remote_Token_Proxy class implements the mechanisms for
40 * distributed token operations. It is similar to the
41 * ACE_Token_Proxy.
42 * @todo
43 * Distributed sleep_hooks have not been implemented. <owner_id>
44 * is not implemented.
46 class ACE_Export ACE_Remote_Token_Proxy : public ACE_Token_Proxy
48 public:
49 /// Null construction.
50 ACE_Remote_Token_Proxy (void);
52 /// Death.
53 virtual ~ACE_Remote_Token_Proxy (void);
55 /**
56 * Same as Token_Proxy. @a name is the string uniquely identifying
57 * the token. @a ignore_deadlock can be 1 to disable deadlock
58 * notifications. @a debug prints debug messages.
60 int open (const ACE_TCHAR *name,
61 int ignore_deadlock = 0,
62 int debug = 0);
65 /**
66 * Open a connection with the token server. This only need be used
67 * when the user wishes to explicitly open a connection to check if
68 * the server exists. Connections are stored in the
69 * ACE_Token_Connections singleton as thread-specific data. That
70 * is, every thread has only one connection that is used for all
71 * remote tokens.
73 int initiate_connection (void);
75 /**
76 * Acquire the distributed token. If notify is specified and the
77 * token is already held, the owner is notified. options contains
78 * the timeout value for the acquire call. The timer is kept at the
79 * token server. Asynchronous operations are not supported.
80 * Returns 0 on success, -1 on failure with @c errno == problem.
82 virtual int acquire (int notify = 0,
83 void (*sleep_hook)(void *) = 0,
84 ACE_Synch_Options &options =
85 ACE_Synch_Options::synch);
87 /**
88 * Try to acquire the distributed token. If the token is already
89 * held, the call returns without queuing the caller as a waiter.
90 * Returns 0 on success (the token was acquired), and -1 with
91 * EWOULDBLOCK if the token was already held.
93 virtual int tryacquire (void (*sleep_hook)(void *) = 0);
95 /**
96 * Renew the token by offering to release it if there are any other
97 * waiters, otherwise get the token back immediately. This renew
98 * has the same semantics as ACE_Local_Mutex release. It is
99 * semantically equivalent to release() followed by acquire(), but
100 * it is faster. options contains the timeout value used if renew
101 * blocks. As with acquire, the timer is maintained at the token
102 * server. If there are waiters and requeue_position == -1, the
103 * caller is queued at the rear of the waiter list. Otherwise,
104 * requeue_position specifies the number of waiters to "let by"
105 * before reacquiring the token (effectively, the position in the
106 * waiter list.)
108 virtual int renew (int requeue_position = 0,
109 ACE_Synch_Options &options =
110 ACE_Synch_Options::synch);
113 * Release the distributed token. Similar to ACE_Local_Mutex, if the
114 * caller is not the owner, it is removed from the waiter list (if
115 * applicable.) Returns 0 on success, -1 on failure with @c errno ==
116 * problem.
118 virtual int release (ACE_Synch_Options &options =
119 ACE_Synch_Options::synch);
121 /// Become interface compliant for our guards. This has no
122 /// functionality.
123 virtual int remove (ACE_Synch_Options &options = ACE_Synch_Options::synch);
125 /// Override the default to do nothing.
126 virtual void token_acquired (ACE_TPQ_Entry *);
128 /// The client id of the current token holder
129 virtual const ACE_TCHAR* owner_id (void);
132 * Sets the server address for all instances of ACE_Remote_Token_Proxy
133 * If this isn't called, the environment variable TOKEN_SERVER is
134 * checked for the server address. If that is not specified, all
135 * ACE_Remote_** operations will fail.
137 static void set_server_address (const ACE_INET_Addr &server_address);
139 /// Dump the state of the class.
140 void dump (void) const;
142 protected:
144 /// If shadows report deadlock, go remote anyway
145 int ignore_shadow_deadlock_;
147 /// Perform the request and wait for the reply.
148 int request_reply (ACE_Token_Request &request,
149 ACE_Synch_Options &options);
153 * @class ACE_Remote_Mutex
155 * @brief Proxy for acquiring, renewing, and releasing a distributed
156 * mutex.
158 * This is the remote equivalent to ACE_Local_Mutex. The
159 * Remote_Mutex class offers methods for acquiring, renewing, and
160 * releasing a distributed synchronization mutex. Similar to
161 * ACE_Local_Mutex, ACE_Remote_Token_Proxy offers recursive
162 * acquisition, FIFO waiter ordering, and deadlock detection. It
163 * depends on the Token Server for its distributed synchronization
164 * semantics.
166 class ACE_Export ACE_Remote_Mutex : public ACE_Remote_Token_Proxy
168 public:
169 /// Null creation. Remote_Token_Proxy::open must be called.
170 ACE_Remote_Mutex (void);
172 /// Calls Remote_Token_Proxy::open for you.
173 ACE_Remote_Mutex (const ACE_TCHAR *token_name,
174 int ignore_deadlock = 0,
175 int debug = 0);
177 /// Dump the state of the class.
178 void dump (void) const;
180 /// Return deep copy.
181 virtual ACE_Token_Proxy *clone (void) const;
183 protected:
184 /// Make the correct type of ACE_Tokens.
185 /// This is called by the ACE_Token_Manager.
186 virtual ACE_Tokens *create_token (const ACE_TCHAR *name);
190 * @class ACE_Remote_RLock
192 * @brief Proxy for acquiring, renewing, and releasing a distributed
193 * readers lock.
195 * This is the remote equivalent to ACE_Local_RLock. Multiple
196 * readers can hold the lock simultaneously when no writers have
197 * the lock. Alternatively, when a writer holds the lock, no other
198 * participants (readers or writers) may hold the lock.
199 * ACE_Remote_RLock depends on the ACE Token Server for its
200 * distributed synchronization semantics.
202 class ACE_Export ACE_Remote_RLock : public ACE_Remote_Token_Proxy
204 public:
205 ACE_Remote_RLock (void);
207 ACE_Remote_RLock (const ACE_TCHAR *token_name,
208 int ignore_deadlock = 0,
209 int debug = 0);
211 ACE_Remote_RLock (const ACE_Remote_RLock &mutex);
213 /// Dump the state of the class.
214 void dump (void) const;
216 /// Returns ACE_RW_Token::RLOCK;
217 virtual int type (void) const;
219 /// Return deep copy.
220 virtual ACE_Token_Proxy *clone (void) const;
222 protected:
223 /// Make the correct type of ACE_Tokens. This is called by the Token
224 /// Manager.
225 virtual ACE_Tokens *create_token (const ACE_TCHAR *name);
229 * @class ACE_Remote_WLock
231 * @brief Proxy for acquiring, renewing, and releasing a distributed
232 * writers lock.
234 * Shields applications from details of interacting with the
235 * ACE_Token_Server. The token_name_ is just the string that the
236 * Token Server uses to identify the token. The client_id_ (also
237 * used by the Token Server,) identifies the owner of the token and
238 * is used for deadlock detection.
240 class ACE_Export ACE_Remote_WLock : public ACE_Remote_Token_Proxy
242 public:
243 ACE_Remote_WLock (void);
245 ACE_Remote_WLock (const ACE_TCHAR *token_name,
246 int ignore_deadlock = 0,
247 int debug = 0);
249 ACE_Remote_WLock (const ACE_Remote_WLock &mutex);
251 /// Dump the state of the class.
252 void dump (void) const;
254 /// Returns ACE_RW_Token::WLOCK;
255 virtual int type (void) const;
257 /// Return deep copy.
258 virtual ACE_Token_Proxy *clone (void) const;
260 protected:
261 /// Make the correct type of ACE_Tokens. This is called by the Token
262 /// Manager.
263 virtual ACE_Tokens *create_token (const ACE_TCHAR *name);
267 * @class ACE_TSS_Connection
269 * @brief Class for providing a connection per thread.
271 * ACE_TSS_Connection provides a single access point for all
272 * threads to access thread-specific connections. This prevents
273 * resource-sharing problems such as thread serialization.
275 class ACE_Export ACE_TSS_Connection : public ACE_TSS<ACE_SOCK_Stream>
277 public:
278 // Necessary to make some compilers work...
279 ACE_TSS_Connection (void);
280 ~ACE_TSS_Connection (void);
282 /// Retrieve the thread's connection
283 ACE_SOCK_Stream *get_connection (void);
285 /// Factory Method that creates a new SOCK Stream.
286 virtual ACE_SOCK_Stream *make_TSS_TYPE (void) const;
288 /// Inheritance and operator overloading don't mix. Redefine this
289 /// from ACE_TSS so that we can use it.
290 operator ACE_SOCK_Stream *(void);
292 /// Set the server address.
293 static void set_server_address (const ACE_INET_Addr &server_address);
295 /// Dump the state of the class.
296 void dump (void) const;
298 protected:
299 /// The address of the Token Server used by all instances of
300 /// Token_Proxy.
301 static ACE_INET_Addr server_address_;
303 private:
304 /// Private: should not be used
305 ACE_TSS_Connection (const ACE_TSS_Connection &);
306 void operator= (const ACE_TSS_Connection &);
309 ACE_END_VERSIONED_NAMESPACE_DECL
311 #endif /* ACE_HAS_TOKENS_LIBRARY */
313 #if defined (__ACE_INLINE__)
314 #include "ace/Remote_Tokens.inl"
315 #endif /* __ACE_INLINE__ */
317 #include /**/ "ace/post.h"
319 #endif /* ACE_REMOTE_TOKEN_H */