[omniORB] Recursive mutex class for omnithreads
Alex Tingle
alex.omniorb at firetree.net
Tue Jun 28 23:54:09 BST 2005
Hi Peter,
There already is an omni recursive mutex, it's just not exported as part of the generic omnithread library.
Look in: include/omniORB4/internal/rmutex.h & src/lib/omniORB/orbcore/rmutex.cc
-Alex
--
On Tue, 28 Jun 2005 07:26:22 -0700
"Peter S. Housel" <housel at acm.org> wrote:
> It would be nice if omnithreads provided a recursive mutex class. The
> following is a portable implementation of recursive mutexes in terms of
> the other omnithreads primitives.
>
> class omni_recursive_mutex {
> omni_mutex nesting_mutex_;
> omni_condition cond_;
> volatile unsigned level_;
> volatile omni_thread *thread_;
> public:
> omni_recursive_mutex()
> : cond_(&nesting_mutex_), level_(0), thread_(0) {
> }
> void lock() {
> nesting_mutex_.lock();
> if(level_ == 0) {
> thread_ = omni_thread::self();
> } else if(thread_ != omni_thread::self()) {
> while(level_ > 0)
> cond_.wait();
> thread_ = omni_thread::self();
> }
> ++level_;
> nesting_mutex_.unlock();
> }
> void unlock() {
> nesting_mutex_.lock();
> if(--level_ == 0) {
> thread_ = 0;
> cond_.signal();
> }
> nesting_mutex_.unlock();
> }
> };
>
> --
> Peter S. Housel <housel at acm.org>
>
> _______________________________________________
> omniORB-list mailing list
> omniORB-list at omniorb-support.com
> http://www.omniorb-support.com/mailman/listinfo/omniorb-list
--
:: alex tingle
:: http://www.firetree.net/consulting/
:: alex.tingle AT firetree.net +44-7901-552763
More information about the omniORB-list
mailing list