summaryrefslogtreecommitdiff
path: root/examples/Shared_Malloc
diff options
context:
space:
mode:
authorWilliam R. Otte <wotte@dre.vanderbilt.edu>2006-07-24 15:50:11 +0000
committerWilliam R. Otte <wotte@dre.vanderbilt.edu>2006-07-24 15:50:11 +0000
commit6b846cf03c0bcbd8c276cb0af61a181e5f98eaae (patch)
treeda50d054f9c761c3f6a5923f6979e93306c56d68 /examples/Shared_Malloc
parent0e555b9150d38e3b3473ba325b56db2642e6352b (diff)
downloadATCD-6b846cf03c0bcbd8c276cb0af61a181e5f98eaae.tar.gz
Repo restructuring
Diffstat (limited to 'examples/Shared_Malloc')
-rw-r--r--examples/Shared_Malloc/.cvsignore4
-rw-r--r--examples/Shared_Malloc/Makefile.am106
-rw-r--r--examples/Shared_Malloc/Malloc.cpp69
-rw-r--r--examples/Shared_Malloc/Malloc.h33
-rw-r--r--examples/Shared_Malloc/Options.cpp201
-rw-r--r--examples/Shared_Malloc/Options.h86
-rw-r--r--examples/Shared_Malloc/Shared_Malloc.mpc37
-rw-r--r--examples/Shared_Malloc/test_malloc.cpp228
-rw-r--r--examples/Shared_Malloc/test_multiple_mallocs.cpp125
-rw-r--r--examples/Shared_Malloc/test_persistence.cpp350
-rw-r--r--examples/Shared_Malloc/test_position_independent_malloc.cpp190
-rw-r--r--examples/Shared_Malloc/test_position_independent_malloc.h28
12 files changed, 0 insertions, 1457 deletions
diff --git a/examples/Shared_Malloc/.cvsignore b/examples/Shared_Malloc/.cvsignore
deleted file mode 100644
index c5ad2e56e0e..00000000000
--- a/examples/Shared_Malloc/.cvsignore
+++ /dev/null
@@ -1,4 +0,0 @@
-malloc
-multiple
-persistence
-posind
diff --git a/examples/Shared_Malloc/Makefile.am b/examples/Shared_Malloc/Makefile.am
deleted file mode 100644
index baccb0359e0..00000000000
--- a/examples/Shared_Malloc/Makefile.am
+++ /dev/null
@@ -1,106 +0,0 @@
-## 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:
-## /acebuilds/ACE_wrappers-repository/bin/mwc.pl -include /acebuilds/MPC/config -include /acebuilds/MPC/templates -feature_file /acebuilds/ACE_wrappers-repository/local.features -noreldefs -type automake -exclude build,Kokyu
-
-ACE_BUILDDIR = $(top_builddir)
-ACE_ROOT = $(top_srcdir)
-
-noinst_PROGRAMS =
-
-## Makefile.Shared_Malloc.am
-
-if !BUILD_ACE_FOR_TAO
-noinst_PROGRAMS += malloc
-
-malloc_CPPFLAGS = \
- -I$(ACE_ROOT) \
- -I$(ACE_BUILDDIR)
-
-malloc_SOURCES = \
- Malloc.cpp \
- Options.cpp \
- test_malloc.cpp \
- Malloc.h \
- Options.h
-
-malloc_LDADD = \
- $(ACE_BUILDDIR)/ace/libACE.la
-
-endif !BUILD_ACE_FOR_TAO
-
-## Makefile.Shared_Malloc_Multiple.am
-
-if !BUILD_ACE_FOR_TAO
-noinst_PROGRAMS += multiple
-
-multiple_CPPFLAGS = \
- -I$(ACE_ROOT) \
- -I$(ACE_BUILDDIR)
-
-multiple_SOURCES = \
- Malloc.cpp \
- Options.cpp \
- test_multiple_mallocs.cpp \
- Malloc.h \
- Options.h
-
-multiple_LDADD = \
- $(ACE_BUILDDIR)/ace/libACE.la
-
-endif !BUILD_ACE_FOR_TAO
-
-## Makefile.Shared_Malloc_Persistence.am
-
-if !BUILD_ACE_FOR_TAO
-noinst_PROGRAMS += persistence
-
-persistence_CPPFLAGS = \
- -I$(ACE_ROOT) \
- -I$(ACE_BUILDDIR)
-
-persistence_SOURCES = \
- test_persistence.cpp \
- Malloc.h \
- Options.h \
- test_position_independent_malloc.h
-
-persistence_LDADD = \
- $(ACE_BUILDDIR)/ace/libACE.la
-
-endif !BUILD_ACE_FOR_TAO
-
-## Makefile.Shared_Malloc_Posind.am
-
-if !BUILD_ACE_FOR_TAO
-noinst_PROGRAMS += posind
-
-posind_CPPFLAGS = \
- -I$(ACE_ROOT) \
- -I$(ACE_BUILDDIR)
-
-posind_SOURCES = \
- Malloc.cpp \
- Options.cpp \
- test_position_independent_malloc.cpp \
- Malloc.h \
- Options.h \
- test_position_independent_malloc.h
-
-posind_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/examples/Shared_Malloc/Malloc.cpp b/examples/Shared_Malloc/Malloc.cpp
deleted file mode 100644
index 4499d9fa11b..00000000000
--- a/examples/Shared_Malloc/Malloc.cpp
+++ /dev/null
@@ -1,69 +0,0 @@
-// $Id$
-
-#include "Options.h"
-#include "Malloc.h"
-#include "ace/MMAP_Memory_Pool.h"
-#include "ace/Local_Memory_Pool.h"
-
-#ifndef ACE_LACKS_SYSV_SHMEM
-# include "ace/Shared_Memory_Pool.h"
-#endif /* !ACE_LACKS_SYSV_SHMEM */
-
-#ifndef ACE_LACKS_SBRK
-# include "ace/Sbrk_Memory_Pool.h"
-#endif /* !ACE_LACKS_SBRK */
-
-#include "ace/Process_Mutex.h"
-#include "ace/Malloc_T.h"
-
-ACE_RCSID(Shared_Malloc, Malloc, "$Id$")
-
-// Strategic typedefs for memory allocation.
-
-typedef ACE_Malloc <ACE_LOCAL_MEMORY_POOL, ACE_SYNCH_MUTEX> L_ALLOCATOR;
-typedef ACE_Malloc <ACE_MMAP_MEMORY_POOL, ACE_Process_Mutex> M_ALLOCATOR;
-
-#if defined (ACE_LACKS_SYSV_SHMEM)
-typedef ACE_Malloc <ACE_MMAP_MEMORY_POOL, ACE_SYNCH_MUTEX> SP_ALLOCATOR;
-typedef ACE_Malloc <ACE_MMAP_MEMORY_POOL, ACE_SYNCH_MUTEX> ST_ALLOCATOR;
-#else
-typedef ACE_Malloc <ACE_SHARED_MEMORY_POOL, ACE_Process_Mutex> SP_ALLOCATOR;
-typedef ACE_Malloc <ACE_SHARED_MEMORY_POOL, ACE_SYNCH_MUTEX> ST_ALLOCATOR;
-#endif /* ACE_LACKS_SYSV_SHMEM */
-
-#if defined (ACE_LACKS_SBRK)
-typedef ACE_Malloc <ACE_LOCAL_MEMORY_POOL, ACE_SYNCH_MUTEX> SB_ALLOCATOR;
-#else
-typedef ACE_Malloc <ACE_SBRK_MEMORY_POOL, ACE_SYNCH_MUTEX> SB_ALLOCATOR;
-#endif /* ACE_LACKS_SBRK */
-
-// Singleton
-ACE_Allocator *Malloc::instance_ = 0;
-
-// This is a factory that decides what type of allocator to create.
-
-ACE_Allocator *
-Malloc::instance (void)
-{
- if (Malloc::instance_ == 0)
- {
- if (Options::instance ()->child ())
- Malloc::instance_ = new ACE_Allocator_Adapter<M_ALLOCATOR>;
- else if (Options::instance ()->spawn_threads ())
- {
- if (Options::instance ()->use_sbrk ())
- Malloc::instance_ = new ACE_Allocator_Adapter<SB_ALLOCATOR>;
- else if (Options::instance ()->use_shmem ())
- Malloc::instance_ = new ACE_Allocator_Adapter<ST_ALLOCATOR>;
- else
- Malloc::instance_ = new ACE_Allocator_Adapter<L_ALLOCATOR>;
- }
- else if (Options::instance ()->use_mmap ())
- Malloc::instance_ = new ACE_Allocator_Adapter<M_ALLOCATOR>;
- else // Use Shared_Memory_Pool.
- Malloc::instance_ = new ACE_Allocator_Adapter<SP_ALLOCATOR>;
- }
-
- return Malloc::instance_;
-}
-
diff --git a/examples/Shared_Malloc/Malloc.h b/examples/Shared_Malloc/Malloc.h
deleted file mode 100644
index c88cead8bfb..00000000000
--- a/examples/Shared_Malloc/Malloc.h
+++ /dev/null
@@ -1,33 +0,0 @@
-/* -*- C++ -*- */
-// $Id$
-
-#ifndef MY_MALLOC_H
-#define MY_MALLOC_H
-
-#include "ace/config-all.h"
-
-#if !defined (ACE_LACKS_PRAGMA_ONCE)
-# pragma once
-#endif /* ACE_LACKS_PRAGMA_ONCE */
-
-ACE_BEGIN_VERSIONED_NAMESPACE_DECL
-class ACE_Allocator;
-ACE_END_VERSIONED_NAMESPACE_DECL
-
-class Malloc
- // = TITLE
- // Allocator Singleton.
-{
-public:
- static ACE_Allocator *instance (void);
- // Returns static instance.
-
-private:
- Malloc (void);
- // Ensure Singleton.
-
- static ACE_Allocator *instance_;
- // Malloc Singleton.
-};
-
-#endif /* MY_MALLOC_H */
diff --git a/examples/Shared_Malloc/Options.cpp b/examples/Shared_Malloc/Options.cpp
deleted file mode 100644
index 6716fa66c31..00000000000
--- a/examples/Shared_Malloc/Options.cpp
+++ /dev/null
@@ -1,201 +0,0 @@
-// $Id$
-
-#include "ace/Get_Opt.h"
-#include "Options.h"
-#include "ace/Log_Msg.h"
-#include "ace/OS_NS_stdlib.h"
-#include "ace/OS_NS_string.h"
-
-ACE_RCSID (Shared_Malloc,
- Options,
- "$Id$")
-
-// Static Singleton instance.
-Options *Options::instance_ = 0;
-
-Options *
-Options::instance (void)
-{
- if (Options::instance_ == 0)
- Options::instance_ = new Options ();
-
- return Options::instance_;
-}
-
-const char *
-Options::program_name (void)
-{
- return this->program_name_;
-}
-
-const char *
-Options::slave_name (void)
-{
- return this->slave_name_;
-}
-
-int
-Options::debug (void)
-{
- return this->debug_;
-}
-
-int
-Options::exec_slave (void)
-{
- return this->exec_slave_;
-}
-
-size_t
-Options::iteration_count (void)
-{
- return this->iteration_count_;
-}
-
-int
-Options::use_sbrk (void)
-{
- return this->use_sbrk_;
-}
-
-size_t
-Options::max_msg_size (void)
-{
- return this->max_msg_size_;
-}
-
-size_t
-Options::spawn_count (void)
-{
- return this->spawn_count_;
-}
-
-int
-Options::spawn_threads (void)
-{
- return this->spawn_threads_;
-}
-
-int
-Options::use_mmap (void)
-{
- return this->use_mmap_;
-}
-
-int
-Options::use_shmem (void)
-{
- return this->use_shmem_;
-}
-
-int
-Options::child (void)
-{
- return this->child_;
-}
-
-// Explain usage and exit.
-
-void
-Options::print_usage_and_die (void)
-{
- ACE_ERROR ((LM_ERROR,
- ACE_TEXT ("usage: %n")
- ACE_TEXT ("\n[-d] (run in debugging mode)\n")
- ACE_TEXT ("[-e] (use exec(2) in addition to fork(2))\n")
- ACE_TEXT ("[-l] (use C++ new operator rather than sbrk(2)\n")
- ACE_TEXT ("[-L max_msg_size]\n")
- ACE_TEXT ("[-m] (use mmap rather than SysV shared memory)\n")
- ACE_TEXT ("[-p] (use processes rather than threads)\n")
- ACE_TEXT ("[-s] (use SysV shared memory rather than mmap)\n")
- ACE_TEXT ("[-t number of threads or processes to spawn]\n")
- ACE_TEXT ("[-T] (enable tracking)\n")
- ACE_TEXT ("[-n iteration_count]\n")));
- ACE_OS::exit (1);
- /* NOTREACHED */
-}
-
-Options::Options (void)
- : debug_ (0),
- exec_slave_ (0),
- iteration_count_ (100),
- use_sbrk_ (0),
- use_shmem_ (0),
- max_msg_size_ (127),
- spawn_count_ (1),
- spawn_threads_ (1),
- use_mmap_ (0),
- child_ (0)
-{
- ACE_OS::strcpy (this->slave_name_, "slave");
-}
-
-void
-Options::parse_args (int argc, ACE_TCHAR *argv[])
-{
- ACE_Get_Opt get_opt (argc, argv, ACE_TEXT ("dehlL:mn:pst:T"));
-
- ACE_OS::strcpy (this->program_name_, ACE_TEXT_ALWAYS_CHAR (argv[0]));
- ACE_LOG_MSG->open (argv[0]);
-
- // Put in a special-case check for child process.
- if (ACE_OS::strcmp (this->program_name_, slave_name_) == 0)
- {
- this->child_ = 1;
- this->use_mmap_ = 1;
- }
-
- for (int c;
- (c = get_opt ()) != -1;
- )
- {
- switch (c)
- {
- case 'd':
- this->debug_ = 1;
- break;
- case 'e':
- this->exec_slave_ = 1;
- break;
- case 'h':
- this->print_usage_and_die ();
- /* NOTREACHED */
- break;
- case 'l':
- this->use_sbrk_ = 0;
- break;
- case 'L':
- this->max_msg_size_ = ACE_OS::atoi (get_opt.opt_arg ());
- break;
- case 'm':
- this->use_mmap_ = 1;
- break;
- case 'n':
- this->iteration_count_ = ACE_OS::atoi (get_opt.opt_arg ());
- break;
- case 'p': // Spawn processes rather than threads
- this->spawn_threads_ = 0;
- break;
- case 's':
- // Use System V shared memory...
- this->use_shmem_ = 1;
- break;
- case 't':
- this->spawn_count_ = ACE_OS::atoi (get_opt.opt_arg ());
- break;
- case 'T':
-#if defined (ACE_HAS_TRACE)
- ACE_Trace::start_tracing ();
-#endif /* ACE_HAS_TRACE */
- break;
- default:
- this->print_usage_and_die ();
- /* NOTREACHED */
- break;
- }
- }
-
- // Switch to using MMAP when the -p and -e options are enabled.
- if (this->exec_slave_ == 1 && this->spawn_threads_ == 0)
- this->use_mmap_ = 1;
-}
diff --git a/examples/Shared_Malloc/Options.h b/examples/Shared_Malloc/Options.h
deleted file mode 100644
index 67956d80cc3..00000000000
--- a/examples/Shared_Malloc/Options.h
+++ /dev/null
@@ -1,86 +0,0 @@
-/* -*- C++ -*- */
-// $Id$
-
-#ifndef _OPTIONS
-#define _OPTIONS
-
-#include "ace/os_include/os_stddef.h"
-#include "ace/os_include/os_limits.h"
-
-#if !defined (ACE_LACKS_PRAGMA_ONCE)
-# pragma once
-#endif /* ACE_LACKS_PRAGMA_ONCE */
-
-class Options
- // = TITLE
- // Options Singleton.
-{
-public:
- static Options *instance (void);
- // Return Singleton.
-
- void parse_args (int argc, ACE_TCHAR *argv[]);
- // Parse the arguments.
-
- // = Accessor methods.
- const char *program_name (void);
- const char *slave_name (void);
- int debug (void);
- int exec_slave (void);
- size_t iteration_count (void);
- int use_sbrk (void);
- int use_shmem (void);
- size_t max_msg_size (void);
- size_t spawn_count (void);
- int spawn_threads (void);
- int use_mmap (void);
- int child (void);
-
-private:
- Options (void);
- // Ensure Singleton.
-
- static Options *instance_;
- // Singleton.
-
- void print_usage_and_die (void);
- // Explain usage and exit.
-
- char program_name_[MAXPATHLEN];
- // Name of the program.
-
- char slave_name_[MAXPATHLEN];
- // Name of slave process.
-
- int debug_;
- // Flag to indicate if we are debugging.
-
- int exec_slave_;
- // Flag to indicate if we should exec after forking.
-
- size_t iteration_count_;
- // Number of iterations to call malloc_recurse().
-
- int use_sbrk_;
- // Should we use sbrk(2)?
-
- int use_shmem_;
- // Should we use Shared Memory?
-
- size_t max_msg_size_;
- // Maximum number of bytes to malloc.
-
- size_t spawn_count_;
- // Number of threads.
-
- int spawn_threads_;
- // Spawn threads vs. processes.
-
- int use_mmap_;
- // Use mmap() as the backing store.
-
- int child_;
- // We're a child process.
-};
-
-#endif /* _OPTIONS */
diff --git a/examples/Shared_Malloc/Shared_Malloc.mpc b/examples/Shared_Malloc/Shared_Malloc.mpc
deleted file mode 100644
index 42753246815..00000000000
--- a/examples/Shared_Malloc/Shared_Malloc.mpc
+++ /dev/null
@@ -1,37 +0,0 @@
-// -*- MPC -*-
-// $Id$
-
-project : aceexe {
- avoids += ace_for_tao
- exename = malloc
- Source_Files {
- Malloc.cpp
- Options.cpp
- test_malloc.cpp
- }
-}
-project(*multiple) : aceexe {
- avoids += ace_for_tao
- exename = multiple
- Source_Files {
- Malloc.cpp
- Options.cpp
- test_multiple_mallocs.cpp
- }
-}
-project(*persistence) : aceexe {
- avoids += ace_for_tao
- exename = persistence
- Source_Files {
- test_persistence.cpp
- }
-}
-project(*posind) : aceexe {
- avoids += ace_for_tao
- exename = posind
- Source_Files {
- Malloc.cpp
- Options.cpp
- test_position_independent_malloc.cpp
- }
-}
diff --git a/examples/Shared_Malloc/test_malloc.cpp b/examples/Shared_Malloc/test_malloc.cpp
deleted file mode 100644
index b6143aa989c..00000000000
--- a/examples/Shared_Malloc/test_malloc.cpp
+++ /dev/null
@@ -1,228 +0,0 @@
-// $Id$
-
-// This program tests out all the various ACE_Malloc combinations and
-// the ACE_Allocator_Adapter.
-
-#include "ace/Thread.h"
-#include "ace/Thread_Manager.h"
-#include "ace/Malloc.h"
-#include "ace/Signal.h"
-#include "ace/OS_NS_stdio.h"
-#include "ace/OS_NS_string.h"
-#include "ace/OS_NS_sys_wait.h"
-#include "ace/OS_NS_unistd.h"
-#include "Malloc.h"
-#include "Options.h"
-
-ACE_RCSID(Shared_Malloc, test_malloc, "$Id$")
-
-static int
-gen_size (void)
-{
-#if defined (ACE_HAS_THREADS)
- ACE_RANDR_TYPE seed = static_cast<ACE_RANDR_TYPE> (reinterpret_cast<unsigned long> (&seed));
- return (ACE_OS::rand_r (seed) % Options::instance ()->max_msg_size ()) + 1;
-#else
- return (ACE_OS::rand () % Options::instance ()->max_msg_size ()) + 1;
-#endif /* ACE_HAS_THREADS */
-}
-
-// Recursively allocate and deallocate dynamic memory.
-
-static int
-malloc_recurse (int count)
-{
- static char default_char = 0;
-
- if (count <= 0)
- {
- if (Options::instance ()->debug ())
- {
- // Note that you'll need to #define ACE_HAS_MALLOC_STATS in
- // the main ACE config.h file and remake ACE to enable this.
- ACE_MALLOC_STATS (Malloc::instance ()->print_stats ());
- }
- }
- else
- {
- int alloc_size = gen_size ();
- void *ptr = Malloc::instance ()->malloc (alloc_size);
-
- if (ptr == 0)
- ACE_ERROR ((LM_ERROR,
- "(%P|%t) *** malloc of size %d failed, %p\n%a",
- "malloc",
- alloc_size));
- else
- {
- ACE_OS::memset (ptr, default_char++, alloc_size);
-
- if (Options::instance ()->debug ())
- ACE_DEBUG ((LM_INFO,
- "(%P|%t) %u (alloc), size = %d\n",
- ptr,
- alloc_size));
-
- // Call ourselves recursively
- malloc_recurse (count - 1);
-
- if (Options::instance ()->debug ())
- ACE_DEBUG ((LM_INFO,
- "(%P|%t) %u (free), size = %d\n",
- ptr,
- alloc_size));
- Malloc::instance ()->free (ptr);
- }
- }
-
- return 0;
-}
-
-#if defined (ACE_HAS_THREADS)
-static void *
-worker (void *arg)
-{
- // Cast the arg to a long, first, because a pointer is the same
- // size as a long on all current ACE platforms.
- malloc_recurse ((int) (long) arg);
-
- return 0;
-}
-#endif /* ACE_HAS_THREADS */
-
-// Create the appropriate type of process/thread.
-
-static void
-spawn (void)
-{
- if (Options::instance ()->spawn_threads ())
- {
-#if defined (ACE_HAS_THREADS)
- if (ACE_Thread_Manager::instance ()->spawn (ACE_THR_FUNC (worker),
- (void *) Options::instance ()->iteration_count (),
- THR_BOUND) == -1)
- ACE_ERROR ((LM_ERROR, "%p\n%a", "thread create failed"));
-#else
- if (Options::instance ()->spawn_count () > 1)
- ACE_ERROR ((LM_ERROR,
- "only one thread may be run in a process on this platform\n%a",
- 1));
-#endif /* ACE_HAS_THREADS */
- }
-#if !defined (ACE_WIN32)
- else if (ACE_OS::fork (ACE_TEXT_CHAR_TO_TCHAR (Options::instance ()->program_name ())) == 0)
- {
- if (Options::instance ()->exec_slave ())
- {
- char iterations[20];
- char msg_size[20];
-
- ACE_OS::sprintf (iterations, "%lu",
- (unsigned long)
- Options::instance ()->iteration_count ());
- ACE_OS::sprintf (msg_size, "%lu",
- (unsigned long)
- Options::instance ()->max_msg_size ());
- const char *cp = 0;
-
- if (Options::instance ()->debug ())
- cp = "-d";
- else
- cp = "";
-
- const char *argv[] =
- {
- Options::instance ()->slave_name (),
- "-p",
- "-n",
- iterations,
- "-L",
- msg_size,
- cp,
- 0
- };
-
- if (ACE_OS::execv (Options::instance ()->program_name (),
- (char *const *) argv) == -1)
- ACE_ERROR ((LM_ERROR, "%p\n", "exec failed"));
- ACE_OS::_exit (1);
- }
- else
- {
- ACE_DEBUG ((LM_INFO,
- "(%P|%t) about to recurse with iteration count = %d\n",
- Options::instance ()->iteration_count ()));
-
- malloc_recurse (Options::instance ()->iteration_count ());
- Malloc::instance ()->remove ();
- ACE_OS::exit (0);
- }
- }
-#endif /* ACE_WIN32 */
-}
-
-// Wait for all the child processes/threads to exit.
-
-static void
-wait_for_children (void)
-{
- if (Options::instance ()->spawn_threads ())
- {
-#if defined (ACE_HAS_THREADS)
- // Wait for the threads to terminate.
- ACE_Thread_Manager::instance ()->wait ();
-#else
- malloc_recurse (Options::instance ()->iteration_count ());
-#endif /* ACE_HAS_THREADS */
- }
-#if !defined (ACE_WIN32)
- else
- {
- pid_t pid;
-
- while ((pid = ACE_OS::wait (0)) != -1)
- ACE_DEBUG ((LM_DEBUG, "(%P|%t) reaped pid = %d\n", pid));
- }
-#endif /* ACE_WIN32 */
-}
-
-extern "C" void
-handler (int)
-{
- Malloc::instance ()->remove ();
- ACE_ERROR ((LM_ERROR, "(%P|%t) removed handler\n%a", 0));
-}
-
-int
-ACE_TMAIN (int argc, ACE_TCHAR *argv[])
-{
- // Register a signal handler.
- ACE_Sig_Action sa ((ACE_SignalHandler) handler, SIGINT);
- ACE_UNUSED_ARG (sa);
-
- Options::instance ()->parse_args (argc, argv);
-
-#if !defined (ACE_WIN32)
- if (Options::instance ()->child ())
- {
- ACE_DEBUG ((LM_INFO,
- "(%P|%t) about to recurse with iteration count = %d, debug = %d\n",
- Options::instance ()->iteration_count ()));
-
- // We've been forked...
- malloc_recurse (Options::instance ()->iteration_count ());
- Malloc::instance ()->remove ();
- }
- else
-#endif /* ACE_WIN32 */
- {
- for (size_t i = 0;
- i < Options::instance ()->spawn_count ();
- i++)
- spawn ();
-
- wait_for_children ();
- Malloc::instance ()->remove ();
- }
- return 0;
-}
diff --git a/examples/Shared_Malloc/test_multiple_mallocs.cpp b/examples/Shared_Malloc/test_multiple_mallocs.cpp
deleted file mode 100644
index 1638a762060..00000000000
--- a/examples/Shared_Malloc/test_multiple_mallocs.cpp
+++ /dev/null
@@ -1,125 +0,0 @@
-// $Id$
-
-// Test the capability of <ACE_Malloc> to handle multiple mallocs
-// rooted at different base addresses.
-
-#include "ace/OS_NS_string.h"
-#include "ace/Malloc_T.h"
-#include "ace/MMAP_Memory_Pool.h"
-#include "ace/Auto_Ptr.h"
-#include "ace/Process_Mutex.h"
-
-ACE_RCSID(Shared_Malloc, test_multiple_mallocs, "$Id$")
-
-typedef ACE_Malloc <ACE_MMAP_MEMORY_POOL, ACE_Process_Mutex> TEST_MALLOC;
-
-#if (ACE_HAS_POSITION_INDEPENDENT_POINTERS == 1)
-// The Address for the shared memory mapped files defaults to wherever
-// the OS wants to map it.
-const void *REQUEST_BASE_ADDR = 0;
-const void *RESPONSE_BASE_ADDR = 0;
-#else
-// Default address for shared memory mapped files and SYSV shared
-// memory (defaults to 64 M).
-const void *REQUEST_BASE_ADDR = ((void *) (64 * 1024 * 1024));
-
-// Default address for shared memory mapped files and SYSV shared
-// memory (defaults to 64 M).
-const void *RESPONSE_BASE_ADDR = ((void *) (128 * 1024 * 1024));
-#endif /* ACE_HAS_POSITION_INDEPENDENT_POINTERS == 1 */
-
-static const char *request_string = "hello from request repository";
-static const char *response_string = "hello from response repository";
-
-int
-ACE_TMAIN (int, ACE_TCHAR *[])
-{
- ACE_MMAP_Memory_Pool_Options request_options (REQUEST_BASE_ADDR);
-
- // Create an adapter version of an allocator.
- ACE_Allocator_Adapter<TEST_MALLOC> *adapter_ptr = 0;
- ACE_NEW_RETURN (adapter_ptr,
- ACE_Allocator_Adapter<TEST_MALLOC> ("request_file",
- "request_lock",
- &request_options),
- 1);
-
- auto_ptr <ACE_Allocator_Adapter<TEST_MALLOC> > shmem_request (adapter_ptr);
- ACE_MMAP_Memory_Pool_Options response_options (RESPONSE_BASE_ADDR);
-
- TEST_MALLOC *ptr = 0;
- // Create a non-adapter version of an allocator.
- ACE_NEW_RETURN (ptr,
- TEST_MALLOC (ACE_TEXT("response_file"),
- ACE_TEXT("response_lock"),
- &response_options),
- 1);
- auto_ptr <TEST_MALLOC> shmem_response (ptr);
- void *data = 0;
-
- // If we find "foo" then we're running the "second" time, so we must
- // release the resources.
- if (shmem_request->find ("foo",
- data) == 0)
- {
- ACE_DEBUG ((LM_DEBUG,
- "%s\n",
- data));
- shmem_request->remove ();
- }
-
- // This is the first time in, so we allocate the memory and bind it
- // to the name "foo".
- else
- {
- ACE_ALLOCATOR_RETURN (data,
- shmem_request->malloc (ACE_OS::strlen (request_string) + 1),
- 1);
- ACE_OS::strcpy ((char *) data,
- request_string);
-
- if (shmem_request->bind ("foo",
- data) == -1)
- ACE_ERROR_RETURN ((LM_ERROR,
- "%p\n",
- "bind"),
- 1);
- }
- data = 0;
-
- // If we find "foo" then we're running the "second" time, so we must
- // release the resources.
- if (shmem_response->find ("foo",
- data) == 0)
- {
- ACE_DEBUG ((LM_DEBUG,
- "%s\n",
- data));
- shmem_response->remove ();
- ACE_DEBUG ((LM_DEBUG,
- "all shared memory resources have been released\n"));
- }
-
- // This is the first time in, so we allocate the memory and bind it
- // to the name "foo".
- else
- {
- ACE_ALLOCATOR_RETURN (data,
- shmem_response->malloc (ACE_OS::strlen (response_string) + 1),
- 1);
- ACE_OS::strcpy ((char *) data,
- response_string);
-
- if (shmem_response->bind ("foo",
- data) == -1)
- ACE_ERROR ((LM_ERROR,
- "%p\n",
- "bind"));
- else
- ACE_DEBUG ((LM_DEBUG,
- "Run again to see results and release resources.\n"));
- }
-
- return 0;
-}
-
diff --git a/examples/Shared_Malloc/test_persistence.cpp b/examples/Shared_Malloc/test_persistence.cpp
deleted file mode 100644
index 8c3df750853..00000000000
--- a/examples/Shared_Malloc/test_persistence.cpp
+++ /dev/null
@@ -1,350 +0,0 @@
-// $Id$
-
-// Test the persistence capabilities of <ACE_Malloc> when configured
-// for mmap-based shared memory management.
-
-// This examples uses scanf to read user inputs from stdin into fixed
-// sized buffers. This may cause buffers to overrun.
-
-#include "ace/OS_NS_string.h"
-#include "ace/Malloc_T.h"
-#include "ace/MMAP_Memory_Pool.h"
-
-// FUZZ: disable check_for_streams_include
-#include "ace/streams.h"
-
-#include "ace/Null_Mutex.h"
-
-ACE_RCSID (Shared_Malloc,
- test_persistence,
- "$Id$")
-
-typedef ACE_Malloc <ACE_MMAP_MEMORY_POOL, ACE_Null_Mutex> TEST_MALLOC;
-typedef ACE_Malloc_LIFO_Iterator <ACE_MMAP_MEMORY_POOL, ACE_Null_Mutex> MALLOC_LIFO_ITERATOR;
-typedef ACE_Malloc_FIFO_Iterator <ACE_MMAP_MEMORY_POOL, ACE_Null_Mutex> MALLOC_FIFO_ITERATOR;
-
-// Shared memory manager.
-static TEST_MALLOC *shmem_allocator = 0;
-
-// Backing store name.
-static ACE_TCHAR backing_store[MAXPATHLEN + 1] = ACE_TEXT ("");
-
-class Employee
-{
-public:
- Employee (void): name_ (0), id_ (0) {}
-
- Employee (const char *name, u_long id) : id_ (id)
- {
- size_t len = ACE_OS::strlen (name) + 1;
- this->name_ = reinterpret_cast<char *> (shmem_allocator->malloc (len));
- ACE_OS::strcpy (this->name_, name);
- }
-
- ~Employee (void) { shmem_allocator->free (this->name_); }
-
- const char *name (void) const { return this->name_; }
-
- void name (const char *name)
- {
- if (this->name_)
- shmem_allocator->free (this->name_);
-
- size_t len = ACE_OS::strlen (name) + 1;
- this->name_ = reinterpret_cast<char *> (shmem_allocator->malloc (len));
- ACE_OS::strcpy (this->name_, name);
- }
-
- u_long id (void) const { return id_; }
-
- void id (u_long id) { id_ = id; }
-
- void *operator new (size_t)
- {
- return shmem_allocator->malloc (sizeof (Employee));
- }
-
-#if defined (ACE_HAS_NEW_NOTHROW)
- void *operator new (size_t, const ACE_nothrow_t&)
- {
- return shmem_allocator->malloc (sizeof (Employee));
- }
-#if !defined (ACE_LACKS_PLACEMENT_OPERATOR_DELETE)
- void operator delete (void *p, const ACE_nothrow_t&) throw ()
- {
- shmem_allocator->free (p);
- }
-#endif /* ACE_LACKS_PLACEMENT_OPERATOR_DELETE */
-#endif
-
- void operator delete (void *pointer)
- {
- shmem_allocator->free (pointer);
- }
-
-private:
- char *name_;
- // Employee name.
-
- u_long id_;
- // Employee ID.
-};
-
-class GUI_Handler
-{
-public:
- GUI_Handler (void) { menu (); }
-
- ~GUI_Handler (void)
- {
- TEST_MALLOC::MEMORY_POOL &pool =
- shmem_allocator->memory_pool ();
- pool.sync ();
- }
-
- int service(void)
- {
- char option[BUFSIZ];
- char buf1[BUFSIZ];
- char buf2[BUFSIZ];
-
- if (::scanf ("%s", option) <= 0)
- {
- ACE_ERROR ((LM_ERROR,
- "try again\n"));
- return 0;
- }
-
- int result = 0;
- switch (option[0])
- {
- case 'I' :
- case 'i' :
- if (::scanf ("%s %s", buf1, buf2) <= 0)
- break;
- result = insert_employee (buf1,
- ACE_OS::atoi (buf2));
- break;
- case 'F' :
- case 'f' :
- if (::scanf ("%s", buf1) <= 0)
- break;
- result = find_employee (buf1);
- break;
- case 'D' :
- case 'd' :
- if (::scanf ("%s", buf1) <= 0)
- break;
- result = delete_employee (buf1);
- break;
- case 'L' :
- case 'l' :
- result = list_employees ();
- break;
- case 'Q' :
- case 'q' :
- return -1;
- ACE_NOTREACHED(break);
- default :
- cout << "unrecognized command" << endl;
- }
- if (result == 0)
- cout << "Last operation was successful!!" << endl;
- else
- cout << "Last operation failed!! " << endl;
-
- menu ();
-
- return 0;
- }
-
- void menu(void)
- {
- cout << endl;
- cout << "\t************************** " << endl;
- cout << "\tThe employee database menu " << endl;
- cout << endl;
- cout << "\t<I> Insert <name> <id> " << endl;
- cout << "\t<D> Delete <name> " << endl;
- cout << "\t<F> Find <name> " << endl;
- cout << endl;
- cout << "\t<L> List all employees " << endl;
- cout << endl;
- cout << "\t<Q> Quit " << endl;
- cout << "\t************************** " << endl;
- }
-
-private:
- int insert_employee (const char *name,
- u_long id);
- int find_employee (const char *name);
- int list_employees (void);
- int delete_employee (const char *name);
-};
-
-int
-GUI_Handler::insert_employee (const char *name,
- u_long id)
-{
- if (find_employee (name) == 0)
- ACE_ERROR_RETURN ((LM_ERROR,
- "Employee already exists\n"),
- -1);
-
- Employee *new_employee = 0;
-
- ACE_NEW_RETURN (new_employee,
- Employee (name, id),
- -1);
-
- if (shmem_allocator->bind (name,
- new_employee) == -1)
- ACE_ERROR_RETURN ((LM_ERROR,
- "bind failed\n"),
- -1);
- return 0;
-}
-
-int
-GUI_Handler::find_employee (const char *name)
-{
- void *temp = 0;
-
- if (shmem_allocator->find (name,
- temp) == 0)
- {
- Employee *employee = reinterpret_cast<Employee *> (temp);
-
- ACE_DEBUG ((LM_DEBUG,
- "The following employee was found.......\n\n"));
- ACE_DEBUG ((LM_DEBUG,
- "Employee name: %s\nEmployee id: %d\n",
- employee->name (),
- employee->id ()));
- return 0;
- }
-
- return -1;
-}
-
-int
-GUI_Handler::list_employees (void)
-{
- ACE_DEBUG ((LM_DEBUG,
- "The following employees were found.......\n\n"));
-
- {
- ACE_DEBUG ((LM_DEBUG,
- "LIFO order:\n"));
- MALLOC_LIFO_ITERATOR iterator (*shmem_allocator);
-
- for (void *temp = 0;
- iterator.next (temp) != 0;
- iterator.advance ())
- {
- Employee *employee = reinterpret_cast<Employee *> (temp);
- ACE_DEBUG ((LM_DEBUG,
- "Employee name: %s\nEmployee id: %d\n",
- employee->name (),
- employee->id ()));
- }
- }
-
- {
- ACE_DEBUG ((LM_DEBUG,
- "FIFO order:\n"));
- MALLOC_FIFO_ITERATOR iterator (*shmem_allocator);
-
- for (void *temp = 0;
- iterator.next (temp) != 0;
- iterator.advance ())
- {
- Employee *employee = reinterpret_cast<Employee *> (temp);
- ACE_DEBUG ((LM_DEBUG,
- "Employee name: %s\nEmployee id: %d\n",
- employee->name (),
- employee->id ()));
- }
- }
- return 0;
-}
-
-int
-GUI_Handler::delete_employee (const char *name)
-{
- void *temp = 0;
-
- if (shmem_allocator->unbind (name,
- temp) == 0)
- {
- Employee *employee = reinterpret_cast<Employee *> (temp);
-
- ACE_DEBUG ((LM_DEBUG,
- "The following employee was found and deleted.......\n\n"));
-
- ACE_DEBUG ((LM_DEBUG,
- "Employee name: %s\nEmployee id: %d\n",
- employee->name (),
- employee->id ()));
-
- delete employee;
- return 0;
- }
-
- ACE_DEBUG ((LM_DEBUG,
- "There is no employee with name %s",
- name));
- return -1;
-}
-
-void
-parse_args (int argc, ACE_TCHAR *argv[])
-{
- if (argc > 1)
- ACE_OS::strcpy (backing_store, argv[1]);
-}
-
-int
-ACE_TMAIN (int argc, ACE_TCHAR *argv[])
-{
- parse_args (argc, argv);
-
- if (ACE_OS::strcmp (backing_store, ACE_TEXT ("")) == 0)
- {
-#if defined (ACE_DEFAULT_BACKING_STORE)
- // Create a temporary file.
- ACE_OS::strcpy (backing_store,
- ACE_DEFAULT_BACKING_STORE);
-#else /* ACE_DEFAULT_BACKING_STORE */
- if (ACE::get_temp_dir (backing_store,
- MAXPATHLEN - 17) == -1) // -17 for ace-malloc-XXXXXX
- {
- ACE_ERROR ((LM_ERROR,
- ACE_TEXT ("Temporary path too long, ")
- ACE_TEXT ("defaulting to current directory\n")));
- backing_store[0] = 0;
- }
-
- // Add the filename to the end
- ACE_OS::strcat (backing_store, ACE_TEXT ("ace-malloc-XXXXXX"));
-
-#endif /* ACE_DEFAULT_BACKING_STORE */
- }
-
- ACE_NEW_RETURN (shmem_allocator,
- TEST_MALLOC (backing_store),
- -1);
-
- GUI_Handler handler;
-
- for (;;)
- if (handler.service () == -1)
- {
- ACE_DEBUG ((LM_DEBUG,
- ACE_TEXT ("closing down ....\n")));
- break;
- }
-
- return 0;
-}
-
diff --git a/examples/Shared_Malloc/test_position_independent_malloc.cpp b/examples/Shared_Malloc/test_position_independent_malloc.cpp
deleted file mode 100644
index b4c66e54957..00000000000
--- a/examples/Shared_Malloc/test_position_independent_malloc.cpp
+++ /dev/null
@@ -1,190 +0,0 @@
-// $Id$
-
-// Test the capability of the "position-independent" <ACE_Malloc> to
-// handle a single malloc that can be rooted at different base
-// addresses each time it's used. The actual backing store used by
-// <ACE_Malloc> is located in a memory-mapped file.
-
-#include "test_position_independent_malloc.h"
-#include "ace/PI_Malloc.h"
-#include "ace/Based_Pointer_T.h"
-#include "ace/Get_Opt.h"
-#include "ace/Auto_Ptr.h"
-#include "ace/Process_Mutex.h"
-#include "ace/Malloc_T.h"
-#include "ace/MMAP_Memory_Pool.h"
-
-ACE_RCSID(Shared_Malloc, test_multiple_mallocs, "$Id$")
-
-#if (ACE_HAS_POSITION_INDEPENDENT_POINTERS == 1)
-typedef ACE_PI_Control_Block CONTROL_BLOCK;
-#else
-typedef ACE_Control_Block CONTROL_BLOCK;
-#endif /* ACE_HAS_POSITION_INDEPENDENT_POINTERS == 1 */
-
-typedef ACE_Malloc_T <ACE_MMAP_MEMORY_POOL, ACE_Process_Mutex, CONTROL_BLOCK> TEST_MALLOC;
-
-// Default address for memory-mapped files.
-static void *base_addr = ACE_DEFAULT_BASE_ADDR;
-
-static void
-print (Test_Data *data)
-{
- for (Test_Data *t = data; t != 0; t = t->next_)
- {
- ACE_DEBUG ((LM_DEBUG,
- "<<<<\ni1_ = %d, i2_ = %d, i3_ = %d\n",
- t->i1_,
- t->i2_,
- t->i3_));
- ACE_DEBUG ((LM_DEBUG,
- "*t->bpl_ = %d, t->long_test_->array_[0] = %d\n>>>>\n",
- *t->long_test_->bpl_,
- t->long_test_->array_[0]));
- }
-}
-
-static void *
-initialize (TEST_MALLOC *allocator)
-{
- void *ptr;
- ACE_ALLOCATOR_RETURN (ptr,
- allocator->malloc (sizeof (Test_Data)),
- 0);
- Test_Data *data1 = new (ptr) Test_Data;
-
- data1->i1_ = 111;
- data1->i2_ = 222;
- data1->i3_ = 333;
-
- void *gap = 0;
- ACE_ALLOCATOR_RETURN (gap,
- allocator->malloc (sizeof (256)),
- 0);
-
- allocator->free (gap);
-
- ACE_ALLOCATOR_RETURN (ptr,
- allocator->malloc (sizeof (Test_Data)),
- 0);
- Test_Data *data2 = new (ptr) Test_Data;
-
- data1->next_ = 0;
- data1->i1_ = 111;
- data1->i2_ = 222;
- data1->i3_ = 333;
- data2->next_ = data1;
- data2->i1_ = -111;
- data2->i2_ = -222;
- data2->i3_ = -333;
-
- // Test in shared memory using long (array/pointer)
- ACE_ALLOCATOR_RETURN (ptr,
- allocator->malloc (sizeof (Long_Test)),
- 0);
- Long_Test *lt = new (ptr) Long_Test;
-
- lt->array_[0] = 1000;
- lt->array_[1] = 1001;
- lt->array_[2] = 1002;
- lt->array_[3] = 1003;
- lt->array_[4] = 1004;
- lt->bpl_ = lt->array_;
-
- data1->long_test_= lt;
-
- ACE_ASSERT (*lt->bpl_ == 1000);
- ACE_ASSERT (lt->bpl_[3] == 1003);
-
- ACE_ALLOCATOR_RETURN (ptr,
- allocator->malloc (sizeof (Long_Test)),
- 0);
- lt = new (ptr) Long_Test;
-
- lt->array_[0] = 2000;
- lt->array_[1] = 2001;
- lt->array_[2] = 2002;
- lt->array_[3] = 2003;
- lt->array_[4] = 2004;
- lt->bpl_ = lt->array_;
-
- data2->long_test_= lt;
-
- ACE_ASSERT (*lt->bpl_ == 2000);
- ACE_ASSERT (lt->bpl_[4] == 2004);
-
- return data2;
-}
-
-static void
-parse_args (int argc, ACE_TCHAR *argv[])
-{
- ACE_Get_Opt get_opt (argc, argv, ACE_TEXT("a:T"));
-
- for (int c;
- (c = get_opt ()) != -1;
- )
- {
- switch (c)
- {
- case 'a':
- // Override the default base address.
- base_addr = reinterpret_cast<void *> (ACE_OS::atoi (get_opt.opt_arg ()));
- break;
- case 'T':
-#if defined (ACE_HAS_TRACE)
- ACE_Trace::start_tracing ();
-#endif /* ACE_HAS_TRACE */
- break;
- }
- }
-}
-
-int
-ACE_TMAIN (int argc, ACE_TCHAR *argv[])
-{
- parse_args (argc, argv);
-
- ACE_MMAP_Memory_Pool_Options options (base_addr);
-
- // Create an allocator.
- TEST_MALLOC *ptr = 0;
- ACE_NEW_RETURN (ptr,
- TEST_MALLOC (ACE_TEXT("test_file"),
- ACE_TEXT("test_lock"),
- &options),
- 1);
- auto_ptr <TEST_MALLOC> allocator (ptr);
- void *data = 0;
-
- // This is the first time in, so we allocate the memory and bind it
- // to the name "foo".
- if (allocator->find ("foo",
- data) == -1)
- {
- data = initialize (allocator.get ());
-
- if (allocator->bind ("foo",
- data) == -1)
- ACE_ERROR_RETURN ((LM_ERROR,
- "%p\n",
- "bind"),
- 1);
-
- ACE_DEBUG ((LM_DEBUG,
- "Run again to see results and release resources.\n"));
- }
- // If we find "foo" then we're running the "second" time, so we must
- // release the resources.
- else
- {
- print ((Test_Data *) data);
- allocator->free (data);
- allocator->remove ();
- ACE_DEBUG ((LM_DEBUG,
- "all resources released\n"));
- }
-
- return 0;
-}
-
diff --git a/examples/Shared_Malloc/test_position_independent_malloc.h b/examples/Shared_Malloc/test_position_independent_malloc.h
deleted file mode 100644
index 2785a386045..00000000000
--- a/examples/Shared_Malloc/test_position_independent_malloc.h
+++ /dev/null
@@ -1,28 +0,0 @@
-// $Id$
-//
-// Define struct used in test_position_independent_malloc.cpp - needs
-// to be in a separate file for template generation on AIX IBM C++.
-
-#ifndef __TEST_POSITION_INDEPENDENT_MALLOC_H
-#define __TEST_POSITION_INDEPENDENT_MALLOC_H
-
-#include "ace/Based_Pointer_T.h"
-
-// Some test data.
-struct Long_Test
-{
- ACE_Based_Pointer_Basic<long> bpl_;
- long array_[10];
-};
-
-// Some more test data.
-struct Test_Data
-{
- int i1_;
- int i2_;
- int i3_;
- ACE_Based_Pointer<Test_Data> next_;
- ACE_Based_Pointer<Long_Test> long_test_;
-};
-
-#endif /* __TEST_POSITION_INDEPENDENT_MALLOC */