Public Types | Public Member Functions | Static Public Member Functions | Static Public Attributes | Private Member Functions | Private Attributes | Static Private Attributes | Friends

ACE_Object_Manager Class Reference

Manager for ACE library services and singleton cleanup. More...

#include <Object_Manager.h>

Inheritance diagram for ACE_Object_Manager:
Inheritance graph
[legend]
Collaboration diagram for ACE_Object_Manager:
Collaboration graph
[legend]

List of all members.

Public Types

enum  Preallocated_Object { ACE_FILECACHE_LOCK, ACE_PREALLOCATED_OBJECTS }
enum  Preallocated_Array { ACE_EMPTY_PREALLOCATED_ARRAY, ACE_PREALLOCATED_ARRAYS }

Public Member Functions

virtual int init (void)
virtual int fini (void)
 ACE_Object_Manager (void)
 ~ACE_Object_Manager (void)

Static Public Member Functions

static int starting_up (void)
static int shutting_down (void)
static int at_exit (ACE_Cleanup *object, void *param=0, const char *name=0)
static int at_exit (void *object, ACE_CLEANUP_FUNC cleanup_hook, void *param, const char *name=0)
static int remove_at_exit (void *object)
static ACE_Sig_Setdefault_mask (void)
static ACE_Object_Managerinstance (void)

Static Public Attributes

static void * preallocated_object [ACE_PREALLOCATED_OBJECTS] = { 0 }
 Table of preallocated objects.
static void * preallocated_array [ACE_PREALLOCATED_ARRAYS] = { 0 }
 Table of preallocated arrays.

Private Member Functions

int at_exit_i (void *object, ACE_CLEANUP_FUNC cleanup_hook, void *param, const char *name)
int remove_at_exit_i (void *object)
 ACE_Object_Manager (const ACE_Object_Manager &)
 Disallow copying by not implementing the following . . .
ACE_Object_Manageroperator= (const ACE_Object_Manager &)

Private Attributes

ACE_OS_Exit_Info exit_info_
 For at_exit support.
ACE_Object_Manager_Preallocationspreallocations_
 Preallocated objects collection.
ACE_Sig_Adapterace_service_config_sig_handler_
 ACE_Service_Config signal handler.

Static Private Attributes

static ACE_Object_Managerinstance_ = 0
 Singleton pointer.

Friends

class ACE_Object_Manager_Manager

Detailed Description

Manager for ACE library services and singleton cleanup.

The ACE_Object_Manager manages cleanup of objects, typically singletons, at program termination. In addition to managing the cleanup of the ACE library, it provides an interface for application to register objects to be cleaned up. This class also shuts down ACE library services, so that they can reclaim their storage, at program termination. It works by creating a static instance whose destructor gets called along with those of all other static objects. Hooks are provided for application code to register objects and arrays for cleanup, e.g., destruction. The order of such cleanup calls is in the reverse order of registration, i.e., that last object/array to register gets cleaned up first. The ACE_Object_Manager API includes ACE_Managed_Object. That class is contained in a separate file because it is a template class, and some compilers require that template and non-template class definitions appear in separate files. Please see ace/Managed_Object.h for a description of that part of the API. In summary, ACE_Managed_Object provides two adapters, the ACE_Cleanup_Adapter and ACE_Managed_Object template classes for adapting objects of any type to be easily managed by the ACE_Object_Manager. There are several mechanisms for adapting objects and arrays for cleanup at program termination, in roughly increasing order of ease-of-use: 1) Derive the object's class from ACE_Cleanup. 2) Allow the ACE_Object_Manager to both dynamically allocate and deallocate the object. 3) Provide an <ACE_CLEANUP_FUNC> cleanup hook for the object or array. 4) Allow the ACE_Object_Manager to both preallocate the object or array, either statically in global data or dynamically on the heap, when its singleton instance is construction.

There are also several mechanisms for registering objects and arrays for cleanup. In decreasing order of flexibility and complexity (with the exception of the last mechanism):

