2 //=============================================================================
8 //=============================================================================
10 #include "ace/Get_Opt.h"
11 #include "ace/Local_Tokens.h"
12 #include "ace/Remote_Tokens.h"
13 #include "ace/Thread.h"
14 #include "ace/Thread_Manager.h"
16 #if defined (ACE_HAS_THREADS) && defined (ACE_HAS_THREADS_LIBRARY)
18 static ACE_Token_Proxy
*mutex
;
19 static int remote_mutexes
= 0;
20 static const char *server_host
= ACE_DEFAULT_SERVER_HOST
;
21 static int server_port
= ACE_DEFAULT_SERVER_PORT
;
22 static int iterations
= 100;
23 static int spawn_count
= 2;
28 int count
= iterations
;
29 // test recursive acquisition of a global proxy
32 if (mutex
->acquire () == -1)
34 ACE_ERROR ((LM_ERROR
, "(%t) %p acquire failed\n","test_mutex"));
39 if (mutex
->renew () == -1)
41 ACE_ERROR ((LM_ERROR
, "(%t) %p renew failed\n","test_mutex"));
45 if (mutex
->release () == -1)
47 ACE_ERROR ((LM_ERROR
, "(%t) %p release failed\n","test_mutex"));
58 parse_args (int argc
, ACE_TCHAR
*argv
[])
60 ACE_LOG_MSG
->open (argv
[0]);
62 ACE_Get_Opt
get_opt (argc
, argv
, ACE_TEXT("t:uh:p:n:"), 1);
64 for (int c
; (c
= get_opt ()) != -1; )
69 spawn_count
= ACE_OS::atoi (get_opt
.opt_arg ());
71 case 'h': // specify the host machine on which the server is running
72 server_host
= get_opt
.opt_arg ();
75 case 'p': // specify the port on which the server is running
76 server_port
= ACE_OS::atoi (get_opt
.opt_arg ());
79 case 'n': // specify the port on which the server is running
80 iterations
= ACE_OS::atoi (get_opt
.opt_arg ());
84 ACE_ERROR_RETURN ((LM_ERROR
,
86 "[-h <remote host>]\n"
87 "[-p <remote port>]\n"
90 "[-h <remote host>]\n"
91 "[-p <remote port>]\n", 1), -1);
100 ACE_TMAIN (int argc
, ACE_TCHAR
*argv
[])
102 ACE_Thread_Manager thread_mgr
;
104 if (parse_args (argc
, argv
) == -1)
109 ACE_Remote_Mutex::set_server_address (ACE_INET_Addr (server_port
, server_host
));
110 mutex
= new ACE_Remote_Mutex ("Remote TOKEN", 0, 1);
114 mutex
= new ACE_Local_Mutex ("Local TOKEN", 0, 1);
117 if (thread_mgr
.spawn_n (spawn_count
,
118 ACE_THR_FUNC (run_test
),
121 ACE_ERROR_RETURN ((LM_DEBUG
, "%p\n", "spawn"), -1);
128 int ACE_TMAIN (int, ACE_TCHAR
*[])
130 ACE_ERROR_RETURN ((LM_ERROR
, "you must have threads to run this test program\n"), -1);
132 #endif /* ACE_HAS_THREADS */