summaryrefslogtreecommitdiff
path: root/cpp/src/IceUtil/StaticMutex.cpp
diff options
context:
space:
mode:
authorMatthew Newhook <matthew@zeroc.com>2008-03-12 18:50:04 +0800
committerMatthew Newhook <matthew@zeroc.com>2008-03-12 18:50:04 +0800
commitba5bbb636402043f7dff5cdaa3444b66dd7bffbd (patch)
tree79ac9e34f32a41945d82826eb4196e859d26a3f9 /cpp/src/IceUtil/StaticMutex.cpp
parentFixed bug with fixVersion.py, and updated the IceStorm service version in tes... (diff)
downloadice-ba5bbb636402043f7dff5cdaa3444b66dd7bffbd.tar.bz2
ice-ba5bbb636402043f7dff5cdaa3444b66dd7bffbd.tar.xz
ice-ba5bbb636402043f7dff5cdaa3444b66dd7bffbd.zip
Squashed commit of the following:
I also got rid of some old 0x0400 compatibility stuff in RecMutex and StaticMutex. commit 8e7277ac6d19922c9be8c4b12a12b909da36eb60 Author: U-MARCH3\matthew <matthew@march3.(none)> Date: Wed Mar 12 18:19:15 2008 +0800 added missing file. commit 3ac0a9fdf2c5d976b08d9bbf24b0144e2533c8db Author: U-MARCH3\matthew <matthew@march3.(none)> Date: Wed Mar 12 18:12:56 2008 +0800 bug 2752
Diffstat (limited to 'cpp/src/IceUtil/StaticMutex.cpp')
-rw-r--r--cpp/src/IceUtil/StaticMutex.cpp40
1 files changed, 20 insertions, 20 deletions
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;