diff options
author | Michi Henning <michi@zeroc.com> | 2008-07-08 17:15:16 +1000 |
---|---|---|
committer | Michi Henning <michi@zeroc.com> | 2008-07-08 17:15:16 +1000 |
commit | c49d9f97620053b30ecdfa66581484030865d039 (patch) | |
tree | 18803c9334660fad1a069fb8d1a01fe58f202512 /cpp/src/Ice/FactoryTableInit.cpp | |
parent | Bug 2038 - Fixed stale comment from previous fix. (diff) | |
download | ice-c49d9f97620053b30ecdfa66581484030865d039.tar.bz2 ice-c49d9f97620053b30ecdfa66581484030865d039.tar.xz ice-c49d9f97620053b30ecdfa66581484030865d039.zip |
Squashed commit of the following:
commit 3677312fda0e2e230d5572b3e76b3d1758c86919
Author: Michi Henning <michi@zeroc.com>
Date: Tue Jul 8 17:08:15 2008 +1000
Bug 2038 - Ctrl-C on Windows without CtrlCHandler
Renamed FactoryTableDef -> FactoryTable
Renamed FactoryTable -> FactoryTableInit
Diffstat (limited to 'cpp/src/Ice/FactoryTableInit.cpp')
-rw-r--r-- | cpp/src/Ice/FactoryTableInit.cpp | 62 |
1 files changed, 62 insertions, 0 deletions
diff --git a/cpp/src/Ice/FactoryTableInit.cpp b/cpp/src/Ice/FactoryTableInit.cpp new file mode 100644 index 00000000000..11026891b3a --- /dev/null +++ b/cpp/src/Ice/FactoryTableInit.cpp @@ -0,0 +1,62 @@ +// ********************************************************************** +// +// Copyright (c) 2003-2008 ZeroC, Inc. All rights reserved. +// +// This copy of Ice is licensed to you under the terms described in the +// ICE_LICENSE file included in this distribution. +// +// ********************************************************************** + +#include <Ice/FactoryTableInit.h> +#include <Ice/UserExceptionFactory.h> + +namespace IceInternal +{ + +// +// Single global instance of the factory table for non-local +// exceptions and non-abstract classes. +// +ICE_DECLSPEC_EXPORT FactoryTable* factoryTable; + +} + +namespace +{ + +static int initCount = 0; // Initialization count +IceUtil::StaticMutex initCountMutex = ICE_STATIC_MUTEX_INITIALIZER; + + +} + +// +// This constructor initializes the single global +// IceInternal::factoryTable instance from the outside (if it hasn't +// been initialized yet). The constructor here is triggered by a +// file-static instance of FactoryTable in each slice2cpp-generated +// header file that uses non-local exceptions or non-abstract classes. +// This ensures that IceInternal::factoryTable is always initialized +// before it is used. +// +IceInternal::FactoryTableInit::FactoryTableInit() +{ + IceUtil::StaticMutex::Lock lock(initCountMutex); + if(0 == initCount++) + { + factoryTable = new FactoryTable; + } +} + +// +// The destructor decrements the reference count and, once the +// count drops to zero, deletes the table. +// +IceInternal::FactoryTableInit::~FactoryTableInit() +{ + IceUtil::StaticMutex::Lock lock(initCountMutex); + if(0 == --initCount) + { + delete factoryTable; + } +} |