summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--cpp/include/IceUtil/Cache.h4
-rw-r--r--cpp/include/IceUtil/CountDownLatch.h3
-rw-r--r--cpp/src/IceUtil/CountDownLatch.cpp6
3 files changed, 6 insertions, 7 deletions
diff --git a/cpp/include/IceUtil/Cache.h b/cpp/include/IceUtil/Cache.h
index ff2f4cbbe72..9f0d3b917ee 100644
--- a/cpp/include/IceUtil/Cache.h
+++ b/cpp/include/IceUtil/Cache.h
@@ -50,7 +50,7 @@ public:
struct CacheValue
{
- CacheValue(const Handle<Value>& o = 0) :
+ CacheValue(const Handle<Value>& o) :
obj(o),
latch(0)
{
@@ -199,7 +199,7 @@ Cache<Key, Value>::pinImpl(const Key& key, const Handle<Value>& newObj)
#else
std::pair<typename CacheMap::iterator, bool> ir =
#endif
- _map.insert(CacheMap::value_type(key, CacheValue()));
+ _map.insert(CacheMap::value_type(key, CacheValue(0)));
if(ir.second == false)
{
diff --git a/cpp/include/IceUtil/CountDownLatch.h b/cpp/include/IceUtil/CountDownLatch.h
index ddd4fd18568..78f2b119552 100644
--- a/cpp/include/IceUtil/CountDownLatch.h
+++ b/cpp/include/IceUtil/CountDownLatch.h
@@ -32,11 +32,12 @@ public:
int getCount() const;
private:
- int _count;
#ifdef _WIN32
+ mutable LONG _count;
HANDLE _event;
#else
+ int _count;
mutable pthread_mutex_t _mutex;
mutable pthread_cond_t _cond;
diff --git a/cpp/src/IceUtil/CountDownLatch.cpp b/cpp/src/IceUtil/CountDownLatch.cpp
index 6e1f37d8646..41a9d60abe6 100644
--- a/cpp/src/IceUtil/CountDownLatch.cpp
+++ b/cpp/src/IceUtil/CountDownLatch.cpp
@@ -49,8 +49,7 @@ void
IceUtil::CountDownLatch::await() const
{
#ifdef _WIN32
- int* countPtr = const_cast<int*>(&_count);
- while(InterlockedCompareExchange(countPtr, 0, 0) > 0)
+ while(InterlockedExchangeAdd(&_count, 0) > 0)
{
DWORD rc = WaitForSingleObject(_event, INFINITE);
assert(rc == WAIT_OBJECT_0 || rc == WAIT_FAILED);
@@ -113,8 +112,7 @@ int
IceUtil::CountDownLatch::getCount() const
{
#ifdef _WIN32
- int* countPtr = const_cast<int*>(&_count);
- int count = InterlockedCompareExchange(countPtr, 0, 0);
+ int count = InterlockedExchangeAdd(&_count, 0);
return count > 0 ? count : 0;
#else
lock();