diff options
-rw-r--r-- | cpp/CHANGES | 3 | ||||
-rw-r--r-- | cpp/demo/Ice/MFC/client/stdafx.h | 14 | ||||
-rw-r--r-- | cpp/demo/Ice/MFC/server/stdafx.h | 14 | ||||
-rwxr-xr-x | cpp/demo/IcePatch2/MFC/stdafx.h | 14 | ||||
-rw-r--r-- | cpp/include/IceUtil/Mutex.h | 19 | ||||
-rw-r--r-- | cpp/include/IceUtil/RecMutex.h | 4 | ||||
-rw-r--r-- | cpp/include/IceUtil/StaticMutex.h | 110 | ||||
-rw-r--r-- | cpp/src/IceUtil/.depend | 1 | ||||
-rw-r--r-- | cpp/src/IceUtil/Makefile | 1 | ||||
-rw-r--r-- | cpp/src/IceUtil/Makefile.mak | 1 | ||||
-rw-r--r-- | cpp/src/IceUtil/Mutex.cpp | 30 | ||||
-rw-r--r-- | cpp/src/IceUtil/RecMutex.cpp | 115 | ||||
-rw-r--r-- | cpp/src/IceUtil/StaticMutex.cpp | 40 |
13 files changed, 65 insertions, 301 deletions
diff --git a/cpp/CHANGES b/cpp/CHANGES index a48ac26efe0..9d6eff49899 100644 --- a/cpp/CHANGES +++ b/cpp/CHANGES @@ -1,6 +1,9 @@ Changes since version 3.2.X (binary incompatible) ------------------------------------------------- +- Under Windows when building a MFC application it is no longer necessary + to define WINVER in the generated stdafx.h. + - The iceca ImportKey.class utility is now installed in /usr/share/Ice-3.3.0 for an RPM install or ${prefix}/lib otherwise. diff --git a/cpp/demo/Ice/MFC/client/stdafx.h b/cpp/demo/Ice/MFC/client/stdafx.h index 7157f78f7d1..ee30d53d5f9 100644 --- a/cpp/demo/Ice/MFC/client/stdafx.h +++ b/cpp/demo/Ice/MFC/client/stdafx.h @@ -25,20 +25,6 @@ #define VC_EXTRALEAN // Exclude rarely-used stuff from Windows headers #endif -// Modify the following defines if you have to target a platform prior to the ones specified below. -// Refer to MSDN for the latest info on corresponding values for different platforms. -#ifndef WINVER // Allow use of features specific to Windows 95 and Windows NT 4 or later. -#define WINVER 0x0400 // Change this to the appropriate value to target Windows 98 and Windows 2000 or later. -#endif - -#ifndef _WIN32_WINNT // Allow use of features specific to Windows NT 4 or later. -#define _WIN32_WINNT 0x0400 // Change this to the appropriate value to target Windows 98 and Windows 2000 or later. -#endif - -#ifndef _WIN32_IE // Allow use of features specific to IE 4.0 or later. -#define _WIN32_IE 0x0400 // Change this to the appropriate value to target IE 5.0 or later. -#endif - #define _ATL_CSTRING_EXPLICIT_CONSTRUCTORS // some CString constructors will be explicit // turns off MFC's hiding of some common and often safely ignored warning messages diff --git a/cpp/demo/Ice/MFC/server/stdafx.h b/cpp/demo/Ice/MFC/server/stdafx.h index 7157f78f7d1..ee30d53d5f9 100644 --- a/cpp/demo/Ice/MFC/server/stdafx.h +++ b/cpp/demo/Ice/MFC/server/stdafx.h @@ -25,20 +25,6 @@ #define VC_EXTRALEAN // Exclude rarely-used stuff from Windows headers #endif -// Modify the following defines if you have to target a platform prior to the ones specified below. -// Refer to MSDN for the latest info on corresponding values for different platforms. -#ifndef WINVER // Allow use of features specific to Windows 95 and Windows NT 4 or later. -#define WINVER 0x0400 // Change this to the appropriate value to target Windows 98 and Windows 2000 or later. -#endif - -#ifndef _WIN32_WINNT // Allow use of features specific to Windows NT 4 or later. -#define _WIN32_WINNT 0x0400 // Change this to the appropriate value to target Windows 98 and Windows 2000 or later. -#endif - -#ifndef _WIN32_IE // Allow use of features specific to IE 4.0 or later. -#define _WIN32_IE 0x0400 // Change this to the appropriate value to target IE 5.0 or later. -#endif - #define _ATL_CSTRING_EXPLICIT_CONSTRUCTORS // some CString constructors will be explicit // turns off MFC's hiding of some common and often safely ignored warning messages diff --git a/cpp/demo/IcePatch2/MFC/stdafx.h b/cpp/demo/IcePatch2/MFC/stdafx.h index 667deb8235f..09d7cfd1435 100755 --- a/cpp/demo/IcePatch2/MFC/stdafx.h +++ b/cpp/demo/IcePatch2/MFC/stdafx.h @@ -24,20 +24,6 @@ #define VC_EXTRALEAN // Exclude rarely-used stuff from Windows headers #endif -// Modify the following defines if you have to target a platform prior to the ones specified below. -// Refer to MSDN for the latest info on corresponding values for different platforms. -#ifndef WINVER // Allow use of features specific to Windows 95 and Windows NT 4 or later. -#define WINVER 0x0400 // Change this to the appropriate value to target Windows 98 and Windows 2000 or later. -#endif - -#ifndef _WIN32_WINNT // Allow use of features specific to Windows NT 4 or later. -#define _WIN32_WINNT 0x0400 // Change this to the appropriate value to target Windows 98 and Windows 2000 or later. -#endif - -#ifndef _WIN32_IE // Allow use of features specific to IE 4.0 or later. -#define _WIN32_IE 0x0400 // Change this to the appropriate value to target IE 5.0 or later. -#endif - #define _ATL_CSTRING_EXPLICIT_CONSTRUCTORS // some CString constructors will be explicit // turns off MFC's hiding of some common and often safely ignored warning messages diff --git a/cpp/include/IceUtil/Mutex.h b/cpp/include/IceUtil/Mutex.h index 1d7f3fb018b..7e5068df07c 100644 --- a/cpp/include/IceUtil/Mutex.h +++ b/cpp/include/IceUtil/Mutex.h @@ -32,7 +32,7 @@ class Cond; // `IceUtil::noncopyable' inaccessible in `IceInternal::Outgoing' due // to ambiguity // -class Mutex +class ICE_UTIL_API Mutex { public: @@ -55,6 +55,9 @@ public: // // Returns true if the lock was acquired, and false otherwise. // + // This method is not inlined under Win32 due to issues with VC6, + // MFC and WINVER >= 0x0400. See bug 2752 for details. + // bool tryLock() const; void unlock() const; @@ -128,20 +131,6 @@ Mutex::lock() const assert(_mutex.RecursionCount == 1); } -inline bool -Mutex::tryLock() const -{ - if(!TryEnterCriticalSection(&_mutex)) - { - return false; - } - if(_mutex.RecursionCount > 1) - { - LeaveCriticalSection(&_mutex); - throw ThreadLockedException(__FILE__, __LINE__); - } - return true; -} inline void Mutex::unlock() const diff --git a/cpp/include/IceUtil/RecMutex.h b/cpp/include/IceUtil/RecMutex.h index d387255f130..6f53b9f6565 100644 --- a/cpp/include/IceUtil/RecMutex.h +++ b/cpp/include/IceUtil/RecMutex.h @@ -94,11 +94,7 @@ private: friend class Cond; #ifdef _WIN32 -# if defined(_WIN32_WINNT) && _WIN32_WINNT >= 0x0400 mutable CRITICAL_SECTION _mutex; -# else - HANDLE _mutex; -# endif #else mutable pthread_mutex_t _mutex; #endif diff --git a/cpp/include/IceUtil/StaticMutex.h b/cpp/include/IceUtil/StaticMutex.h index 17b8d11d1a8..59fdb7f0581 100644 --- a/cpp/include/IceUtil/StaticMutex.h +++ b/cpp/include/IceUtil/StaticMutex.h @@ -39,7 +39,7 @@ class Cond; // // -class StaticMutex +class ICE_UTIL_API StaticMutex { public: @@ -59,18 +59,16 @@ public: // // Returns true if the lock was acquired, and false otherwise. // + // This method is not inlined under Win32 due to issues with VC6, + // MFC and WINVER >= 0x0400. See bug 2752 for details. + // bool tryLock() const; void unlock() const; #ifdef _WIN32 -# if defined(_WIN32_WINNT) && _WIN32_WINNT >= 0x0400 mutable CRITICAL_SECTION* _mutex; -# else - mutable HANDLE _mutex; - mutable int _recursionCount; -# endif #else mutable pthread_mutex_t _mutex; #endif @@ -104,7 +102,7 @@ private: #ifdef _WIN32 inline bool initialized() const; - ICE_UTIL_API void initialize() const; + void initialize() const; #endif #ifndef _MSC_VER @@ -142,8 +140,6 @@ StaticMutex::initialized() const return InterlockedCompareExchangePointer(reinterpret_cast<void**>(&tmp), 0, 0) != 0; } -# if defined(_WIN32_WINNT) && _WIN32_WINNT >= 0x0400 - inline void StaticMutex::lock() const { @@ -155,25 +151,6 @@ StaticMutex::lock() const assert(_mutex->RecursionCount == 1); } -inline bool -StaticMutex::tryLock() const -{ - if(!initialized()) - { - initialize(); - } - if(!TryEnterCriticalSection(_mutex)) - { - return false; - } - if(_mutex->RecursionCount > 1) - { - LeaveCriticalSection(_mutex); - throw ThreadLockedException(__FILE__, __LINE__); - } - return true; -} - inline void StaticMutex::unlock() const { @@ -200,83 +177,6 @@ StaticMutex::lock(LockState&) const EnterCriticalSection(_mutex); } -# else - -inline void -StaticMutex::lock() const -{ - if(!initialized()) - { - initialize(); - } - - DWORD rc = WaitForSingleObject(_mutex, INFINITE); - if(rc != WAIT_OBJECT_0) - { - if(rc == WAIT_FAILED) - { - throw ThreadSyscallException(__FILE__, __LINE__, GetLastError()); - } - else - { - throw ThreadSyscallException(__FILE__, __LINE__, 0); - } - } - _recursionCount++; - assert(_recursionCount == 1); -} - -inline bool -StaticMutex::tryLock() const -{ - if(!initialized()) - { - initialize(); - } - - DWORD rc = WaitForSingleObject(_mutex, 0); - if(rc != WAIT_OBJECT_0) - { - return false; - } - else if(_recursionCount == 1) - { - _recursionCount++; - unlock(); - throw ThreadLockedException(__FILE__, __LINE__); - } - else - { - _recursionCount++; - return true; - } -} - -inline void -StaticMutex::unlock() const -{ - _recursionCount--; - BOOL rc = ReleaseMutex(_mutex); - if(rc == 0) - { - throw ThreadSyscallException(__FILE__, __LINE__, GetLastError()); - } -} - -inline void -StaticMutex::unlock(LockState& state) const -{ - unlock(); -} - -inline void -StaticMutex::lock(LockState&) const -{ - lock(); -} - -# endif - #else inline void diff --git a/cpp/src/IceUtil/.depend b/cpp/src/IceUtil/.depend index ab30f546191..41b5147f63e 100644 --- a/cpp/src/IceUtil/.depend +++ b/cpp/src/IceUtil/.depend @@ -9,6 +9,7 @@ InputUtil$(OBJEXT): InputUtil.cpp $(includedir)/IceUtil/InputUtil.h $(includedir Options$(OBJEXT): Options.cpp $(includedir)/IceUtil/Options.h $(includedir)/IceUtil/Config.h $(includedir)/IceUtil/RecMutex.h $(includedir)/IceUtil/Lock.h $(includedir)/IceUtil/ThreadException.h $(includedir)/IceUtil/Exception.h $(includedir)/IceUtil/Time.h $(includedir)/IceUtil/Shared.h $(includedir)/IceUtil/Mutex.h $(includedir)/IceUtil/Handle.h OutputUtil$(OBJEXT): OutputUtil.cpp $(includedir)/IceUtil/OutputUtil.h $(includedir)/IceUtil/Config.h Random$(OBJEXT): Random.cpp $(includedir)/IceUtil/Random.h $(includedir)/IceUtil/Config.h $(includedir)/IceUtil/Exception.h $(includedir)/IceUtil/StaticMutex.h $(includedir)/IceUtil/Lock.h $(includedir)/IceUtil/ThreadException.h $(includedir)/IceUtil/Time.h +Mutex$(OBJEXT): Mutex.cpp $(includedir)/IceUtil/Mutex.h $(includedir)/IceUtil/Config.h $(includedir)/IceUtil/Lock.h $(includedir)/IceUtil/ThreadException.h $(includedir)/IceUtil/Exception.h $(includedir)/IceUtil/Time.h RWRecMutex$(OBJEXT): RWRecMutex.cpp $(includedir)/IceUtil/RWRecMutex.h $(includedir)/IceUtil/Mutex.h $(includedir)/IceUtil/Config.h $(includedir)/IceUtil/Lock.h $(includedir)/IceUtil/ThreadException.h $(includedir)/IceUtil/Exception.h $(includedir)/IceUtil/Time.h $(includedir)/IceUtil/Cond.h $(includedir)/IceUtil/Thread.h $(includedir)/IceUtil/Shared.h $(includedir)/IceUtil/Handle.h RecMutex$(OBJEXT): RecMutex.cpp $(includedir)/IceUtil/RecMutex.h $(includedir)/IceUtil/Config.h $(includedir)/IceUtil/Lock.h $(includedir)/IceUtil/ThreadException.h $(includedir)/IceUtil/Exception.h $(includedir)/IceUtil/Time.h StaticMutex$(OBJEXT): StaticMutex.cpp $(includedir)/IceUtil/StaticMutex.h $(includedir)/IceUtil/Config.h $(includedir)/IceUtil/Lock.h $(includedir)/IceUtil/ThreadException.h $(includedir)/IceUtil/Exception.h $(includedir)/IceUtil/Time.h diff --git a/cpp/src/IceUtil/Makefile b/cpp/src/IceUtil/Makefile index 033414933b6..abe74995a26 100644 --- a/cpp/src/IceUtil/Makefile +++ b/cpp/src/IceUtil/Makefile @@ -26,6 +26,7 @@ OBJS = ArgVector.o \ Options.o \ OutputUtil.o \ Random.o \ + Mutex.o \ RWRecMutex.o \ RecMutex.o \ StaticMutex.o \ diff --git a/cpp/src/IceUtil/Makefile.mak b/cpp/src/IceUtil/Makefile.mak index 6e646c22767..cb5039170f4 100644 --- a/cpp/src/IceUtil/Makefile.mak +++ b/cpp/src/IceUtil/Makefile.mak @@ -25,6 +25,7 @@ OBJS = ArgVector.obj \ Options.obj \ OutputUtil.obj \ Random.obj \ + Mutex.obj \ RWRecMutex.obj \ RecMutex.obj \ StaticMutex.obj \ diff --git a/cpp/src/IceUtil/Mutex.cpp b/cpp/src/IceUtil/Mutex.cpp new file mode 100644 index 00000000000..32e1036a730 --- /dev/null +++ b/cpp/src/IceUtil/Mutex.cpp @@ -0,0 +1,30 @@ +// ********************************************************************** +// +// 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 <IceUtil/Mutex.h> +#include <IceUtil/Exception.h> + +#ifdef _WIN32 + +bool +IceUtil::Mutex::tryLock() const +{ + if(!TryEnterCriticalSection(&_mutex)) + { + return false; + } + if(_mutex.RecursionCount > 1) + { + LeaveCriticalSection(&_mutex); + throw ThreadLockedException(__FILE__, __LINE__); + } + return true; +} + +#endif diff --git a/cpp/src/IceUtil/RecMutex.cpp b/cpp/src/IceUtil/RecMutex.cpp index 7a68dd18d4a..2e185ff99a6 100644 --- a/cpp/src/IceUtil/RecMutex.cpp +++ b/cpp/src/IceUtil/RecMutex.cpp @@ -14,8 +14,6 @@ using namespace std; #ifdef _WIN32 -# if defined(_WIN32_WINNT) && _WIN32_WINNT >= 0x0400 - IceUtil::RecMutex::RecMutex() : _count(0) { @@ -76,119 +74,6 @@ IceUtil::RecMutex::lock(LockState& state) const _count = state.count; } -# else - -IceUtil::RecMutex::RecMutex() : - _count(0) -{ - _mutex = CreateMutex(0, false, 0); - if(_mutex == 0) - { - throw ThreadSyscallException(__FILE__, __LINE__, GetLastError()); - } -} - -IceUtil::RecMutex::~RecMutex() -{ - assert(_count == 0); - BOOL rc = CloseHandle(_mutex); - if(rc == 0) - { - throw ThreadSyscallException(__FILE__, __LINE__, GetLastError()); - } -} - -void -IceUtil::RecMutex::lock() const -{ - DWORD rc = WaitForSingleObject(_mutex, INFINITE); - if(rc != WAIT_OBJECT_0) - { - if(rc == WAIT_FAILED) - { - throw ThreadSyscallException(__FILE__, __LINE__, GetLastError()); - } - else - { - throw ThreadSyscallException(__FILE__, __LINE__, 0); - } - } - - if(++_count > 1) - { - BOOL rc2 = ReleaseMutex(_mutex); - if(rc2 == 0) - { - throw ThreadSyscallException(__FILE__, __LINE__, GetLastError()); - } - } -} - -bool -IceUtil::RecMutex::tryLock() const -{ - DWORD rc = WaitForSingleObject(_mutex, 0); - if(rc != WAIT_OBJECT_0) - { - return false; - } - if(++_count > 1) - { - BOOL rc2 = ReleaseMutex(_mutex); - if(rc2 == 0) - { - throw ThreadSyscallException(__FILE__, __LINE__, GetLastError()); - } - } - return true; -} - -void -IceUtil::RecMutex::unlock() const -{ - if(--_count == 0) - { - BOOL rc = ReleaseMutex(_mutex); - if(rc == 0) - { - throw ThreadSyscallException(__FILE__, __LINE__, GetLastError()); - } - } -} - -void -IceUtil::RecMutex::unlock(LockState& state) const -{ - state.count = _count; - _count = 0; - BOOL rc = ReleaseMutex(_mutex); - if(rc == 0) - { - throw ThreadSyscallException(__FILE__, __LINE__, GetLastError()); - } -} - -void -IceUtil::RecMutex::lock(LockState& state) const -{ - DWORD rc = WaitForSingleObject(_mutex, INFINITE); - if(rc != WAIT_OBJECT_0) - { - if(rc == WAIT_FAILED) - { - throw ThreadSyscallException(__FILE__, __LINE__, GetLastError()); - } - else - { - throw ThreadSyscallException(__FILE__, __LINE__, 0); - } - } - - _count = state.count; -} - -# endif - #else IceUtil::RecMutex::RecMutex() : diff --git a/cpp/src/IceUtil/StaticMutex.cpp b/cpp/src/IceUtil/StaticMutex.cpp index 53fa1f812b3..8084d79c666 100644 --- a/cpp/src/IceUtil/StaticMutex.cpp +++ b/cpp/src/IceUtil/StaticMutex.cpp @@ -18,11 +18,7 @@ using namespace std; static CRITICAL_SECTION _criticalSection; -# if defined(_WIN32_WINNT) && _WIN32_WINNT >= 0x0400 typedef list<CRITICAL_SECTION*> MutexList; -# else -typedef list<HANDLE> MutexList; -# endif static MutexList* _mutexList; @@ -53,17 +49,12 @@ Init::Init() Init::~Init() { -# if defined(_WIN32_WINNT) && _WIN32_WINNT >= 0x0400 for(MutexList::iterator p = _mutexList->begin(); p != _mutexList->end(); ++p) { DeleteCriticalSection(*p); delete *p; } -# else - for_each(_mutexList->begin(), _mutexList->end(), - CloseHandle); -# endif delete _mutexList; DeleteCriticalSection(&_criticalSection); } @@ -82,19 +73,8 @@ void IceUtil::StaticMutex::initialize() const // if(_mutex == 0) { -# if defined(_WIN32_WINNT) && _WIN32_WINNT >= 0x0400 CRITICAL_SECTION* newMutex = new CRITICAL_SECTION; InitializeCriticalSection(newMutex); -# else - _recursionCount = 0; - - HANDLE newMutex = CreateMutex(0, false, 0); - if(newMutex == 0) - { - LeaveCriticalSection(&_criticalSection); - throw ThreadSyscallException(__FILE__, __LINE__, GetLastError()); - } -# endif // // _mutex is written after the new initialized CRITICAL_SECTION/Mutex @@ -106,6 +86,26 @@ void IceUtil::StaticMutex::initialize() const } LeaveCriticalSection(&_criticalSection); } + +bool +IceUtil::StaticMutex::tryLock() const +{ + if(!initialized()) + { + initialize(); + } + if(!TryEnterCriticalSection(_mutex)) + { + return false; + } + if(_mutex->RecursionCount > 1) + { + LeaveCriticalSection(_mutex); + throw ThreadLockedException(__FILE__, __LINE__); + } + return true; +} + #endif IceUtil::StaticMutex IceUtil::globalMutex = ICE_STATIC_MUTEX_INITIALIZER; |