Mercurial > hg > truffle
diff src/share/vm/utilities/ostream.hpp @ 2263:5841dc1964f0
7021531: lock ordering problems after fix for 6354181
Reviewed-by: kvn, jrose
author | never |
---|---|
date | Tue, 22 Feb 2011 15:26:36 -0800 |
parents | d8a72fbc4be7 |
children | 1d1603768966 |
line wrap: on
line diff
--- a/src/share/vm/utilities/ostream.hpp Wed Feb 09 15:02:23 2011 -0800 +++ b/src/share/vm/utilities/ostream.hpp Tue Feb 22 15:26:36 2011 -0800 @@ -123,18 +123,36 @@ // advisory locking for the shared tty stream: class ttyLocker: StackObj { + friend class ttyUnlocker; private: intx _holder; public: static intx hold_tty(); // returns a "holder" token static void release_tty(intx holder); // must witness same token + static bool release_tty_if_locked(); // returns true if lock was released static void break_tty_lock_for_safepoint(intx holder); ttyLocker() { _holder = hold_tty(); } ~ttyLocker() { release_tty(_holder); } }; +// Release the tty lock if it's held and reacquire it if it was +// locked. Used to avoid lock ordering problems. +class ttyUnlocker: StackObj { + private: + bool _was_locked; + public: + ttyUnlocker() { + _was_locked = ttyLocker::release_tty_if_locked(); + } + ~ttyUnlocker() { + if (_was_locked) { + ttyLocker::hold_tty(); + } + } +}; + // for writing to strings; buffer will expand automatically class stringStream : public outputStream { protected: