You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@activemq.apache.org by ta...@apache.org on 2013/02/12 22:53:15 UTC
svn commit: r1445406 - in /activemq/activemq-cpp/trunk/activemq-cpp/src:
main/decaf/internal/util/concurrent/ main/decaf/util/concurrent/
test/decaf/util/concurrent/
Author: tabish
Date: Tue Feb 12 21:53:15 2013
New Revision: 1445406
URL: http://svn.apache.org/r1445406
Log:
Add a sanity check on mutex lock state when there's an exception in the synchronized block.
Modified:
activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/internal/util/concurrent/Threading.cpp
activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/internal/util/concurrent/Threading.h
activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/util/concurrent/Mutex.cpp
activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/util/concurrent/Mutex.h
activemq/activemq-cpp/trunk/activemq-cpp/src/test/decaf/util/concurrent/MutexTest.cpp
Modified: activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/internal/util/concurrent/Threading.cpp
URL: http://svn.apache.org/viewvc/activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/internal/util/concurrent/Threading.cpp?rev=1445406&r1=1445405&r2=1445406&view=diff
==============================================================================
--- activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/internal/util/concurrent/Threading.cpp (original)
+++ activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/internal/util/concurrent/Threading.cpp Tue Feb 12 21:53:15 2013
@@ -1507,6 +1507,16 @@ void Threading::returnMonitor(MonitorHan
}
////////////////////////////////////////////////////////////////////////////////
+bool Threading::isMonitorLocked(MonitorHandle* monitor) {
+
+ if (monitor != NULL) {
+ return monitor->owner != NULL;
+ }
+
+ return false;
+}
+
+////////////////////////////////////////////////////////////////////////////////
void Threading::enterMonitor(MonitorHandle* monitor) {
ThreadHandle* thisThread = getCurrentThreadHandle();
Modified: activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/internal/util/concurrent/Threading.h
URL: http://svn.apache.org/viewvc/activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/internal/util/concurrent/Threading.h?rev=1445406&r1=1445405&r2=1445406&view=diff
==============================================================================
--- activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/internal/util/concurrent/Threading.h (original)
+++ activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/internal/util/concurrent/Threading.h Tue Feb 12 21:53:15 2013
@@ -174,6 +174,13 @@ namespace concurrent {
*/
static void notifyAllWaiters(MonitorHandle* monitor);
+ /**
+ * Query the monitor object to determine if it is currently locked. This method is a mainly
+ * a diagnostic tool and its return value is not guaranteed to reflect the locked state after
+ * its been called as the state can change quickly.
+ */
+ static bool isMonitorLocked(MonitorHandle* monitor);
+
public: // Threads
/**
Modified: activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/util/concurrent/Mutex.cpp
URL: http://svn.apache.org/viewvc/activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/util/concurrent/Mutex.cpp?rev=1445406&r1=1445405&r2=1445406&view=diff
==============================================================================
--- activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/util/concurrent/Mutex.cpp (original)
+++ activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/util/concurrent/Mutex.cpp Tue Feb 12 21:53:15 2013
@@ -32,15 +32,15 @@ using namespace decaf::lang;
using namespace decaf::lang::exceptions;
////////////////////////////////////////////////////////////////////////////////
-namespace decaf{
-namespace util{
-namespace concurrent{
+namespace decaf {
+namespace util {
+namespace concurrent {
class MutexProperties {
private:
- MutexProperties( const MutexProperties& );
- MutexProperties& operator= ( const MutexProperties& );
+ MutexProperties(const MutexProperties&);
+ MutexProperties& operator=(const MutexProperties&);
public:
@@ -49,8 +49,8 @@ namespace concurrent{
}
MutexProperties(const std::string& name) : monitor(NULL), name(name) {
- if( this->name.empty() ) {
- this->name = DEFAULT_NAME_PREFIX + Integer::toString( ++id );
+ if (this->name.empty()) {
+ this->name = DEFAULT_NAME_PREFIX + Integer::toString(++id);
}
}
@@ -98,6 +98,15 @@ std::string Mutex::toString() const {
}
////////////////////////////////////////////////////////////////////////////////
+bool Mutex::isLocked() const {
+ if (this->properties->monitor != NULL) {
+ Threading::isMonitorLocked(this->properties->monitor);
+ }
+
+ return false;
+}
+
+////////////////////////////////////////////////////////////////////////////////
void Mutex::lock() {
if(this->properties->monitor == NULL) {
Modified: activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/util/concurrent/Mutex.h
URL: http://svn.apache.org/viewvc/activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/util/concurrent/Mutex.h?rev=1445406&r1=1445405&r2=1445406&view=diff
==============================================================================
--- activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/util/concurrent/Mutex.h (original)
+++ activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/util/concurrent/Mutex.h Tue Feb 12 21:53:15 2013
@@ -23,9 +23,9 @@
#include <decaf/lang/Thread.h>
#include <decaf/util/Config.h>
-namespace decaf{
-namespace util{
-namespace concurrent{
+namespace decaf {
+namespace util {
+namespace concurrent {
class MutexProperties;
@@ -36,21 +36,21 @@ namespace concurrent{
*
* @since 1.0
*/
- class DECAF_API Mutex : public Synchronizable {
+ class DECAF_API Mutex: public Synchronizable {
private:
MutexProperties* properties;
private:
- Mutex( const Mutex& src );
- Mutex& operator= ( const Mutex& src );
+ Mutex(const Mutex& src);
+ Mutex& operator=(const Mutex& src);
public:
Mutex();
- Mutex( const std::string& name );
+ Mutex(const std::string& name);
virtual ~Mutex();
@@ -58,7 +58,9 @@ namespace concurrent{
std::string toString() const;
- public: // Synchronizable API Implementation
+ bool isLocked() const;
+
+ public:
virtual void lock();
@@ -68,9 +70,9 @@ namespace concurrent{
virtual void wait();
- virtual void wait( long long millisecs );
+ virtual void wait(long long millisecs);
- virtual void wait( long long millisecs, int nanos );
+ virtual void wait(long long millisecs, int nanos);
virtual void notify();
Modified: activemq/activemq-cpp/trunk/activemq-cpp/src/test/decaf/util/concurrent/MutexTest.cpp
URL: http://svn.apache.org/viewvc/activemq/activemq-cpp/trunk/activemq-cpp/src/test/decaf/util/concurrent/MutexTest.cpp?rev=1445406&r1=1445405&r2=1445406&view=diff
==============================================================================
--- activemq/activemq-cpp/trunk/activemq-cpp/src/test/decaf/util/concurrent/MutexTest.cpp (original)
+++ activemq/activemq-cpp/trunk/activemq-cpp/src/test/decaf/util/concurrent/MutexTest.cpp Tue Feb 12 21:53:15 2013
@@ -46,6 +46,14 @@ void MutexTest::testConstructor() {
CPPUNIT_ASSERT( mutex.tryLock() == true );
mutex.unlock();
+
+ try {
+ synchronized(&mutex) {
+ throw Exception();
+ }
+ } catch (...) {}
+
+ CPPUNIT_ASSERT(!mutex.isLocked());
}
///////////////////////////////////////////////////////////////////////////////