summaryrefslogtreecommitdiff
path: root/cpp
diff options
context:
space:
mode:
authorBernard Normier <bernard@zeroc.com>2012-08-09 15:40:44 -0400
committerBernard Normier <bernard@zeroc.com>2012-08-09 15:40:44 -0400
commit87ae1f009ce03d18e459ad8d66050da9a9f63144 (patch)
tree40118e7d5f3ce44688de309d6c8c4e13a26b6ac3 /cpp
parentWinRT Endpoint fixes for encoding11 (diff)
downloadice-87ae1f009ce03d18e459ad8d66050da9a9f63144.tar.bz2
ice-87ae1f009ce03d18e459ad8d66050da9a9f63144.tar.xz
ice-87ae1f009ce03d18e459ad8d66050da9a9f63144.zip
Added native cond-var implementation on Windows (bug #2667)
for Visual Studio 2012 and up Removed all #define and checks for _WIN32_WINNT (no longer needed) Misc build fixes for Visual Studio IceUtil/Config.h cleanup (minor)
Diffstat (limited to 'cpp')
-rwxr-xr-xcpp/config/Make.rules.msvc25
-rw-r--r--cpp/include/IceUtil/Cond.h73
-rw-r--r--cpp/include/IceUtil/Config.h44
-rw-r--r--cpp/include/IceUtil/Mutex.h16
-rw-r--r--cpp/include/IceUtil/RecMutex.h3
-rw-r--r--cpp/src/Ice/Makefile.mak1
-rw-r--r--cpp/src/Ice/Network.cpp8
-rw-r--r--cpp/src/Ice/ThreadPool.cpp8
-rw-r--r--cpp/src/IceUtil/Cond.cpp27
-rwxr-xr-x[-rw-r--r--]cpp/src/IceUtil/FileUtil.cpp10
-rw-r--r--cpp/src/IceUtil/RecMutex.cpp16
-rw-r--r--cpp/src/iceserviceinstall/ServiceInstaller.cpp2
12 files changed, 163 insertions, 70 deletions
diff --git a/cpp/config/Make.rules.msvc b/cpp/config/Make.rules.msvc
index 195ccd59175..dc2853d0cc3 100755
--- a/cpp/config/Make.rules.msvc
+++ b/cpp/config/Make.rules.msvc
@@ -28,7 +28,7 @@ GENERATE_PDB = yes
!endif
CPPFLAGS = $(CPPFLAGS) -nologo -W3 -WX -GR -EHsc
-ARFLAGS = $(ARFLAGS) -nologo -WX
+ARFLAGS = $(ARFLAGS) -nologo -WX
!if "$(WINRT)" == "yes"
CPPFLAGS = $(CPPFLAGS) -DWINAPI_FAMILY=2 -Gm- -Oy- -Gd -ZW -D_UNICODE -DUNICODE
@@ -47,7 +47,7 @@ CPPFLAGS = $(CPPFLAGS) -MP
!if "$(OPTIMIZE)" == "yes"
CPPFLAGS = $(CPPFLAGS) -O2 -DNDEBUG -MD
-ARFLAGS = $(ARFLAGS) /LTCG
+ARFLAGS = $(ARFLAGS) /LTCG
CONFIG = Retail
!else
@@ -81,9 +81,6 @@ LDFLAGS = $(LDFLAGS) /FIXED:no
!if "$(OPTIMIZE)" != "yes"
LDFLAGS = $(LDFLAGS) /debug
-!if "$(CPP_COMPILER)" != "VC100" && "$(CPP_COMPILER)" != "VC100_EXPRESS"
-LDFLAGS = $(LDFLAGS) /incremental:yes
-!endif
!else
@@ -120,18 +117,18 @@ LIBS = ice.lib $(BASELIBS)
!if "$(WINRT)" == "yes"
-SDK_VERSION = $(SHORT_VERSION)
-SDK_NAME = IceWinRT
-SDK_REG_FILE = $(SDK_NAME).reg
-SDK_MANIFEST = SDKManifest.xml
-SDK_BASE_PATH = $(top_srcdir)\SDKs\$(SDK_NAME)\$(SDK_VERSION)
-SDK_INCLUDE_PATH = $(SDK_BASE_PATH)\DesignTime\CommonConfiguration\Neutral\include
-SDK_LIBRARY_PATH = $(SDK_BASE_PATH)\DesignTime\$(CONFIG)\$(ARCH)
+SDK_VERSION = $(SHORT_VERSION)
+SDK_NAME = IceWinRT
+SDK_REG_FILE = $(SDK_NAME).reg
+SDK_MANIFEST = SDKManifest.xml
+SDK_BASE_PATH = $(top_srcdir)\SDKs\$(SDK_NAME)\$(SDK_VERSION)
+SDK_INCLUDE_PATH = $(SDK_BASE_PATH)\DesignTime\CommonConfiguration\Neutral\include
+SDK_LIBRARY_PATH = $(SDK_BASE_PATH)\DesignTime\$(CONFIG)\$(ARCH)
SDK_REFERENCES_PATH = $(SDK_BASE_PATH)\References\$(CONFIG)\$(ARCH)
SDK_REDIST_PATH = $(SDK_BASE_PATH)\Redist\$(CONFIG)\$(ARCH)
SDK_PROPS_PATH = $(SDK_BASE_PATH)\DesignTime\CommonConfiguration\Neutral
-SDK_PROPS_FILE = $(SDK_NAME).props
-SDK_LICENSE = $(SDK_BASE_PATH)\LICENSE.txt
+SDK_PROPS_FILE = $(SDK_NAME).props
+SDK_LICENSE = $(SDK_BASE_PATH)\LICENSE.txt
SDK_ICE_LICENSE = $(SDK_BASE_PATH)\ICE_LICENSE.txt
diff --git a/cpp/include/IceUtil/Cond.h b/cpp/include/IceUtil/Cond.h
index ff4aa2a4f4d..5a4121fbaf1 100644
--- a/cpp/include/IceUtil/Cond.h
+++ b/cpp/include/IceUtil/Cond.h
@@ -13,12 +13,8 @@
#include <IceUtil/Time.h>
#include <IceUtil/ThreadException.h>
-#ifdef _WIN32
-# include <IceUtil/Mutex.h>
-#endif
-
-
-#ifdef _WIN32
+#if defined(_WIN32) && !defined(ICE_HAS_WIN32_CONDVAR)
+# include <IceUtil/Mutex.h>
namespace IceUtilInternal
{
@@ -125,7 +121,7 @@ private:
//
// The Monitor implementation uses waitImpl & timedWaitImpl.
//
-#ifdef _WIN32
+#if defined(_WIN32) && !defined(ICE_HAS_WIN32_CONDVAR)
template <typename M> void
waitImpl(const M& mutex) const
@@ -179,6 +175,9 @@ private:
#endif
#ifdef _WIN32
+# ifdef ICE_HAS_WIN32_CONDVAR
+ mutable CONDITION_VARIABLE _cond;
+# else
ICE_UTIL_API void wake(bool);
ICE_UTIL_API void preWait() const;
ICE_UTIL_API void postWait(bool) const;
@@ -197,13 +196,65 @@ private:
StateBroadcast
};
mutable State _state;
+# endif
#else
mutable pthread_cond_t _cond;
#endif
};
-#ifndef _WIN32
+#ifdef _WIN32
+
+# ifdef ICE_HAS_WIN32_CONDVAR
+
+template <typename M> inline void
+Cond::waitImpl(const M& mutex) const
+{
+ typedef typename M::LockState LockState;
+
+ LockState state;
+ mutex.unlock(state);
+ BOOL ok = SleepConditionVariableCS(&_cond, state.mutex, INFINITE);
+ mutex.lock(state);
+
+ if(!ok)
+ {
+ throw ThreadSyscallException(__FILE__, __LINE__, GetLastError());
+ }
+}
+
+template <typename M> inline bool
+Cond::timedWaitImpl(const M& mutex, const Time& timeout) const
+{
+ IceUtil::Int64 msTimeout = timeout.toMilliSeconds();
+ if(msTimeout < 0 || msTimeout > 0x7FFFFFFF)
+ {
+ throw IceUtil::InvalidTimeoutException(__FILE__, __LINE__, timeout);
+ }
+
+ typedef typename M::LockState LockState;
+
+ LockState state;
+ mutex.unlock(state);
+ BOOL ok = SleepConditionVariableCS(&_cond, state.mutex, static_cast<DWORD>(msTimeout));
+ mutex.lock(state);
+
+ if(!ok)
+ {
+ DWORD err = GetLastError();
+
+ if(err != ERROR_TIMEOUT)
+ {
+ throw ThreadSyscallException(__FILE__, __LINE__, err);
+ }
+ return false;
+ }
+ return true;
+}
+
+# endif
+
+#else
template <typename M> inline void
Cond::waitImpl(const M& mutex) const
{
@@ -233,16 +284,16 @@ Cond::timedWaitImpl(const M& mutex, const Time& timeout) const
LockState state;
mutex.unlock(state);
-#ifdef __APPLE__
+# ifdef __APPLE__
//
// The monotonic time is based on mach_absolute_time and pthread
// condition variables require time from gettimeofday so we get
// the realtime time.
//
timeval tv = Time::now(Time::Realtime) + timeout;
-#else
+# else
timeval tv = Time::now(Time::Monotonic) + timeout;
-#endif
+# endif
timespec ts;
ts.tv_sec = tv.tv_sec;
ts.tv_nsec = tv.tv_usec * 1000;
diff --git a/cpp/include/IceUtil/Config.h b/cpp/include/IceUtil/Config.h
index 33191fb13f6..2fb166f0e72 100644
--- a/cpp/include/IceUtil/Config.h
+++ b/cpp/include/IceUtil/Config.h
@@ -34,13 +34,7 @@
//
// 32 or 64 bit mode?
//
-#if defined(__linux) && defined(__sparc__)
-//
-// We are a linux sparc, which forces 32 bit usr land, no matter
-// the architecture
-//
-# define ICE_32
-#elif defined(__sun) && (defined(__sparcv9) || defined(__x86_64)) || \
+#if defined(__sun) && (defined(__sparcv9) || defined(__x86_64)) || \
defined(__linux) && defined(__x86_64) || \
defined(__hppa) && defined(__LP64__) || \
defined(_ARCH_COM) && defined(__64BIT__) || \
@@ -51,19 +45,28 @@
# define ICE_32
#endif
-#if defined(_MSC_VER) && _MSC_VER > 1600
+#if defined(_MSC_VER) && (_MSC_VER >= 1700)
+//
+// Visual Studio 2012 and later
+//
# include <winapifamily.h>
-# if defined(WINAPI_FAMILY) && WINAPI_FAMILY == WINAPI_FAMILY_APP
+# if defined(WINAPI_FAMILY) && (WINAPI_FAMILY == WINAPI_FAMILY_APP)
# define ICE_OS_WINRT
# define ICE_STATIC_LIBS
# endif
+//
+// Windows provides native condition variables on Vista and later,
+// and Visual Studio 2012 no longer supports Windows XP or Windows Server 2003.
+//
+// You can also "switch-on" this macro to use native condition variables with
+// other C++ compilers on Windows.
+//
+# define ICE_HAS_WIN32_CONDVAR
#endif
//
// Compiler extensions to export and import symbols: see the documentation
-// for Visual C++, Sun ONE Studio 8 and HP aC++.
-//
-// TODO: more macros to support IBM Visual Age _Export syntax as well.
+// for Visual C++, Solaris Studio and HP aC++.
//
#if (defined(_MSC_VER) && !defined(ICE_STATIC_LIBS)) || \
(defined(__HP_aCC) && defined(__HP_WINDLL))
@@ -94,12 +97,8 @@
# define ICE_UTIL_API ICE_DECLSPEC_IMPORT
#endif
-#if defined(_WIN32)
-# ifndef _WIN32_WINNT
-# elif _WIN32_WINNT < 0x0400
-# error "TryEnterCricalSection requires _WIN32_WINNT >= 0x0400"
-# endif
+#ifdef _WIN32
# if !defined(ICE_STATIC_LIBS) && defined(_MSC_VER) && (!defined(_DLL) || !defined(_MT))
# error "Only multi-threaded DLL libraries can be used with Ice!"
@@ -137,17 +136,12 @@
# include <errno.h>
#endif
-//
-// By deriving from this class, other classes are made non-copyable.
-//
+
namespace IceUtil
{
//
-// TODO: Constructor and destructor should not be inlined, as they are
-// not performance critical.
-//
-// TODO: Naming conventions?
+// By deriving from this class, other classes are made non-copyable.
//
class noncopyable
{
@@ -168,7 +162,7 @@ private:
//
#ifdef _MSC_VER
//
-// On Windows, long is always 32-bit
+// With Visual C++, long is always 32-bit
//
typedef __int64 Int64;
#elif defined(ICE_64)
diff --git a/cpp/include/IceUtil/Mutex.h b/cpp/include/IceUtil/Mutex.h
index 3914e325dc3..f85cf721f30 100644
--- a/cpp/include/IceUtil/Mutex.h
+++ b/cpp/include/IceUtil/Mutex.h
@@ -85,6 +85,9 @@ private:
#ifdef _WIN32
struct LockState
{
+# ifdef ICE_HAS_WIN32_CONDVAR
+ CRITICAL_SECTION* mutex;
+# endif
};
#else
struct LockState
@@ -175,6 +178,18 @@ Mutex::unlock() const
LeaveCriticalSection(&_mutex);
}
+# ifdef ICE_HAS_WIN32_CONDVAR
+inline void
+Mutex::unlock(LockState& state) const
+{
+ state.mutex = &_mutex;
+}
+
+inline void
+Mutex::lock(LockState&) const
+{
+}
+# else
inline void
Mutex::unlock(LockState&) const
{
@@ -186,6 +201,7 @@ Mutex::lock(LockState&) const
{
EnterCriticalSection(&_mutex);
}
+# endif
#else
diff --git a/cpp/include/IceUtil/RecMutex.h b/cpp/include/IceUtil/RecMutex.h
index 3ca2e4c43c1..ed03f834b05 100644
--- a/cpp/include/IceUtil/RecMutex.h
+++ b/cpp/include/IceUtil/RecMutex.h
@@ -81,6 +81,9 @@ private:
#ifdef _WIN32
struct LockState
{
+# ifdef ICE_HAS_WIN32_CONDVAR
+ CRITICAL_SECTION* mutex;
+# endif
int count;
};
#else
diff --git a/cpp/src/Ice/Makefile.mak b/cpp/src/Ice/Makefile.mak
index c1f22dc6fa1..522da39075e 100644
--- a/cpp/src/Ice/Makefile.mak
+++ b/cpp/src/Ice/Makefile.mak
@@ -129,6 +129,7 @@ PDBFLAGS = /pdb:$(DLLNAME:.dll=.pdb)
LD_DLLFLAGS = $(LD_DLLFLAGS) /entry:"ice_DLL_Main"
RES_FILE = Ice.res
+
$(LIBNAME): $(DLLNAME)
$(DLLNAME): $(OBJS) Ice.res
diff --git a/cpp/src/Ice/Network.cpp b/cpp/src/Ice/Network.cpp
index e4678b96502..1258fa186a9 100644
--- a/cpp/src/Ice/Network.cpp
+++ b/cpp/src/Ice/Network.cpp
@@ -17,14 +17,6 @@
# include <netinet/in.h>
#endif
-//
-// The following is required for the Vista PSDK to bring in
-// the definitions of the IN6_IS_ADDR_* macros.
-//
-#if defined(_WIN32) && !defined(_WIN32_WINNT) && WINAPI_FAMILY != 0x02
-# define _WIN32_WINNT 0x0501
-#endif
-
#include <Ice/Network.h>
#include <IceUtil/StringUtil.h>
#include <IceUtil/Unicode.h>
diff --git a/cpp/src/Ice/ThreadPool.cpp b/cpp/src/Ice/ThreadPool.cpp
index 7217ec3b062..8e79614c66e 100644
--- a/cpp/src/Ice/ThreadPool.cpp
+++ b/cpp/src/Ice/ThreadPool.cpp
@@ -7,14 +7,6 @@
//
// **********************************************************************
-//
-// The following is required to bring in some definitions. Don't
-// define with Metro Style apps.
-//
-#if defined(_WIN32) && !defined(_WIN32_WINNT) && WINAPI_FAMILY != 0x02
-# define _WIN32_WINNT 0x0501
-#endif
-
#include <Ice/ThreadPool.h>
#include <IceUtil/DisableWarnings.h>
#include <Ice/EventHandler.h>
diff --git a/cpp/src/IceUtil/Cond.cpp b/cpp/src/IceUtil/Cond.cpp
index a0f71460f1e..6cfa0700838 100644
--- a/cpp/src/IceUtil/Cond.cpp
+++ b/cpp/src/IceUtil/Cond.cpp
@@ -15,6 +15,31 @@
#ifdef _WIN32
+# ifdef ICE_HAS_WIN32_CONDVAR
+
+IceUtil::Cond::Cond()
+{
+ InitializeConditionVariable(&_cond);
+}
+
+IceUtil::Cond::~Cond()
+{
+}
+
+void
+IceUtil::Cond::signal()
+{
+ WakeConditionVariable(&_cond);
+}
+
+void
+IceUtil::Cond::broadcast()
+{
+ WakeAllConditionVariable(&_cond);
+}
+
+# else
+
IceUtilInternal::Semaphore::Semaphore(long initial)
{
#ifndef ICE_OS_WINRT
@@ -305,6 +330,8 @@ IceUtil::Cond::timedDowait(const Time& timeout) const
}
}
+# endif // ICE_HAS_WIN32_CONDVAR
+
#else
IceUtil::Cond::Cond()
diff --git a/cpp/src/IceUtil/FileUtil.cpp b/cpp/src/IceUtil/FileUtil.cpp
index 58e321c5d63..9fe0a5f85d3 100644..100755
--- a/cpp/src/IceUtil/FileUtil.cpp
+++ b/cpp/src/IceUtil/FileUtil.cpp
@@ -208,7 +208,13 @@ IceUtilInternal::FileLock::FileLock(const std::string& path) :
overlaped.InternalHigh = 0;
overlaped.Offset = 0;
overlaped.OffsetHigh = 0;
+
+#if defined(_MSC_VER) && (_MSC_VER >= 1600)
overlaped.hEvent = nullptr;
+#else
+ overlaped.hEvent = 0;
+#endif
+
if(::LockFileEx(_fd, LOCKFILE_EXCLUSIVE_LOCK | LOCKFILE_FAIL_IMMEDIATELY, 0, 0, 0, &overlaped) == 0)
{
::CloseHandle(_fd);
@@ -216,8 +222,8 @@ IceUtilInternal::FileLock::FileLock(const std::string& path) :
}
#endif
//
- // In Windows implementation we don't write the process pid to the file, as is
- // not posible to read the file from other process while it is locked here.
+ // In Windows implementation we don't write the process pid to the file, as it is
+ // not possible to read the file from other process while it is locked here.
//
}
diff --git a/cpp/src/IceUtil/RecMutex.cpp b/cpp/src/IceUtil/RecMutex.cpp
index 9558a6fed2b..46209f55bc6 100644
--- a/cpp/src/IceUtil/RecMutex.cpp
+++ b/cpp/src/IceUtil/RecMutex.cpp
@@ -79,6 +79,21 @@ IceUtil::RecMutex::unlock() const
}
}
+# ifdef ICE_HAS_WIN32_CONDVAR
+void
+IceUtil::RecMutex::unlock(LockState& state) const
+{
+ state.mutex = &_mutex;
+ state.count = _count;
+ _count = 0;
+}
+
+void
+IceUtil::RecMutex::lock(LockState& state) const
+{
+ _count = state.count;
+}
+# else
void
IceUtil::RecMutex::unlock(LockState& state) const
{
@@ -93,6 +108,7 @@ IceUtil::RecMutex::lock(LockState& state) const
EnterCriticalSection(&_mutex);
_count = state.count;
}
+# endif
#else
diff --git a/cpp/src/iceserviceinstall/ServiceInstaller.cpp b/cpp/src/iceserviceinstall/ServiceInstaller.cpp
index 1b4e9aade6d..dd046a0755a 100644
--- a/cpp/src/iceserviceinstall/ServiceInstaller.cpp
+++ b/cpp/src/iceserviceinstall/ServiceInstaller.cpp
@@ -7,14 +7,12 @@
//
// **********************************************************************
-#define _WIN32_WINNT 0x0500
#define _CRT_SECURE_NO_DEPRECATE 1 // C4996 '<C function>' was declared deprecated
#include <ServiceInstaller.h>
#include <IceUtil/StringUtil.h>
#include <IceUtil/FileUtil.h>
-
#include <Aclapi.h>
#include <Sddl.h>