diff options
author | Jose <jose@zeroc.com> | 2009-07-10 14:40:47 +0200 |
---|---|---|
committer | Jose <jose@zeroc.com> | 2009-07-10 14:40:47 +0200 |
commit | 4fa7afeb9896d550b5b03949d632abac427474c4 (patch) | |
tree | 45665857beb6d2412b9fcf1d77254a0d584d6967 /cpp/include | |
parent | Revert 3965 - new version of Ice::initialize. (diff) | |
download | ice-4fa7afeb9896d550b5b03949d632abac427474c4.tar.bz2 ice-4fa7afeb9896d550b5b03949d632abac427474c4.tar.xz ice-4fa7afeb9896d550b5b03949d632abac427474c4.zip |
Squashed commit of ice-rt branch:
commit 831a201c23d4a4aee9041c20d16e194e918fbb06
Author: Jose Gutierrez <pepone@dhcppc0.(none)>
Date: Thu Jul 9 19:59:57 2009 +0200
Fix typo.
commit 3447d3d63c56d0a948b756d5152b8fe072db2618
Author: Jose Gutierrez <pepone@dhcppc0.(none)>
Date: Thu Jul 9 19:58:42 2009 +0200
Fix collector thread start.
commit ef6e69a167ee4a6cf1c033569b8233f5a891b91b
Author: Jose Gutierrez <pepone@dhcppc0.(none)>
Date: Thu Jul 9 17:39:03 2009 +0200
Disable test on OS X
commit f76e7c2d4027af7d840cf4a59d74aa9872055f6e
Author: root <root@dhcppc0.(none)>
Date: Thu Jul 9 17:25:44 2009 +0200
Disable priority test in Os x
commit 01afc1706ecb53ab1b95980ef1e1949cea4af243
Author: Jose Gutierrez <pepone@dhcppc0.(none)>
Date: Thu Jul 9 17:00:55 2009 +0200
Osx Fix
commit 89509ad18da576949164d9740600edf8ae5db739
Author: Jose Gutierrez <pepone@dhcppc0.(none)>
Date: Thu Jul 9 16:39:47 2009 +0200
Minor fixes
commit c89a1e5fe9c344c6bfb4d588d8faa79834bc3106
Author: Jose Gutierrez <pepone@dhcppc0.(none)>
Date: Tue Jul 7 15:42:03 2009 +0200
Support for MIN_PRIORITY, NORM_PRIORITY, MAX_PRIORITY in Java.
commit 9d73fc28719e73e930a8b616e4de31ded64e6a41
Author: Jose Gutierrez <pepone@dhcppc0.(none)>
Date: Tue Jul 7 00:57:30 2009 +0200
setPriority fixes.
commit 44e89ea3092fa9cda1573bb2dae57d4a76da35e2
Author: Jose Gutierrez <pepone@dhcppc0.(none)>
Date: Mon Jul 6 18:26:51 2009 +0200
Thread priority fixes.
commit eb689a397a0d53ef3f3448736c8cd103e369df6a
Author: Jose Gutierrez <pepone@dhcppc0.(none)>
Date: Tue Jun 30 21:49:09 2009 +0200
Fix MutexPtr to set _acquired false on release.
commit 22dd76d2a08f34d306cfc7508a5465435aa600d1
Author: Jose Gutierrez <pepone@dhcppc0.(none)>
Date: Tue Jun 30 17:31:30 2009 +0200
Code style fixes to thread priority changes.
commit e04c19a06167b9b58e52144946a00cdf01e3500f
Author: Jose Gutierrez <pepone@dhcppc0.(none)>
Date: Mon Jun 29 22:20:23 2009 +0200
Changes to thread priority support. and global static removes.
commit aed0ae1e9f6ae7e33cd2dcd390be1bcdc4270378
Author: Jose Gutierrez <pepone@dhcppc0.(none)>
Date: Fri Jun 26 16:19:23 2009 +0200
Add support to set Thread priorities to C#
commit fff01616d2fffde5e6a7b3920228bb861b4e16d8
Author: Jose Gutierrez <pepone@dhcppc0.(none)>
Date: Thu Jun 25 18:49:23 2009 +0200
replace static with anon namespace
commit 34c84d7d6e1591210b1a6d79def79cb5fcc8bd19
Author: Jose Gutierrez <pepone@dhcppc0.(none)>
Date: Wed Jun 24 17:23:46 2009 +0200
Add call to TestUtil.cleanup
commit 58e2e13803e154dd2c5a26117c396f0ddf40d189
Author: Jose Gutierrez <pepone@dhcppc0.(none)>
Date: Tue Jun 23 21:02:43 2009 +0200
Remove priorities for throughput test.
commit 679f2b9690db5cad7a9437de72640a38a977e555
Author: Jose Gutierrez <jose@zeroc.com>
Date: Thu Dec 4 00:44:38 2008 +0100
Updates to real time priorities
commit 78eb230923f57d968ceb78c5a670b7ef3ab10e24
Author: Jose Gutierrez <jose@zeroc.com>
Date: Wed Dec 3 02:23:00 2008 +0100
Sync priority inversion test with simplication of this test in icee-rt
commit fdd8fcd6f171bd456e335f82dfa3e64974c0220e
Author: Jose Gutierrez <jose@zeroc.com>
Date: Wed Dec 3 02:22:34 2008 +0100
Remove static mutex from demo book lifecycle
commit 1c646ad332d931de3f716bb5130bac360a4cf198
Author: Jose Gutierrez <jose@zeroc.com>
Date: Wed Dec 3 02:22:00 2008 +0100
Fix allTest to run rt test only as root in unix.
commit e813ef4101700584b6464de99066137247fe21a8
Author: Jose Gutierrez <jose@zeroc.com>
Date: Wed Dec 3 02:08:07 2008 +0100
More StaticMutex removed.
commit 289d83a46d72091f65ff99c0e151aedf0bd60417
Author: Jose Gutierrez <jose@zeroc.com>
Date: Wed Dec 3 01:34:32 2008 +0100
End remove StaticMutex usage from Ice
commit d422e04009a8627c73269f2824bd842453cea319
Author: Jose Gutierrez <jose@zeroc.com>
Date: Wed Dec 3 00:21:21 2008 +0100
Remove StaticMutex use in Ice tests
commit 275baefd6b8b45be33d9e098ec38ab69c6cf981b
Author: Jose Gutierrez <jose@zeroc.com>
Date: Tue Dec 2 22:39:15 2008 +0100
Removing StaticMutex used in Ice core and Ice services.
commit 31b496ffda0a6def8097c46b7269b73d174ba495
Author: Jose Gutierrez <jose@zeroc.com>
Date: Tue Dec 2 00:43:42 2008 +0100
Sync changes with latest changes in icee-rt.
commit b31abef3b24131214908664bb488ba2069c0b8c1
Author: Jose Gutierrez <jose@zeroc.com>
Date: Fri Nov 14 19:44:28 2008 +0100
Change test assertions
commit b81f4d8854580e7c2cc9faef3c648f8ccd4484e0
Author: Jose Gutierrez <jose@zeroc.com>
Date: Fri Nov 14 19:23:34 2008 +0100
Priority inversion test fixes.
commit 3d35130b569c20ddd2da74fed39d1c78b7430c9e
Author: Jose Gutierrez <jose@zeroc.com>
Date: Fri Nov 14 02:08:06 2008 +0100
Fixes to priority inversion test.
commit 0e158c1bba306184ac4cd166c88ca62dbc557331
Author: Jose Gutierrez <jose@zeroc.com>
Date: Fri Nov 14 00:32:36 2008 +0100
Priority inheritance protocol for Mutex and RecMutex posix implementation.
commit 2587e416316046ac6f3baacee5c73b2a9205703b
Author: Jose Gutierrez <jose@zeroc.com>
Date: Wed Nov 12 19:40:48 2008 +0100
Fix icert.config used in test/Ice/priority
commit 7b1f0a67de9acf6e2b0f8e485ed05e726705f257
Author: Jose Gutierrez <jose@zeroc.com>
Date: Wed Nov 12 19:23:06 2008 +0100
Fix Thread::start to no use duplicate code.
Remove ThreadPriorityException and uset ThreadSyscallException instead.
Remove the change to timer test for real tiem priority timers as require root
user is better to put this in a separte test.
commit 0890d83b0229e09e91ce6393b7f5fc2abd73d020
Author: Jose Gutierrez <jose@zeroc.com>
Date: Wed Nov 12 17:58:12 2008 +0100
Ice real time priority support.
Diffstat (limited to 'cpp/include')
-rw-r--r-- | cpp/include/IceUtil/Config.h | 6 | ||||
-rw-r--r-- | cpp/include/IceUtil/IceUtil.h | 2 | ||||
-rw-r--r-- | cpp/include/IceUtil/Mutex.h | 85 | ||||
-rw-r--r-- | cpp/include/IceUtil/MutexProtocol.h | 28 | ||||
-rw-r--r-- | cpp/include/IceUtil/MutexPtrLock.h | 83 | ||||
-rw-r--r-- | cpp/include/IceUtil/MutexPtrTryLock.h | 82 | ||||
-rw-r--r-- | cpp/include/IceUtil/RWRecMutex.h | 2 | ||||
-rw-r--r-- | cpp/include/IceUtil/RecMutex.h | 3 | ||||
-rw-r--r-- | cpp/include/IceUtil/StaticMutex.h | 6 | ||||
-rw-r--r-- | cpp/include/IceUtil/Thread.h | 7 | ||||
-rw-r--r-- | cpp/include/IceUtil/Timer.h | 6 |
11 files changed, 286 insertions, 24 deletions
diff --git a/cpp/include/IceUtil/Config.h b/cpp/include/IceUtil/Config.h index 3e8ddd03ff0..01bb4d7042e 100644 --- a/cpp/include/IceUtil/Config.h +++ b/cpp/include/IceUtil/Config.h @@ -241,4 +241,10 @@ public: } #endif + +// +// The default Mutex protocol +// +#define ICE_DEFAULT_MUTEX_PROTOCOL PrioInherit + #endif diff --git a/cpp/include/IceUtil/IceUtil.h b/cpp/include/IceUtil/IceUtil.h index 469e2355189..b10aec7c968 100644 --- a/cpp/include/IceUtil/IceUtil.h +++ b/cpp/include/IceUtil/IceUtil.h @@ -25,7 +25,9 @@ #include <IceUtil/Handle.h> #include <IceUtil/Lock.h> #include <IceUtil/Monitor.h> +#include <IceUtil/MutexProtocol.h> #include <IceUtil/Mutex.h> +#include <IceUtil/MutexPtrLock.h> #include <IceUtil/RWRecMutex.h> #include <IceUtil/RecMutex.h> #include <IceUtil/Shared.h> diff --git a/cpp/include/IceUtil/Mutex.h b/cpp/include/IceUtil/Mutex.h index af0c709f89e..9c1a9518406 100644 --- a/cpp/include/IceUtil/Mutex.h +++ b/cpp/include/IceUtil/Mutex.h @@ -13,6 +13,7 @@ #include <IceUtil/Config.h> #include <IceUtil/Lock.h> #include <IceUtil/ThreadException.h> +#include <IceUtil/MutexProtocol.h> namespace IceUtil { @@ -43,6 +44,7 @@ public: typedef TryLockT<Mutex> TryLock; inline Mutex(); + inline Mutex(MutexProtocol); ~Mutex(); // @@ -72,6 +74,7 @@ public: private: + inline void init(MutexProtocol); // noncopyable Mutex(const Mutex&); void operator=(const Mutex&); @@ -106,11 +109,30 @@ private: // // For performance reasons the following functions are inlined. // - +inline +Mutex::Mutex() +{ #ifdef _WIN32 + init(PrioNone); +#else + init(getDefaultMutexProtocol()); +#endif +} inline -Mutex::Mutex() +Mutex::Mutex(MutexProtocol protocol) +{ +#ifdef _WIN32 + init(PrioNone); +#else + init(protocol); +#endif +} + +#ifdef _WIN32 + +inline void +Mutex::init(MutexProtocol) { InitializeCriticalSection(&_mutex); } @@ -164,33 +186,62 @@ Mutex::lock(LockState&) const #else -inline -Mutex::Mutex() +inline void +Mutex::init(MutexProtocol protocol) { -#ifdef NDEBUG - int rc = pthread_mutex_init(&_mutex, 0); -#else - int rc; -#if defined(__linux) && !defined(__USE_UNIX98) - const pthread_mutexattr_t attr = { PTHREAD_MUTEX_ERRORCHECK_NP }; -#else pthread_mutexattr_t attr; rc = pthread_mutexattr_init(&attr); assert(rc == 0); - rc = pthread_mutexattr_settype(&attr, PTHREAD_MUTEX_ERRORCHECK); - assert(rc == 0); -#endif - rc = pthread_mutex_init(&_mutex, &attr); + if(rc != 0) + { + pthread_mutexattr_destroy(&attr); + throw ThreadSyscallException(__FILE__, __LINE__, rc); + } + // + // Enable mutex error checking in debug builds + // +#ifndef NDEBUG #if defined(__linux) && !defined(__USE_UNIX98) -// Nothing to do + rc = pthread_mutexattr_settype(&attr, PTHREAD_MUTEX_ERRORCHECK_NP); #else - rc = pthread_mutexattr_destroy(&attr); + rc = pthread_mutexattr_settype(&attr, PTHREAD_MUTEX_ERRORCHECK); +#endif assert(rc == 0); + if(rc != 0) + { + pthread_mutexattr_destroy(&attr); + throw ThreadSyscallException(__FILE__, __LINE__, rc); + } #endif + + // + // If system has support for priority inheritance we set the protocol + // attribute of the mutex + // +#if defined(_POSIX_THREAD_PRIO_INHERIT) && _POSIX_THREAD_PRIO_INHERIT > 0 + if(PrioInherit == protocol) + { + rc = pthread_mutexattr_setprotocol(&attr, PTHREAD_PRIO_INHERIT); + if(rc != 0) + { + pthread_mutexattr_destroy(&attr); + throw ThreadSyscallException(__FILE__, __LINE__, rc); + } + } #endif + rc = pthread_mutex_init(&_mutex, &attr); + assert(rc == 0); + if(rc != 0) + { + pthread_mutexattr_destroy(&attr); + throw ThreadSyscallException(__FILE__, __LINE__, rc); + } + + rc = pthread_mutexattr_destroy(&attr); + assert(rc == 0); if(rc != 0) { throw ThreadSyscallException(__FILE__, __LINE__, rc); diff --git a/cpp/include/IceUtil/MutexProtocol.h b/cpp/include/IceUtil/MutexProtocol.h new file mode 100644 index 00000000000..b435b457bee --- /dev/null +++ b/cpp/include/IceUtil/MutexProtocol.h @@ -0,0 +1,28 @@ +// ********************************************************************** +// +// 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. +// +// ********************************************************************** + +#ifndef ICE_UTIL_MUTEX_PROTOCOL_H +#define ICE_UTIL_MUTEX_PROTOCOL_H + +#include <IceUtil/Config.h> + +namespace IceUtil +{ + +enum MutexProtocol +{ + PrioInherit, + PrioNone +}; + +ICE_UTIL_API MutexProtocol getDefaultMutexProtocol(); + +} // End namespace IceUtil + +#endif diff --git a/cpp/include/IceUtil/MutexPtrLock.h b/cpp/include/IceUtil/MutexPtrLock.h new file mode 100644 index 00000000000..e6fad2ba78d --- /dev/null +++ b/cpp/include/IceUtil/MutexPtrLock.h @@ -0,0 +1,83 @@ +// ********************************************************************** +// +// Copyright (c) 2003-2008 ZeroC, Inc. All rights reserved. +// +// This copy of Ice-E is licensed to you under the terms described in the +// ICEE_LICENSE file included in this distribution. +// +// ********************************************************************** + +#ifndef ICE_UTIL_MUTEX_PTR_LOCK_H +#define ICE_UTIL_MUTEX_PTR_LOCK_H + +#include <IceUtil/Config.h> +#include <IceUtil/ThreadException.h> + +namespace IceUtilInternal +{ + +template<class T> +class MutexPtrLock +{ +public: + + MutexPtrLock<T>(const T* mutex) : + _mutex(mutex), + _acquired(false) + { + if(_mutex) + { + _mutex->lock(); + _acquired = true; + } + } + + ~MutexPtrLock<T>() + { + if(_mutex && _acquired) + { + _mutex->unlock(); + } + } + + void acquire() const + { + if(_mutex) + { + _mutex->lock(); + _acquired = true; + } + } + + void release() const + { + if(_mutex) + { + if(!_acquired) + { + throw IceUtil::ThreadLockedException(__FILE__, __LINE__); + } + _mutex->unlock(); + _acquired = false; + } + } + + bool acquired() const + { + return _acquired; + } + +private: + + // Not implemented; prevents accidental use. + // + MutexPtrLock<T>(const MutexPtrLock<T>&); + MutexPtrLock<T>& operator=(const MutexPtrLock<T>&); + + const T* _mutex; + mutable bool _acquired; +}; + +} // End namespace IceUtilInternal + +#endif diff --git a/cpp/include/IceUtil/MutexPtrTryLock.h b/cpp/include/IceUtil/MutexPtrTryLock.h new file mode 100644 index 00000000000..4dba3a4795d --- /dev/null +++ b/cpp/include/IceUtil/MutexPtrTryLock.h @@ -0,0 +1,82 @@ +// ********************************************************************** +// +// Copyright (c) 2003-2008 ZeroC, Inc. All rights reserved. +// +// This copy of Ice-E is licensed to you under the terms described in the +// ICEE_LICENSE file included in this distribution. +// +// ********************************************************************** + +#ifndef ICE_UTIL_MUTEX_PTR_TRY_LOCK_H +#define ICE_UTIL_MUTEX_PTR_TRY_LOCK_H + +#include <IceUtil/Config.h> +#include <IceUtil/Mutex.h> + +namespace IceUtilInternal +{ + +template<class T> +class MutexPtrTryLock +{ +public: + + MutexPtrTryLock<T>(const T* mutex) : + _mutex(mutex), + _acquired(false) + { + if(_mutex) + { + _acquired = _mutex->tryLock(); + } + } + + ~MutexPtrTryLock<T>() + { + if(_mutex && _acquired) + { + _mutex->unlock(); + } + } + + void acquire() const + { + if(_mutex) + { + _mutex->lock(); + _acquired = true; + } + } + + void release() const + { + if(_mutex) + { + if(!_acquired) + { + throw IceUtil::ThreadLockedException(__FILE__, __LINE__); + } + _mutex->unlock(); + _acquired = false; + } + } + + bool acquired() const + { + return _acquired; + } + +private: + + // Not implemented; prevents accidental use. + // + MutexPtrTryLock<T>(const MutexPtrTryLock&); + MutexPtrTryLock<T>& operator=(const MutexPtrTryLock<T>&); + + const T* _mutex; + mutable bool _acquired; +}; + +} // End namespace IceUtilInternal + +#endif diff --git a/cpp/include/IceUtil/RWRecMutex.h b/cpp/include/IceUtil/RWRecMutex.h index a4cf81b18f5..b2433b62b5d 100644 --- a/cpp/include/IceUtil/RWRecMutex.h +++ b/cpp/include/IceUtil/RWRecMutex.h @@ -175,7 +175,7 @@ public: ~WLockT() { - if (_acquired) + if(_acquired) { _mutex.unlock(); } diff --git a/cpp/include/IceUtil/RecMutex.h b/cpp/include/IceUtil/RecMutex.h index 70aa66109a7..0954f51e829 100644 --- a/cpp/include/IceUtil/RecMutex.h +++ b/cpp/include/IceUtil/RecMutex.h @@ -13,6 +13,7 @@ #include <IceUtil/Config.h> #include <IceUtil/Lock.h> #include <IceUtil/ThreadException.h> +#include <IceUtil/MutexProtocol.h> namespace IceUtil { @@ -36,6 +37,7 @@ public: typedef TryLockT<RecMutex> TryLock; RecMutex(); + RecMutex(const MutexProtocol); ~RecMutex(); // @@ -67,6 +69,7 @@ public: private: + void init(const MutexProtocol); // noncopyable RecMutex(const RecMutex&); void operator=(const RecMutex&); diff --git a/cpp/include/IceUtil/StaticMutex.h b/cpp/include/IceUtil/StaticMutex.h index 9ba6f387c90..d7e4d3c0d72 100644 --- a/cpp/include/IceUtil/StaticMutex.h +++ b/cpp/include/IceUtil/StaticMutex.h @@ -114,12 +114,6 @@ private: # define ICE_STATIC_MUTEX_INITIALIZER { PTHREAD_MUTEX_INITIALIZER } #endif - -// A "shared" global mutex that can be used for very simple tasks -// which should not lock any other mutexes. -// -extern ICE_UTIL_API StaticMutex globalMutex; - // // For performance reasons the following functions are inlined. // diff --git a/cpp/include/IceUtil/Thread.h b/cpp/include/IceUtil/Thread.h index 0d47c810e57..08241d17aa8 100644 --- a/cpp/include/IceUtil/Thread.h +++ b/cpp/include/IceUtil/Thread.h @@ -110,6 +110,7 @@ public: virtual void run() = 0; ThreadControl start(size_t = 0); + ThreadControl start(size_t, int priority); ThreadControl getThreadControl() const; @@ -147,6 +148,12 @@ protected: #endif private: + +#ifdef _WIN32 +#else + ThreadControl start(size_t, bool, int); +#endif + Thread(const Thread&); // Copying is forbidden void operator=(const Thread&); // Assignment is forbidden }; diff --git a/cpp/include/IceUtil/Timer.h b/cpp/include/IceUtil/Timer.h index 2683c87d062..2fcdb41cf5f 100644 --- a/cpp/include/IceUtil/Timer.h +++ b/cpp/include/IceUtil/Timer.h @@ -52,6 +52,12 @@ public: // Timer(); + + // + // Construct a timer and starts its execution thread with the priority. + // + Timer(int priority); + // // Destroy the timer and detach its execution thread if the calling thread // is the timer thread, join the timer execution thread otherwise. |