1 #include "ace/OS_main.h"
2 #include "ace/Process_Semaphore.h"
3 #include "ace/Get_Opt.h"
4 #include "ace/Log_Msg.h"
5 #include "ace/OS_NS_stdlib.h"
6 #include "ace/OS_NS_unistd.h"
7 #include "ace/Synch_Traits.h"
9 int producer (ACE_SYNCH_PROCESS_SEMAPHORE
&sema
,
12 for (int i
= iter
; i
> 0; --i
)
15 "Try releasing the semaphore (%d): ",
18 int result
= sema
.release ();
22 (result
!= 0 ? "fail\n" : "succeed\n")));
27 int consumer (ACE_SYNCH_PROCESS_SEMAPHORE
&sema
,
30 for (int i
= iter
; i
> 0; --i
)
33 "Try acquiring the semaphore (%d): ",
36 int result
= sema
.acquire ();
40 (result
!= 0 ? "fail\n" : "succeed\n")));
45 int ACE_TMAIN (int argc
, ACE_TCHAR
*argv
[])
47 //FUZZ: disable check_for_lack_ACE_OS
48 ACE_Get_Opt
getopt (argc
, argv
, ACE_TEXT ("csn:xi:d:"));
49 //FUZZ: enable check_for_lack_ACE_OS
51 int is_consumer
= 1; // By default, make us a consumer.
55 const ACE_TCHAR
*sema_name
= ACE_TEXT ("Process_Semaphore_Test");
59 //FUZZ: disable check_for_lack_ACE_OS
60 while ((opt
= getopt ()) != -1)
62 //FUZZ: enable check_for_lack_ACE_OS
65 case 'c': // Make us a consumer.
68 case 's': // Make us a supplier.
71 case 'x': // Remove the semaphore after we're done.
74 case 'n': // Specify the name of the semaphore.
75 sema_name
= getopt
.opt_arg ();
77 case 'i': // Number of acquire/release we'll perform.
78 iteration
= ACE_OS::atoi (getopt
.opt_arg ());
81 exit_delay
= ACE_OS::atoi (getopt
.opt_arg ());
88 ACE_SYNCH_PROCESS_SEMAPHORE
sema (0, sema_name
);
91 consumer (sema
, iteration
);
93 producer (sema
, iteration
);
95 ACE_OS::sleep (exit_delay
);