1) ACE_Object_Manager::at_exit (void *object, ACE_CLEANUP_FUNC cleanup_hook, void *param); can be used to register any object or array for any cleanup activity at program termination. 2) ACE_Object_Manager::at_exit (ACE_Cleanup *object, void *param = 0); can be used to register an ACE_Cleanup object for any cleanup activity at program termination. The final mechanism is not general purpose, but can only be used to allocate objects and arrays at program startup: 3) ACE_Managed_Object::get_preallocated_object (ACE_Object_Manager::Preallocated_Object id); and ACE_Managed_Object::get_preallocated_array (ACE_Object_Manager::Preallocated_Array id); can only be used to allocate objects at program startup, either in global data or on the heap (selected at compile time). These are intended to replace static locks, etc. Instead of creating a static ACE_Object_Manager instance, one can alternatively be created on the stack of the main program thread. It is created just after entry to main (int, char *[]), and before any existing code in that function is executed. To enable this alternative, add define ACE_HAS_NONSTATIC_OBJECT_MANAGER before including the platform specific config-* file in ace/config.h prior to building the ACE library and your applications. This define is enabled in some config files that are supplied with ACE.

To ensure a static object manager is used, undef ACE_HAS_NONSTATIC_OBJECT_MANAGER *after* including the platform specific config-* file. Note that the ACE_Object_Manager _must_ be created before any threads are spawned by the program. If ACE_HAS_NONSTATIC_OBJECT_MANAGER is not defined, the ACE library creates a static, singleton ACE_Object_Manager instance. The instance is placed in global program data, and constructed via a static object constructor. If ACE_HAS_NONSTATIC_OBJECT_MANAGER is defined, the ACE_Object_Manager instance is created on the stack of the main program thread, as noted above.

With ACE_HAS_NONSTATIC_OBJECT_MANAGER enabled, the ACE library has no static objects that require destruction. However, there are two drawbacks to using it: 1) main (int, char *[]) must be declared with arguments, even if they're not used. All of ACE is converted to this, so just applications have to be concerned with it. 2) If there any static objects that depend on those that are cleaned up by the Object_Manager, they'll get cleaned up too late. The ACE tests do not violate this requirement. However, applications may have trouble with it. NOTE on the use of <exit> -- <exit> does not destroy automatic objects. Therefore, if ACE_HAS_NONSTATIC_OBJECT_MANAGER is enabled, the ACE_Object_Manager instance will *not* be destroyed if <exit> is called! However, <ACE_OS::exit> will properly destroy the ACE_Object_Manager. It is highly recommended that <ACE_OS::exit> be used instead of <exit>.

However, <exit> and <ACE_OS::exit> are tricky to use properly, especially in multithread programs. It is much safer to throw an exception (or simulate that effect) that will be caught by <main> instead of calling exit. Then, <main> can perform any necessary application-specific cleanup and return the status value. In addition, it's usually best to avoid calling <exit> and <ACE_OS::exit> from threads other than the main thread. Thanks to Jeff Greif <jmg@trivida.com> for pointing out that <exit> doesn't destroy automatic objects, and for developing the recommendations in this paragraph.

Instead of creating a static ACE_Object_Manager, or letting ACE create it on the stack of <main> for you, another alternative is to define ACE_DOESNT_INSTANTIATE_NONSTATIC_OBJECT_MANAGER. With that define, the application must create the ACE_Object_Manager. The recommended way is to call <ACE::init> at the start of the program, and call <ACE::fini> at the end. Alternatively, the application could explicity construct an ACE_Object_Manager.

Definition at line 198 of file Object_Manager.h.


Member Enumeration Documentation

Unique identifiers for preallocated arrays. Please see ace/Managed_Object.h for information on accessing preallocated arrays.

Enumerator:
ACE_EMPTY_PREALLOCATED_ARRAY 

There currently are no preallocated arrays in the ACE library. If the application doesn't have any, make sure the the preallocated_array size is at least one by declaring this dummy . . .

ACE_PREALLOCATED_ARRAYS 

Hook for preallocated arrays provided by application.

Definition at line 315 of file Object_Manager.h.

    {
      /// There currently are no preallocated arrays in the ACE
      /// library.  If the application doesn't have any, make sure
      /// the the preallocated_array size is at least one by declaring
      /// this dummy . . .
      ACE_EMPTY_PREALLOCATED_ARRAY,

      /// Hook for preallocated arrays provided by application.
      ACE_APPLICATION_PREALLOCATED_ARRAY_DECLARATIONS

      ACE_PREALLOCATED_ARRAYS  // This enum value must be last!
    };

Unique identifiers for preallocated objects. Please see ace/Managed_Object.h for information on accessing preallocated objects.

Enumerator:
ACE_FILECACHE_LOCK 
ACE_PREALLOCATED_OBJECTS 

Definition at line 286 of file Object_Manager.h.

    {
      ACE_FILECACHE_LOCK,
#if defined (ACE_HAS_THREADS)
      ACE_STATIC_OBJECT_LOCK,
#endif /* ACE_HAS_THREADS */
#if defined (ACE_MT_SAFE) && (ACE_MT_SAFE != 0)
      ACE_MT_CORBA_HANDLER_LOCK,
      ACE_DUMP_LOCK,
      ACE_SIG_HANDLER_LOCK,
      ACE_SINGLETON_NULL_LOCK,
      ACE_SINGLETON_RECURSIVE_THREAD_LOCK,
      ACE_THREAD_EXIT_LOCK,
#if !defined (ACE_LACKS_ACE_TOKEN)
      ACE_TOKEN_MANAGER_CREATION_LOCK,
      ACE_TOKEN_INVARIANTS_CREATION_LOCK,
#endif /* ! ACE_LACKS_ACE_TOKEN */
      ACE_PROACTOR_EVENT_LOOP_LOCK,
#endif /* ACE_MT_SAFE */

      // Hook for preallocated objects provided by application.
      ACE_APPLICATION_PREALLOCATED_OBJECT_DECLARATIONS

      ACE_PREALLOCATED_OBJECTS  // This enum value must be last!
    };


Constructor & Destructor Documentation

ACE_Object_Manager::ACE_Object_Manager ( void   ) 

Application code should not use these explicitly, so they're hidden here. They're public so that the ACE_Object_Manager can be constructed/destructed in <main> with ACE_HAS_NONSTATIC_OBJECT_MANAGER.

Definition at line 378 of file Object_Manager.cpp.

  : exit_info_ ()
#if !defined (ACE_LACKS_ACE_SVCCONF)
  , preallocations_ (0)
  , ace_service_config_sig_handler_ (0)
#endif /* ! ACE_LACKS_ACE_SVCCONF */
#if defined (ACE_MT_SAFE) && (ACE_MT_SAFE != 0)
  , singleton_null_lock_ (0)
  , singleton_recursive_lock_ (0)
#endif /* ACE_MT_SAFE */
#if defined (ACE_HAS_TSS_EMULATION)
  , ts_storage_initialized_ (false)
#endif
{
#if defined (ACE_MT_SAFE) && (ACE_MT_SAFE != 0)
  ACE_NEW (internal_lock_, ACE_Recursive_Thread_Mutex);
# endif /* ACE_MT_SAFE */

  // If instance_ was not 0, then another ACE_Object_Manager has
  // already been instantiated (it is likely to be one initialized by way
  // of library/DLL loading).  Let this one go through construction in
  // case there really is a good reason for it (like, ACE is a static/archive
  // library, and this one is the non-static instance (with
  // ACE_HAS_NONSTATIC_OBJECT_MANAGER, or the user has a good reason for
  // creating a separate one) but the original one will be the one retrieved
  // from calls to ACE_Object_Manager::instance().

  // Be sure that no further instances are created via instance ().
  if (instance_ == 0)
    instance_ = this;

  init ();
}

ACE_Object_Manager::~ACE_Object_Manager ( void   ) 

Definition at line 414 of file Object_Manager.cpp.

{
  dynamically_allocated_ = false;   // Don't delete this again in fini()
  fini ();
}

ACE_Object_Manager::ACE_Object_Manager ( const ACE_Object_Manager  )  [private]

Disallow copying by not implementing the following . . .


Member Function Documentation

int ACE_Object_Manager::at_exit ( ACE_Cleanup object,
void *  param = 0,
const char *  name = 0 
) [inline, static]

Register an ACE_Cleanup object for cleanup at process termination. The object is deleted via the <ace_cleanup_destroyer>. If you need more flexiblity, see the other at_exit method below. For OS's that do not have processes, cleanup takes place at the end of <main>. Returns 0 on success. On failure, returns -1 and sets errno to: EAGAIN if shutting down, ENOMEM if insufficient virtual memory, or EEXIST if the object (or array) had already been registered.

Definition at line 9 of file Object_Manager.inl.

int ACE_Object_Manager::at_exit ( void *  object,
ACE_CLEANUP_FUNC  cleanup_hook,
void *  param,
const char *  name = 0 
) [inline, static]

Register an object (or array) for cleanup at process termination. "cleanup_hook" points to a (global, or static member) function that is called for the object or array when it to be destroyed. It may perform any necessary cleanup specific for that object or its class. "param" is passed as the second parameter to the cleanup_hook function; the first parameter is the object (or array) to be destroyed. cleanup_hook, for example, may delete the object (or array). For OS's that do not have processes, this function is the same as <at_thread_exit>. Returns 0 on success. On failure, returns -1 and sets errno to: EAGAIN if shutting down, ENOMEM if insufficient virtual memory, or EEXIST if the object (or array) had already been registered.

Definition at line 22 of file Object_Manager.inl.

{
  return ACE_Object_Manager::instance ()->at_exit_i (
    object,
    cleanup_hook,
    param,
    name);
}

int ACE_Object_Manager::at_exit_i ( void *  object,
ACE_CLEANUP_FUNC  cleanup_hook,
void *  param,
const char *  name 
) [private]

Register an object or array for deletion at program termination. See description of static version above for return values.

Definition at line 445 of file Object_Manager.cpp.

{
  ACE_MT (ACE_GUARD_RETURN (ACE_Recursive_Thread_Mutex, ace_mon,
    *instance_->internal_lock_, -1));

  if (shutting_down_i ())
    {
      errno = EAGAIN;
      return -1;
    }

  if (exit_info_.find (object))
    {
      // The object has already been registered.
      errno = EEXIST;
      return -1;
    }

  return exit_info_.at_exit_i (object, cleanup_hook, param, name);
}

ACE_Sig_Set & ACE_Object_Manager::default_mask ( void   )  [inline, static]
Deprecated:
Accesses a default signal set used, for example, in ACE_Sig_Guard methods. Deprecated: use ACE_Object_Manager::default_mask () instead.

Definition at line 43 of file Object_Manager.inl.

{
  // A safe cast, but this static method shouldn't be used anyways.
  // Use ACE_Object_Manager::default_mask () instead.
  return
    *reinterpret_cast<ACE_Sig_Set *> (ACE_OS_Object_Manager::default_mask ());
}

int ACE_Object_Manager::fini ( void   )  [virtual]

Explicitly destroy the singleton instance of the ACE_Object_Manager. Returns 0 on success, -1 on failure, and 1 if it had already been called.

Implements ACE_Object_Manager_Base.

Definition at line 710 of file Object_Manager.cpp.

{
  if (shutting_down_i ())
    // Too late.  Or, maybe too early.  Either fini () has already
    // been called, or init () was never called.
    return object_manager_state_ == OBJ_MAN_SHUT_DOWN  ?  1  :  -1;

  // No mutex here.  Only the main thread should destroy the singleton
  // ACE_Object_Manager instance.

  // Indicate that this ACE_Object_Manager instance is being
  // shut down.
  object_manager_state_ = OBJ_MAN_SHUTTING_DOWN;

  // Call all registered cleanup hooks, in reverse order of
  // registration.
  exit_info_.call_hooks ();

  if (this == instance_)
    {
#if !defined (ACE_LACKS_ACE_SVCCONF)
      delete preallocations_;
      preallocations_ = 0;
#endif /* ! ACE_LACKS_ACE_SVCCONF */

#if defined (ACE_HAS_TRACE)
      ACE_Trace::stop_tracing ();
#endif /* ACE_HAS_TRACE */

#if !defined (ACE_LACKS_ACE_SVCCONF)
      // Close and possibly delete all service instances in the Service
      // Repository.
      ACE_Service_Config::fini_svcs ();

      // Unlink all services in the Service Repository and close/delete
      // all ACE library services and singletons.
      ACE_Service_Config::close ();
#endif /* ! ACE_LACKS_ACE_SVCCONF */

      // This must come after closing ACE_Service_Config, since it will
      // close down it's dlls--it manages ACE_DLL_Manager.
      ACE_Framework_Repository::close_singleton ();
      ACE_DLL_Manager::close_singleton ();

#  if ! defined (ACE_THREAD_MANAGER_LACKS_STATICS)
      ACE_Thread_Manager::close_singleton ();
#  endif /* ! ACE_THREAD_MANAGER_LACKS_STATICS */

      // Close the main thread's TSS, including its Log_Msg instance.
      ACE_OS::cleanup_tss (1 /* main thread */);

      //
      // Note:  Do not access Log Msg after this since it is gone
      //

      // Close the ACE_Allocator.
      ACE_Allocator::close_singleton ();

#if ! defined (ACE_HAS_STATIC_PREALLOCATION)
      // Hooks for deletion of preallocated objects and arrays provided by
      // application.
      ACE_APPLICATION_PREALLOCATED_ARRAY_DELETIONS
      ACE_APPLICATION_PREALLOCATED_OBJECT_DELETIONS

      // Cleanup the dynamically preallocated arrays.
      // (none)

      // Cleanup the dynamically preallocated objects.
      ACE_DELETE_PREALLOCATED_OBJECT (ACE_SYNCH_RW_MUTEX, ACE_FILECACHE_LOCK)
#if defined (ACE_HAS_THREADS)
      ACE_DELETE_PREALLOCATED_OBJECT (ACE_Recursive_Thread_Mutex,
                                      ACE_STATIC_OBJECT_LOCK)
#endif /* ACE_HAS_THREADS */
# if defined (ACE_MT_SAFE) && (ACE_MT_SAFE != 0)
      ACE_DELETE_PREALLOCATED_OBJECT (ACE_Thread_Mutex,
                                      ACE_MT_CORBA_HANDLER_LOCK)
      ACE_DELETE_PREALLOCATED_OBJECT (ACE_Thread_Mutex, ACE_DUMP_LOCK)
      ACE_DELETE_PREALLOCATED_OBJECT (ACE_Recursive_Thread_Mutex,
                                      ACE_SIG_HANDLER_LOCK)
      ACE_DELETE_PREALLOCATED_OBJECT (ACE_Null_Mutex,
                                      ACE_SINGLETON_NULL_LOCK)
      ACE_DELETE_PREALLOCATED_OBJECT (ACE_Recursive_Thread_Mutex,
                                      ACE_SINGLETON_RECURSIVE_THREAD_LOCK)
      ACE_DELETE_PREALLOCATED_OBJECT (ACE_Thread_Mutex, ACE_THREAD_EXIT_LOCK)
#if !defined (ACE_LACKS_ACE_TOKEN) && defined (ACE_HAS_TOKENS_LIBRARY)
      ACE_DELETE_PREALLOCATED_OBJECT (ACE_TOKEN_CONST::MUTEX,
                                      ACE_TOKEN_MANAGER_CREATION_LOCK)
      ACE_DELETE_PREALLOCATED_OBJECT (ACE_TOKEN_CONST::MUTEX,
                                      ACE_TOKEN_INVARIANTS_CREATION_LOCK)
#endif /* ! ACE_LACKS_ACE_TOKEN && ACE_HAS_TOKENS_LIBRARY */
      ACE_DELETE_PREALLOCATED_OBJECT (ACE_Thread_Mutex,
                                      ACE_PROACTOR_EVENT_LOOP_LOCK)
# endif /* ACE_MT_SAFE */
#endif /* ! ACE_HAS_STATIC_PREALLOCATION */

#if defined (ACE_HAS_THREADS)
      ACE_Static_Object_Lock::cleanup_lock ();
#endif /* ACE_HAS_THREADS */
    }

#if !defined (ACE_LACKS_ACE_SVCCONF)
  delete ace_service_config_sig_handler_;
  ace_service_config_sig_handler_ = 0;
#endif /* ! ACE_LACKS_ACE_SVCCONF */

#if defined (ACE_MT_SAFE) && (ACE_MT_SAFE != 0)
  delete internal_lock_;
  internal_lock_ = 0;

  delete singleton_null_lock_;
  singleton_null_lock_ = 0;

  delete singleton_recursive_lock_;
  singleton_recursive_lock_ = 0;
#endif /* ACE_MT_SAFE */

  // Indicate that this ACE_Object_Manager instance has been shut down.
  object_manager_state_ = OBJ_MAN_SHUT_DOWN;

  // Then, ensure that the ACE_OS_Object_Manager gets shut down.
  if (this == instance_ && ACE_OS_Object_Manager::instance_)
    ACE_OS_Object_Manager::instance_->fini ();

  if (dynamically_allocated_)
    {
      delete this;
    }

  if (this == instance_)
    instance_ = 0;

  return 0;
}

