summaryrefslogtreecommitdiff
path: root/cpp/src/IceUtil/StaticMutex.cpp
diff options
context:
space:
mode:
authorBernard Normier <bernard@zeroc.com>2003-09-03 18:16:10 +0000
committerBernard Normier <bernard@zeroc.com>2003-09-03 18:16:10 +0000
commit1454e95d7c987919063cb22f1f7f528fb7626ae9 (patch)
tree2424f28e2416d5429bc33a1c38b8ac712622ba2e /cpp/src/IceUtil/StaticMutex.cpp
parentuse ICE_HOME (if present) to find translator (diff)
downloadice-1454e95d7c987919063cb22f1f7f528fb7626ae9.tar.bz2
ice-1454e95d7c987919063cb22f1f7f528fb7626ae9.tar.xz
ice-1454e95d7c987919063cb22f1f7f528fb7626ae9.zip
Merged from 1.1
Diffstat (limited to 'cpp/src/IceUtil/StaticMutex.cpp')
-rw-r--r--cpp/src/IceUtil/StaticMutex.cpp39
1 files changed, 32 insertions, 7 deletions
diff --git a/cpp/src/IceUtil/StaticMutex.cpp b/cpp/src/IceUtil/StaticMutex.cpp
index 3e326a8f173..49b3a9eb78d 100644
--- a/cpp/src/IceUtil/StaticMutex.cpp
+++ b/cpp/src/IceUtil/StaticMutex.cpp
@@ -22,7 +22,14 @@
using namespace std;
static CRITICAL_SECTION _criticalSection;
-static list<CRITICAL_SECTION*>* _criticalSectionList;
+
+# if defined(_WIN32_WINNT) && _WIN32_WINNT >= 0x0400
+typedef list<CRITICAL_SECTION*> MutexList;
+# else
+typedef list<HANDLE> MutexList;
+# endif
+
+static MutexList* _mutexList;
// Although apparently not documented by Microsoft, static objects are
// initialized before DllMain/DLL_PROCESS_ATTACH and finalized after
@@ -45,19 +52,24 @@ static Init _init;
Init::Init()
{
InitializeCriticalSection(&_criticalSection);
- _criticalSectionList = new list<CRITICAL_SECTION*>;
+
+ _mutexList = new MutexList;
}
Init::~Init()
{
- for(list<CRITICAL_SECTION*>::iterator p = _criticalSectionList->begin();
- p != _criticalSectionList->end(); ++p)
+# if defined(_WIN32_WINNT) && _WIN32_WINNT >= 0x0400
+ for(MutexList::iterator p = _mutexList->begin();
+ p != _mutexList->end(); ++p)
{
DeleteCriticalSection(*p);
delete *p;
}
-
- delete _criticalSectionList;
+# else
+ for_each(_mutexList->begin(), _mutexList->end(),
+ CloseHandle);
+# endif
+ delete _mutexList;
DeleteCriticalSection(&_criticalSection);
}
}
@@ -73,8 +85,21 @@ void IceUtil::StaticMutex::initialize() const
{
_mutex = new CRITICAL_SECTION;
InitializeCriticalSection(_mutex);
+
+# if defined(_WIN32_WINNT) && _WIN32_WINNT >= 0x0400
+ _mutex = new CRITICAL_SECTION;
+ InitializeCriticalSection(_mutex);
+ _mutexList->push_back(_mutex);
+# else
+ _recursionCount = 0;
+ _mutex = CreateMutex(0, false, 0);
+ if(_mutex == 0)
+ {
+ throw ThreadSyscallException(__FILE__, __LINE__, GetLastError());
+ }
+ _mutexList->push_back(_mutex);
+# endif
_mutexInitialized = true;
- _criticalSectionList->push_back(_mutex);
}
LeaveCriticalSection(&_criticalSection);
}