Return-Path: X-Original-To: apmail-activemq-commits-archive@www.apache.org Delivered-To: apmail-activemq-commits-archive@www.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id 574981027F for ; Tue, 13 Aug 2013 21:41:32 +0000 (UTC) Received: (qmail 89707 invoked by uid 500); 13 Aug 2013 21:41:32 -0000 Delivered-To: apmail-activemq-commits-archive@activemq.apache.org Received: (qmail 89685 invoked by uid 500); 13 Aug 2013 21:41:32 -0000 Mailing-List: contact commits-help@activemq.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@activemq.apache.org Delivered-To: mailing list commits@activemq.apache.org Received: (qmail 89678 invoked by uid 99); 13 Aug 2013 21:41:32 -0000 Received: from nike.apache.org (HELO nike.apache.org) (192.87.106.230) by apache.org (qpsmtpd/0.29) with ESMTP; Tue, 13 Aug 2013 21:41:32 +0000 X-ASF-Spam-Status: No, hits=-2000.0 required=5.0 tests=ALL_TRUSTED X-Spam-Check-By: apache.org Received: from [140.211.11.4] (HELO eris.apache.org) (140.211.11.4) by apache.org (qpsmtpd/0.29) with ESMTP; Tue, 13 Aug 2013 21:41:29 +0000 Received: from eris.apache.org (localhost [127.0.0.1]) by eris.apache.org (Postfix) with ESMTP id E5B1423889E0; Tue, 13 Aug 2013 21:41:07 +0000 (UTC) Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: svn commit: r1513662 - /activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/util/concurrent/locks/ReentrantReadWriteLock.cpp Date: Tue, 13 Aug 2013 21:41:07 -0000 To: commits@activemq.apache.org From: tabish@apache.org X-Mailer: svnmailer-1.0.9 Message-Id: <20130813214107.E5B1423889E0@eris.apache.org> X-Virus-Checked: Checked by ClamAV on apache.org Author: tabish Date: Tue Aug 13 21:41:07 2013 New Revision: 1513662 URL: http://svn.apache.org/r1513662 Log: fix for: https://issues.apache.org/jira/browse/AMQCPP-506 Remove the cachedHoldCounter optimization for now. Modified: activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/util/concurrent/locks/ReentrantReadWriteLock.cpp Modified: activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/util/concurrent/locks/ReentrantReadWriteLock.cpp URL: http://svn.apache.org/viewvc/activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/util/concurrent/locks/ReentrantReadWriteLock.cpp?rev=1513662&r1=1513661&r2=1513662&view=diff ============================================================================== --- activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/util/concurrent/locks/ReentrantReadWriteLock.cpp (original) +++ activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/util/concurrent/locks/ReentrantReadWriteLock.cpp Tue Aug 13 21:41:07 2013 @@ -23,6 +23,7 @@ #include #include #include +#include using namespace decaf; using namespace decaf::lang; @@ -30,6 +31,7 @@ using namespace decaf::lang::exceptions; using namespace decaf::util; using namespace decaf::util::concurrent; using namespace decaf::util::concurrent::locks; +using namespace decaf::util::concurrent::atomic; //////////////////////////////////////////////////////////////////////////////// namespace { @@ -39,10 +41,10 @@ namespace { * cached in cachedHoldCounter in class Sync */ struct HoldCounter { - int count; Thread* thread; + int count; - HoldCounter() : count(0), thread(Thread::currentThread()) {} + HoldCounter() : thread(Thread::currentThread()), count(0) {} }; class ThreadLocalHoldCounter : public ThreadLocal { @@ -97,14 +99,6 @@ namespace { ThreadLocalHoldCounter readHolds; /** - * The hold count of the last thread to successfully acquire - * readLock. This saves ThreadLocal lookup in the common case - * where the next thread to release is the last one to - * acquire. - */ - HoldCounter cachedHoldCounter; - - /** * firstReader is the first thread to have acquired the read lock. * firstReaderHoldCount is firstReader's hold count. * @@ -120,7 +114,7 @@ namespace { public: - Sync() : readHolds(), cachedHoldCounter(), firstReader(NULL), firstReaderHoldCount(0) {} + Sync() : readHolds(), firstReader(NULL), firstReaderHoldCount(0) {} virtual ~Sync() {} @@ -193,10 +187,7 @@ namespace { firstReaderHoldCount--; } } else { - HoldCounter rh = cachedHoldCounter; - if (rh.thread == NULL || rh.thread != current) { - rh = readHolds.get(); - } + HoldCounter rh = readHolds.get(); int count = rh.count; if (count <= 1) { readHolds.remove(); @@ -207,7 +198,6 @@ namespace { } --rh.count; readHolds.set(rh); - cachedHoldCounter = rh; } for (;;) { @@ -248,16 +238,9 @@ namespace { } else if (firstReader == current) { firstReaderHoldCount++; } else { - HoldCounter rh = cachedHoldCounter; - if (rh.thread == NULL || rh.thread != current) { - cachedHoldCounter = rh = readHolds.get(); - } else if (rh.count == 0) { - readHolds.set(rh); - } - + HoldCounter rh = readHolds.get(); rh.count++; readHolds.set(rh); - cachedHoldCounter = rh; } return 1; } @@ -283,16 +266,13 @@ namespace { } else if (readerShouldBlock()) { // Make sure we're not acquiring read lock reentrantly if (firstReader == current) { - // assert firstReaderHoldCount > 0; + if (firstReaderHoldCount > 0) { + throw Exception(__FILE__, __LINE__, "Read lock should not be aquired reentrantlly."); + } } else { - if (rh.thread == NULL) { - rh = cachedHoldCounter; - if (rh.thread == NULL || rh.thread != current) { - rh = readHolds.get(); - if (rh.count == 0) { - readHolds.remove(); - } - } + rh = readHolds.get(); + if (rh.count == 0) { + readHolds.remove(); } if (rh.count == 0) { @@ -310,17 +290,9 @@ namespace { } else if (firstReader == current) { firstReaderHoldCount++; } else { - if (rh.thread == NULL) { - rh = cachedHoldCounter; - } - if (rh.thread == NULL || rh.thread != current) { - rh = readHolds.get(); - } else if (rh.count == 0) { - readHolds.set(rh); - } + rh = readHolds.get(); rh.count++; readHolds.set(rh); - cachedHoldCounter = rh; // cache for release } return 1; } @@ -374,15 +346,9 @@ namespace { } else if (firstReader == current) { firstReaderHoldCount++; } else { - HoldCounter rh = cachedHoldCounter; - if (rh.thread == NULL || rh.thread != current) { - cachedHoldCounter = rh = readHolds.get(); - } else if (rh.count == 0) { - readHolds.set(rh); - } + HoldCounter rh = readHolds.get();//cachedHoldCounter; rh.count++; readHolds.set(rh); - cachedHoldCounter = rh; } return true; } @@ -426,11 +392,6 @@ namespace { return firstReaderHoldCount; } - HoldCounter rh = cachedHoldCounter; - if (rh.thread != NULL && rh.thread == current) { - return rh.count; - } - int count = readHolds.get().count; if (count == 0) { readHolds.remove();