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 2007/05/31 21:14:46 UTC

svn commit: r543221 - in /activemq/activemq-cpp/trunk/src/decaf/src/main/decaf/util/concurrent: CountDownLatch.cpp CountDownLatch.h

Author: tabish
Date: Thu May 31 12:14:45 2007
New Revision: 543221

URL: http://svn.apache.org/viewvc?view=rev&rev=543221
Log:
http://issues.apache.org/activemq/browse/AMQCPP-103

Building Decaf lib, remove sub folder from the activemq lib dir, going to top level.

Added:
    activemq/activemq-cpp/trunk/src/decaf/src/main/decaf/util/concurrent/CountDownLatch.cpp
    activemq/activemq-cpp/trunk/src/decaf/src/main/decaf/util/concurrent/CountDownLatch.h

Added: activemq/activemq-cpp/trunk/src/decaf/src/main/decaf/util/concurrent/CountDownLatch.cpp
URL: http://svn.apache.org/viewvc/activemq/activemq-cpp/trunk/src/decaf/src/main/decaf/util/concurrent/CountDownLatch.cpp?view=auto&rev=543221
==============================================================================
--- activemq/activemq-cpp/trunk/src/decaf/src/main/decaf/util/concurrent/CountDownLatch.cpp (added)
+++ activemq/activemq-cpp/trunk/src/decaf/src/main/decaf/util/concurrent/CountDownLatch.cpp Thu May 31 12:14:45 2007
@@ -0,0 +1,98 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#include "CountDownLatch.h"
+
+using namespace decaf;
+using namespace decaf::lang;
+using namespace decaf::util;
+using namespace decaf::util::concurrent;
+
+////////////////////////////////////////////////////////////////////////////////
+CountDownLatch::CountDownLatch( int count )
+{
+    this->count = count;
+}
+
+////////////////////////////////////////////////////////////////////////////////
+CountDownLatch::~CountDownLatch()
+{
+    try {
+
+        synchronized( &mutex ) {
+            mutex.notifyAll();
+        }
+    }
+    DECAF_CATCHALL_NOTHROW()
+}
+
+////////////////////////////////////////////////////////////////////////////////
+void CountDownLatch::await() throw ( lang::Exception ) {
+
+    try {
+
+        synchronized( &mutex ) {
+            if( count == 0 ){
+                return;
+            }
+
+            mutex.wait();
+        }
+    }
+    DECAF_CATCH_RETHROW( lang::Exception )
+    DECAF_CATCHALL_THROW( lang::Exception )
+}
+
+////////////////////////////////////////////////////////////////////////////////
+bool CountDownLatch::await( unsigned long timeOut ) throw ( lang::Exception ) {
+    try {
+
+        synchronized( &mutex ) {
+            if( count == 0 ){
+                return true;
+            }
+
+            mutex.wait( timeOut );
+
+            return count == 0;
+        }
+
+        return true;
+    }
+    DECAF_CATCH_RETHROW( lang::Exception )
+    DECAF_CATCHALL_THROW( lang::Exception )
+}
+
+////////////////////////////////////////////////////////////////////////////////
+void CountDownLatch::countDown() {
+    try {
+
+        if( count == 0 ) {
+            return;
+        }
+
+        synchronized( &mutex ) {
+            count--;
+
+            // Signal when done.
+            if( count == 0 ){
+                mutex.notifyAll();
+            }
+        }
+    }
+    DECAF_CATCHALL_NOTHROW()
+}

Added: activemq/activemq-cpp/trunk/src/decaf/src/main/decaf/util/concurrent/CountDownLatch.h
URL: http://svn.apache.org/viewvc/activemq/activemq-cpp/trunk/src/decaf/src/main/decaf/util/concurrent/CountDownLatch.h?view=auto&rev=543221
==============================================================================
--- activemq/activemq-cpp/trunk/src/decaf/src/main/decaf/util/concurrent/CountDownLatch.h (added)
+++ activemq/activemq-cpp/trunk/src/decaf/src/main/decaf/util/concurrent/CountDownLatch.h Thu May 31 12:14:45 2007
@@ -0,0 +1,84 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#ifndef _DECAF_CONCURRENT_COUNTDOWNLATCH_H_
+#define _DECAF_CONCURRENT_COUNTDOWNLATCH_H_
+
+#include <decaf/util/concurrent/Mutex.h>
+#include <decaf/util/Config.h>
+#include <decaf/lang/Exception.h>
+
+namespace decaf{
+namespace util{
+namespace concurrent{
+
+    class DECAF_API CountDownLatch
+    {
+    private:
+
+        /**
+         * number to count down to
+         */
+        int count;
+
+        /**
+         * Mutex to protect the counts, and wait on.
+         */
+        Mutex mutex;
+
+    public:
+
+        /**
+         * Constructor
+         * @param count - number to count down from.
+         */
+        CountDownLatch( int count );
+
+        virtual ~CountDownLatch();
+
+        /**
+         * Waits for the Count to be zero, and then returns
+         * @throws CMSException
+         */
+        virtual void await() throw ( lang::Exception );
+
+        /**
+         * Waits for the Count to hit zero, or a timeout.
+         * @param timeOut - time in milliseconds to wait.
+         * @returns true if the wait made it to count zero, otherwise false
+         */
+        virtual bool await( unsigned long timeOut )  throw ( lang::Exception );
+
+        /**
+         * Counts down the latch, releasing all waiting threads when
+         * the count hits zero.
+         */
+        virtual void countDown();
+
+        /**
+         * Gets the current count
+         * @returns int count value
+         */
+        virtual int getCount() const {
+            return this->count;
+        }
+
+    };
+
+}}}
+
+#endif /*_DECAF_CONCURRENT_COUNTDOWNLATCH_H_*/