int ACE_Object_Manager::init ( void   )  [virtual]

Explicitly initialize (construct the singleton instance of) the ACE_Object_Manager. Returns 0 on success, -1 on failure, and 1 if it had already been called.

Implements ACE_Object_Manager_Base.

Definition at line 193 of file Object_Manager.cpp.

{
  if (starting_up_i ())
    {
      // First, indicate that the ACE_Object_Manager instance is being
      // initialized.
      object_manager_state_ = OBJ_MAN_INITIALIZING;

      // Only The Instance sets up with ACE_OS_Object_Manager and initializes
      // the preallocated objects.
      if (this == instance_)
        {
          // Make sure that the ACE_OS_Object_Manager has been created,
          // and register with it for chained fini ().
          ACE_OS_Object_Manager::instance ()->next_ = this;

#     if defined (ACE_HAS_BUILTIN_ATOMIC_OP)
          ACE_Atomic_Op<ACE_Thread_Mutex, long>::init_functions ();
          ACE_Atomic_Op<ACE_Thread_Mutex, unsigned long>::init_functions ();
#     endif /* ACE_HAS_BUILTIN_ATOMIC_OP */

#     if !defined (ACE_LACKS_ACE_SVCCONF)
          // Construct the ACE_Service_Config's signal handler.
          ACE_NEW_RETURN (ace_service_config_sig_handler_,
                     ACE_Sig_Adapter (&ACE_Service_Config::handle_signal), -1);
          ACE_Service_Config::signal_handler (ace_service_config_sig_handler_);
#     endif /* ! ACE_LACKS_ACE_SVCCONF */

          // Allocate the preallocated (hard-coded) object instances.
          ACE_PREALLOCATE_OBJECT (ACE_SYNCH_RW_MUTEX, ACE_FILECACHE_LOCK)
#     if defined (ACE_HAS_THREADS)
          ACE_PREALLOCATE_OBJECT (ACE_Recursive_Thread_Mutex,
                                  ACE_STATIC_OBJECT_LOCK)
#     endif /* ACE_HAS_THREADS */
#     if defined (ACE_MT_SAFE) && (ACE_MT_SAFE != 0)
          ACE_PREALLOCATE_OBJECT (ACE_Thread_Mutex,
                                  ACE_MT_CORBA_HANDLER_LOCK)
          ACE_PREALLOCATE_OBJECT (ACE_Thread_Mutex, ACE_DUMP_LOCK)
          ACE_PREALLOCATE_OBJECT (ACE_Recursive_Thread_Mutex,
                                  ACE_SIG_HANDLER_LOCK)
          ACE_PREALLOCATE_OBJECT (ACE_Null_Mutex, ACE_SINGLETON_NULL_LOCK)
          ACE_PREALLOCATE_OBJECT (ACE_Recursive_Thread_Mutex,
                                  ACE_SINGLETON_RECURSIVE_THREAD_LOCK)
          ACE_PREALLOCATE_OBJECT (ACE_Thread_Mutex, ACE_THREAD_EXIT_LOCK)
#if !defined (ACE_LACKS_ACE_TOKEN) && defined (ACE_HAS_TOKENS_LIBRARY)
          ACE_PREALLOCATE_OBJECT (ACE_TOKEN_CONST::MUTEX,
                                  ACE_TOKEN_MANAGER_CREATION_LOCK)
          ACE_PREALLOCATE_OBJECT (ACE_TOKEN_CONST::MUTEX,
                                  ACE_TOKEN_INVARIANTS_CREATION_LOCK)
#endif /* ! ACE_LACKS_ACE_TOKEN && ACE_HAS_TOKENS_LIBRARY */
          ACE_PREALLOCATE_OBJECT (ACE_Thread_Mutex,
                                  ACE_PROACTOR_EVENT_LOOP_LOCK)
#     endif /* ACE_MT_SAFE */
        }

      if (this == instance_)
        {
          // Hooks for preallocated objects and arrays provided by application.
          ACE_APPLICATION_PREALLOCATED_OBJECT_DEFINITIONS
          ACE_APPLICATION_PREALLOCATED_ARRAY_DEFINITIONS

#     if defined (ACE_HAS_TSS_EMULATION)
          // Initialize the main thread's TS storage.
          if (!ts_storage_initialized_)
            {
              ACE_TSS_Emulation::tss_open (ts_storage_);
              ts_storage_initialized_ = true;
            }
#     endif /* ACE_HAS_TSS_EMULATION */

#if defined (ACE_DISABLE_WIN32_ERROR_WINDOWS) && \
    defined (ACE_WIN32) && !defined (ACE_HAS_WINCE)
#if defined (_DEBUG) && (defined (_MSC_VER) || defined (__INTEL_COMPILER))
          _CrtSetReportMode( _CRT_ERROR, _CRTDBG_MODE_FILE );
          _CrtSetReportFile( _CRT_ERROR, _CRTDBG_FILE_STDERR );
          _CrtSetReportMode( _CRT_ASSERT, _CRTDBG_MODE_FILE );
          _CrtSetReportFile( _CRT_ASSERT, _CRTDBG_FILE_STDERR );
#endif /* _DEBUG && _MSC_VER || __INTEL_COMPILER */

          // The system does not display the critical-error-handler message box
          SetErrorMode(SEM_FAILCRITICALERRORS);

          // And this will catch all unhandled exceptions.
          SetUnhandledExceptionFilter (&ACE_UnhandledExceptionFilter);

#  if (_MSC_VER >= 1400) // VC++ 8.0 and above.
          // And this will stop the abort system call from being treated as a crash
          _set_abort_behavior( 0,  _CALL_REPORTFAULT);

  // Note the following fix was derived from that proposed by Jochen Kalmbach
  // http://blog.kalmbachnet.de/?postid=75
  // See also:
  // http://connect.microsoft.com/VisualStudio/feedback/ViewFeedback.aspx?FeedbackID=101337
  //
  // Starting with VC8 (VS2005), Microsoft changed the behaviour of the CRT in some
  // security related and special situations. The are many situations in which our
  // ACE_UnhandledExceptionFilter will never be called. This is a major change to
  // the previous versions of the CRT and is not very well documented.
  // The CRT simply forces the call to the default-debugger without informing the
  // registered unhandled exception filter. Jochen's solution is to stop the CRT
  // from calling SetUnhandledExceptionFilter() after we have done so above.
  // NOTE this only works for intel based windows builds.

#    ifdef _M_IX86
          HMODULE hKernel32 = ACE_TEXT_LoadLibrary (ACE_TEXT ("kernel32.dll"));
          if (hKernel32)
            {
              void *pOrgEntry =
                GetProcAddress (hKernel32, "SetUnhandledExceptionFilter");
              if (pOrgEntry)
                {
                  unsigned char newJump[ 100 ];
                  DWORD dwOrgEntryAddr = reinterpret_cast<DWORD> (pOrgEntry);
                  dwOrgEntryAddr += 5; // add 5 for 5 op-codes for jmp far
                  void *pNewFunc = &ACEdisableSetUnhandledExceptionFilter;
                  DWORD dwNewEntryAddr = reinterpret_cast<DWORD> (pNewFunc);
                  DWORD dwRelativeAddr = dwNewEntryAddr - dwOrgEntryAddr;

                  newJump[ 0 ] = 0xE9;  // JMP absolute
                  ACE_OS::memcpy (&newJump[ 1 ], &dwRelativeAddr, sizeof (pNewFunc));
                  SIZE_T bytesWritten;
                  WriteProcessMemory (
                    GetCurrentProcess (),
                    pOrgEntry,
                    newJump,
                    sizeof (pNewFunc) + 1,
                    &bytesWritten);
                }
            }
#    endif // _M_IX86
#  endif // (_MSC_VER >= 1400) // VC++ 8.0 and above.
#endif /* ACE_DISABLE_WIN32_ERROR_WINDOWS && ACE_WIN32 && !ACE_HAS_WINCE */


#     if !defined (ACE_LACKS_ACE_SVCCONF)
          ACE_NEW_RETURN (preallocations_,
                          ACE_Object_Manager_Preallocations,
                          -1);
#     endif /* ! ACE_LACKS_ACE_SVCCONF */

          // Open the main thread's ACE_Log_Msg.
          if (0 == ACE_LOG_MSG)
            return -1;
        }

      // Finally, indicate that the ACE_Object_Manager instance has
      // been initialized.
      object_manager_state_ = OBJ_MAN_INITIALIZED;

#if defined (ACE_HAS_TRACE)
      // Allow tracing again (useful if user does init/fini/init)
      ACE_Trace::start_tracing ();
#endif /* ACE_HAS_TRACE */

      return 0;
    } else {
      // Had already initialized.
      return 1;
    }
}

