diff options
Diffstat (limited to 'ACE/examples/Synch')
-rw-r--r-- | ACE/examples/Synch/Makefile.am | 39 | ||||
-rw-r--r-- | ACE/examples/Synch/README | 21 | ||||
-rw-r--r-- | ACE/examples/Synch/Synch.mpc | 7 | ||||
-rw-r--r-- | ACE/examples/Synch/proc_sema.cpp | 102 |
4 files changed, 169 insertions, 0 deletions
diff --git a/ACE/examples/Synch/Makefile.am b/ACE/examples/Synch/Makefile.am new file mode 100644 index 00000000000..7e3243cb3b4 --- /dev/null +++ b/ACE/examples/Synch/Makefile.am @@ -0,0 +1,39 @@ +## Process this file with automake to create Makefile.in +## +## $Id$ +## +## This file was generated by MPC. Any changes made directly to +## this file will be lost the next time it is generated. +## +## MPC Command: +## ./bin/mwc.pl -type automake -noreldefs ACE.mwc + +ACE_BUILDDIR = $(top_builddir) +ACE_ROOT = $(top_srcdir) + + +## Makefile.Synch.am + +if !BUILD_ACE_FOR_TAO + +noinst_PROGRAMS = proc_sema + +proc_sema_CPPFLAGS = \ + -I$(ACE_ROOT) \ + -I$(ACE_BUILDDIR) + +proc_sema_SOURCES = \ + proc_sema.cpp + +proc_sema_LDADD = \ + $(ACE_BUILDDIR)/ace/libACE.la + +endif !BUILD_ACE_FOR_TAO + +## Clean up template repositories, etc. +clean-local: + -rm -f *~ *.bak *.rpo *.sym lib*.*_pure_* core core.* + -rm -f gcctemp.c gcctemp so_locations *.ics + -rm -rf cxx_repository ptrepository ti_files + -rm -rf templateregistry ir.out + -rm -rf ptrepository SunWS_cache Templates.DB diff --git a/ACE/examples/Synch/README b/ACE/examples/Synch/README new file mode 100644 index 00000000000..526120f2744 --- /dev/null +++ b/ACE/examples/Synch/README @@ -0,0 +1,21 @@ +This directory currently only contains one example for testing process +semaphores. + +proc_sema: + This test can be used to test out the named process semaphores +support on your platform. It can be run as either a supplier or a +consumer process. The available options are: + + -c: Make us a consumer. + -s: Make us a supplier. + -x: Remove the semaphore after we're done. + -n: Specify the name of the semaphore. + -i: Number of acquire/release we'll perform. + -d: Delay for # of second before exiting the program + + You can use this test to see how process semaphores work. For +example, run the program as: + + proc_sema -c -i 10 + proc_sema -s -i 3 + proc_sema -s -i 7 diff --git a/ACE/examples/Synch/Synch.mpc b/ACE/examples/Synch/Synch.mpc new file mode 100644 index 00000000000..024e8459803 --- /dev/null +++ b/ACE/examples/Synch/Synch.mpc @@ -0,0 +1,7 @@ +// -*- MPC -*- +// $Id$ + +project : aceexe { + avoids += ace_for_tao + exename = proc_sema +} diff --git a/ACE/examples/Synch/proc_sema.cpp b/ACE/examples/Synch/proc_sema.cpp new file mode 100644 index 00000000000..18f967f21a3 --- /dev/null +++ b/ACE/examples/Synch/proc_sema.cpp @@ -0,0 +1,102 @@ +// $Id$ + +#include "ace/OS_main.h" +#include "ace/Process_Semaphore.h" +#include "ace/Get_Opt.h" +#include "ace/Log_Msg.h" +#include "ace/OS_NS_stdlib.h" +#include "ace/OS_NS_unistd.h" +#include "ace/Synch_Traits.h" + +int producer (ACE_SYNCH_PROCESS_SEMAPHORE &sema, + int iter) +{ + for (int i = iter; i > 0; --i) + { + ACE_DEBUG ((LM_DEBUG, + "Try releasing the semaphore (%d): ", + i)); + + int result = sema.release (); + + ACE_DEBUG ((LM_DEBUG, + "%s", + (result != 0 ? "fail\n" : "succeed\n"))); + } + return 0; +} + +int consumer (ACE_SYNCH_PROCESS_SEMAPHORE &sema, + int iter) +{ + for (int i = iter; i > 0; --i) + { + ACE_DEBUG ((LM_DEBUG, + "Try acquiring the semaphore (%d): ", + i)); + + int result = sema.acquire (); + + ACE_DEBUG ((LM_DEBUG, + "%s", + (result != 0 ? "fail\n" : "succeed\n"))); + } + return 0; +} + +int ACE_TMAIN (int argc, ACE_TCHAR *argv[]) +{ + //FUZZ: disable check_for_lack_ACE_OS + ACE_Get_Opt getopt (argc, argv, ACE_TEXT ("csn:xi:d:")); + //FUZZ: enable check_for_lack_ACE_OS + + int is_consumer = 1; // By default, make us a consumer. + int delete_sema = 0; + int iteration = 0; + int exit_delay = 0; + const ACE_TCHAR *sema_name = ACE_TEXT ("Process_Semaphore_Test"); + + int opt; + + //FUZZ: disable check_for_lack_ACE_OS + while ((opt = getopt ()) != -1) + { + //FUZZ: enable check_for_lack_ACE_OS + switch (opt) + { + case 'c': // Make us a consumer. + is_consumer = 1; + break; + case 's': // Make us a supplier. + is_consumer = 0; + break; + case 'x': // Remove the semaphore after we're done. + delete_sema = 1; + break; + case 'n': // Specify the name of the semaphore. + sema_name = getopt.opt_arg (); + break; + case 'i': // Number of acquire/release we'll perform. + iteration = ACE_OS::atoi (getopt.opt_arg ()); + break; + case 'd': + exit_delay = ACE_OS::atoi (getopt.opt_arg ()); + break; + default: + return -1; + } + }; + + ACE_SYNCH_PROCESS_SEMAPHORE sema (0, sema_name); + + if (is_consumer != 0) + consumer (sema, iteration); + else + producer (sema, iteration); + + ACE_OS::sleep (exit_delay); + + if (delete_sema != 0) + sema.remove (); + return 0; +} |