ACE_Object_Manager * ACE_Object_Manager::instance ( void   )  [static]

Accessor to singleton instance. Because static member functions are provided in the interface, this should not be public. However, it is public so that ACE_Managed_Object<TYPE> can access it.

Definition at line 421 of file Object_Manager.cpp.

{
  // This function should be called during construction of static
  // instances, or before any other threads have been created in
  // the process.  So, it's not thread safe.

  if (instance_ == 0)
    {
      ACE_Object_Manager *instance_pointer = 0;

      ACE_NEW_RETURN (instance_pointer,
                      ACE_Object_Manager,
                      0);
      ACE_ASSERT (instance_pointer == instance_);

      instance_pointer->dynamically_allocated_ = true;

      return instance_pointer;
    }
  else
    return instance_;
}

ACE_Object_Manager& ACE_Object_Manager::operator= ( const ACE_Object_Manager  )  [private]
int ACE_Object_Manager::remove_at_exit ( void *  object  )  [inline, static]

Definition at line 36 of file Object_Manager.inl.

int ACE_Object_Manager::remove_at_exit_i ( void *  object  )  [private]

Remove an object for deletion at program termination. See description of static version above for return values.

Definition at line 470 of file Object_Manager.cpp.

{
  ACE_MT (ACE_GUARD_RETURN (ACE_Recursive_Thread_Mutex, ace_mon,
    *instance_->internal_lock_, -1));

  if (shutting_down_i ())
    {
      errno = EAGAIN;
      return -1;
    }

  return exit_info_.remove (object);
}

int ACE_Object_Manager::shutting_down ( void   )  [static]

Returns 1 after the ACE_Object_Manager has been destroyed. This flag can be used to determine if the program is in the midst of destroying static objects. (Note that the program might destroy some static objects before this flag can return 1, if ACE_HAS_NONSTATIC_OBJECT_MANAGER is not defined.)

Definition at line 167 of file Object_Manager.cpp.

int ACE_Object_Manager::starting_up ( void   )  [static]

Returns 1 before the ACE_Object_Manager has been constructed. This flag can be used to determine if the program is constructing static objects. If no static object spawns any threads, the program will be single-threaded when this flag returns 1. (Note that the program still might construct some static objects when this flag returns 0, if ACE_HAS_NONSTATIC_OBJECT_MANAGER is not defined.)

Definition at line 161 of file Object_Manager.cpp.


Friends And Related Function Documentation

friend class ACE_Object_Manager_Manager [friend]

Definition at line 445 of file Object_Manager.h.


Member Data Documentation

ACE_Service_Config signal handler.

Definition at line 346 of file Object_Manager.h.

For at_exit support.

Definition at line 339 of file Object_Manager.h.

Singleton pointer.

Definition at line 424 of file Object_Manager.h.

void * ACE_Object_Manager::preallocated_array = { 0 } [static]

Table of preallocated arrays.

Definition at line 412 of file Object_Manager.h.

void * ACE_Object_Manager::preallocated_object = { 0 } [static]

Table of preallocated objects.

Definition at line 409 of file Object_Manager.h.

Preallocated objects collection.

Definition at line 343 of file Object_Manager.h.


The documentation for this class was generated from the following files:
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines