activemq-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From tab...@apache.org
Subject svn commit: r820258 - in /activemq/activemq-cpp/trunk/activemq-cpp: ./ src/main/ src/main/decaf/lang/ src/main/decaf/util/concurrent/locks/ src/test/ src/test/decaf/util/concurrent/locks/
Date Wed, 30 Sep 2009 12:51:03 GMT
Author: tabish
Date: Wed Sep 30 12:51:02 2009
New Revision: 820258

URL: http://svn.apache.org/viewvc?rev=820258&view=rev
Log:
Adds the ability to park and unpark a Thread from the LockSupport class, adds tests as well.

Added:
    activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/util/concurrent/locks/LockSupport.cpp
  (with props)
    activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/util/concurrent/locks/LockSupport.h
  (with props)
    activemq/activemq-cpp/trunk/activemq-cpp/src/test/decaf/util/concurrent/locks/
    activemq/activemq-cpp/trunk/activemq-cpp/src/test/decaf/util/concurrent/locks/LockSupportTest.cpp
  (with props)
    activemq/activemq-cpp/trunk/activemq-cpp/src/test/decaf/util/concurrent/locks/LockSupportTest.h
  (with props)
Modified:
    activemq/activemq-cpp/trunk/activemq-cpp/configure.ac
    activemq/activemq-cpp/trunk/activemq-cpp/src/main/Makefile.am
    activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/lang/Thread.cpp
    activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/lang/Thread.h
    activemq/activemq-cpp/trunk/activemq-cpp/src/test/Makefile.am
    activemq/activemq-cpp/trunk/activemq-cpp/src/test/testRegistry.cpp

Modified: activemq/activemq-cpp/trunk/activemq-cpp/configure.ac
URL: http://svn.apache.org/viewvc/activemq/activemq-cpp/trunk/activemq-cpp/configure.ac?rev=820258&r1=820257&r2=820258&view=diff
==============================================================================
--- activemq/activemq-cpp/trunk/activemq-cpp/configure.ac (original)
+++ activemq/activemq-cpp/trunk/activemq-cpp/configure.ac Wed Sep 30 12:51:02 2009
@@ -113,6 +113,7 @@
 AC_CHECK_HEADERS([sys/resource.h])
 AC_CHECK_HEADERS([pthread.h])
 AC_CHECK_HEADERS([errno.h])
+AC_CHECK_HEADERS([semaphore.h])
 
 AC_CHECK_FUNCS([ioctl select gettimeofday time ftime])
 

Modified: activemq/activemq-cpp/trunk/activemq-cpp/src/main/Makefile.am
URL: http://svn.apache.org/viewvc/activemq/activemq-cpp/trunk/activemq-cpp/src/main/Makefile.am?rev=820258&r1=820257&r2=820258&view=diff
==============================================================================
--- activemq/activemq-cpp/trunk/activemq-cpp/src/main/Makefile.am (original)
+++ activemq/activemq-cpp/trunk/activemq-cpp/src/main/Makefile.am Wed Sep 30 12:51:02 2009
@@ -550,6 +550,7 @@
     decaf/util/concurrent/TimeUnit.cpp \
     decaf/util/concurrent/atomic/AtomicBoolean.cpp \
     decaf/util/concurrent/atomic/AtomicInteger.cpp \
+    decaf/util/concurrent/locks/LockSupport.cpp \
     decaf/util/concurrent/locks/ReentrantLock.cpp \
     decaf/util/logging/LogManager.cpp \
     decaf/util/logging/LogWriter.cpp \
@@ -1258,6 +1259,7 @@
     decaf/util/concurrent/atomic/AtomicReference.h \
     decaf/util/concurrent/locks/Condition.h \
     decaf/util/concurrent/locks/Lock.h \
+    decaf/util/concurrent/locks/LockSupport.h \
     decaf/util/concurrent/locks/ReadWriteLock.h \
     decaf/util/concurrent/locks/ReentrantLock.h \
     decaf/util/logging/ConsoleHandler.h \

Modified: activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/lang/Thread.cpp
URL: http://svn.apache.org/viewvc/activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/lang/Thread.cpp?rev=820258&r1=820257&r2=820258&view=diff
==============================================================================
--- activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/lang/Thread.cpp (original)
+++ activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/lang/Thread.cpp Wed Sep 30 12:51:02
2009
@@ -29,6 +29,7 @@
 #include <decaf/lang/exceptions/RuntimeException.h>
 #include <decaf/lang/exceptions/NullPointerException.h>
 #include <decaf/util/concurrent/TimeUnit.h>
+#include <decaf/util/concurrent/Mutex.h>
 
 #if HAVE_PTHREAD_H
 #include <pthread.h>
@@ -59,6 +60,7 @@
 using namespace decaf::internal;
 using namespace decaf::lang;
 using namespace decaf::lang::exceptions;
+using namespace decaf::util;
 using namespace decaf::util::concurrent;
 
 ////////////////////////////////////////////////////////////////////////////////
@@ -68,10 +70,6 @@
     class ThreadProperties {
     public:
 
-        /**
-         * The task to be run by this thread, defaults to
-         * this thread object.
-         */
         Runnable* task;
 
         /**
@@ -84,41 +82,30 @@
             HANDLE handle;
         #endif
 
-        /**
-         * Current state of this thread.
-         */
         Thread::State state;
-
-        /**
-         * The Assigned name of this thread.
-         */
         std::string name;
-
-        /**
-         * The currently assigned priority
-         */
         int priority;
+        bool interrupted;
+        bool unparked;
+        bool parked;
+        decaf::util::concurrent::Mutex mutex;
 
-        /**
-         * static value that holds the incrementing Thread ID for unnamed threads.
-         */
         static unsigned int id;
 
-        /**
-         * The handler to invoke if the thread terminates due to an exception that
-         * was not caught in the user's run method.
-         */
         Thread::UncaughtExceptionHandler* exHandler;
-
-        /**
-         * The Thread that created this Object.
-         */
         Thread* parent;
 
     public:
 
         ThreadProperties() {
 
+            this->priority = Thread::NORM_PRIORITY;
+            this->state = Thread::NEW;
+            this->interrupted = false;
+            this->parked = false;
+            this->unparked = false;
+            this->parent = NULL;
+
             #ifdef HAVE_PTHREAD_H
                 pthread_attr_init( &attributes );
             #endif
@@ -602,3 +589,67 @@
 
     return (Thread*)result;
 }
+
+////////////////////////////////////////////////////////////////////////////////
+void Thread::park( Thread* thread ) {
+
+    if( thread == NULL ) {
+        throw NullPointerException(
+            __FILE__, __LINE__, "Null Thread Pointer Passed." );
+    }
+
+    Thread::park( thread, 0LL, 0LL );
+}
+
+////////////////////////////////////////////////////////////////////////////////
+void Thread::park( Thread* thread, long long mills, long long nanos ) {
+
+    if( thread == NULL ) {
+        throw NullPointerException(
+            __FILE__, __LINE__, "Null Thread Pointer Passed." );
+    }
+
+    synchronized( &thread->properties->mutex ) {
+
+        if( thread->properties->unparked ) {
+            thread->properties->unparked = false;
+            return;
+        }
+
+        thread->properties->parked = true;
+
+        if( mills == 0 && nanos == 0 ) {
+            thread->properties->mutex.wait();
+        } else {
+            thread->properties->mutex.wait( mills, nanos );
+        }
+
+        thread->properties->parked = false;
+
+        // consume the unparked token.
+        thread->properties->unparked = false;
+    }
+}
+
+////////////////////////////////////////////////////////////////////////////////
+void Thread::unpark( Thread* thread ) {
+
+    if( thread == NULL ) {
+        throw NullPointerException(
+            __FILE__, __LINE__, "Null Thread Pointer Passed." );
+    }
+
+    synchronized( &thread->properties->mutex ) {
+
+        // Set the unparked token, if the thread is parked it will consume
+        // it when it resumes, otherwise the next call to park will consume
+        // it without needing to actually wait.
+        thread->properties->unparked = true;
+
+        // If the thread is actually parked then we send it a signal so
+        // that it will resume.
+        if( thread->properties->parked ) {
+            thread->properties->mutex.notifyAll();
+        }
+    }
+}

Modified: activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/lang/Thread.h
URL: http://svn.apache.org/viewvc/activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/lang/Thread.h?rev=820258&r1=820257&r2=820258&view=diff
==============================================================================
--- activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/lang/Thread.h (original)
+++ activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/lang/Thread.h Wed Sep 30 12:51:02
2009
@@ -369,6 +369,15 @@
         // Threading library.
         static void shutdownThreading();
 
+        // Called from LockSupport to Park a Thread (suspend it from execution)
+        static void park( Thread* thread );
+
+        // Called from LockSupport to Park a Thread (suspend it from execution)
+        static void park( Thread* thread, long long mills, long long nanos );
+
+        // Called from LockSupport to UnPark a Thread (resume its execution status).
+        static void unpark( Thread* thread );
+
         // Allow some Decaf Classes greater access to the Threading model.
         friend class decaf::util::concurrent::locks::LockSupport;
         friend class decaf::lang::Runtime;

Added: activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/util/concurrent/locks/LockSupport.cpp
URL: http://svn.apache.org/viewvc/activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/util/concurrent/locks/LockSupport.cpp?rev=820258&view=auto
==============================================================================
--- activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/util/concurrent/locks/LockSupport.cpp
(added)
+++ activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/util/concurrent/locks/LockSupport.cpp
Wed Sep 30 12:51:02 2009
@@ -0,0 +1,76 @@
+/*
+ * 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 "LockSupport.h"
+
+#include <decaf/lang/Exception.h>
+#include <decaf/lang/Thread.h>
+#include <decaf/lang/System.h>
+
+using namespace decaf;
+using namespace decaf::lang;
+using namespace decaf::util;
+using namespace decaf::util::concurrent;
+using namespace decaf::util::concurrent::locks;
+
+////////////////////////////////////////////////////////////////////////////////
+LockSupport::LockSupport() {
+}
+
+////////////////////////////////////////////////////////////////////////////////
+LockSupport::~LockSupport() {
+}
+
+////////////////////////////////////////////////////////////////////////////////
+void LockSupport::unpark( decaf::lang::Thread* thread ) throw() {
+
+    try{
+        Thread::unpark( thread );
+    } DECAF_CATCHALL_NOTHROW()
+}
+
+////////////////////////////////////////////////////////////////////////////////
+void LockSupport::park() throw() {
+
+    try{
+        Thread::park( Thread::currentThread() );
+    } DECAF_CATCHALL_NOTHROW()
+}
+
+////////////////////////////////////////////////////////////////////////////////
+void LockSupport::parkNanos( long long nanos ) throw() {
+
+    try{
+        Thread::park( Thread::currentThread(), 0, nanos );
+    } DECAF_CATCHALL_NOTHROW()
+}
+
+////////////////////////////////////////////////////////////////////////////////
+void LockSupport::parkUntil( long long deadline ) throw() {
+
+    try{
+
+        long long now = System::currentTimeMillis();
+
+        if( deadline < now ) {
+            return;
+        }
+
+        Thread::park( Thread::currentThread(), ( deadline - now ), 0 );
+
+    } DECAF_CATCHALL_NOTHROW()
+}

Propchange: activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/util/concurrent/locks/LockSupport.cpp
------------------------------------------------------------------------------
    svn:eol-style = native

Added: activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/util/concurrent/locks/LockSupport.h
URL: http://svn.apache.org/viewvc/activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/util/concurrent/locks/LockSupport.h?rev=820258&view=auto
==============================================================================
--- activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/util/concurrent/locks/LockSupport.h
(added)
+++ activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/util/concurrent/locks/LockSupport.h
Wed Sep 30 12:51:02 2009
@@ -0,0 +1,181 @@
+/*
+ * 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_UTIL_CONCURRENT_LOCKSUPPORT_H_
+#define _DECAF_UTIL_CONCURRENT_LOCKSUPPORT_H_
+
+#include <decaf/util/Config.h>
+
+namespace decaf {
+namespace lang{
+    class Thread;
+}
+namespace util {
+namespace concurrent {
+namespace locks {
+
+    /**
+     * Basic thread blocking primitives for creating locks and other synchronization classes.
+     *
+     * This class associates, with each thread that uses it, a permit (in the sense of the
+     * Semaphore class). A call to park will return immediately if the permit is available,
+     * consuming it in the process; otherwise it may block. A call to unpark makes the permit
+     * available, if it was not already available. (Unlike with Semaphores though, permits
do
+     * not accumulate. There is at most one.)
+     *
+     * Methods park and unpark provide efficient means of blocking and unblocking threads
+     * Races between one thread invoking park and another thread trying to unpark it will
+     * preserve liveness, due to the permit. Additionally, park will return if the caller's
+     * thread was interrupted, and timeout versions are supported. The park method may also
+     * return at any other time, for "no reason", so in general must be invoked within a
loop
+     * that rechecks conditions upon return. In this sense park serves as an optimization
of a
+     * "busy wait" that does not waste as much time spinning, but must be paired with an
unpark
+     * to be effective.
+     *
+     * These methods are designed to be used as tools for creating higher-level synchronization
+     * utilities, and are not in themselves useful for most concurrency control applications.
+     * The park method is designed for use only in constructions of the form:
+     *
+     *   while (!canProceed()) { ... LockSupport.park(this); }
+     *
+     * where neither canProceed nor any other actions prior to the call to park entail locking
or
+     * blocking. Because only one permit is associated with each thread, any intermediary
uses of
+     * park could interfere with its intended effects.
+     *
+     * Sample Usage. Here is a sketch of a first-in-first-out non-reentrant lock class:
+     *
+     *   class FIFOMutex {
+     *   private:
+     *
+     *      AtomicBoolean locked;
+     *      ConcurrentLinkedQueue<Thread*> waiters;
+     *
+     *   public:
+     *
+     *      void lock() {
+     *
+     *         bool wasInterrupted = false;
+     *         Thread* current = Thread::currentThread();
+     *         waiters.add( current );
+     *
+     *         // Block while not first in queue or cannot acquire lock
+     *         while( waiters.peek() != current ||
+     *                !locked.compareAndSet( false, true ) ) {
+     *
+     *            LockSupport.park(this);
+     *            if( Thread::interrupted() ) // ignore interrupts while waiting
+     *               wasInterrupted = true;
+     *            }
+     *
+     *            waiters.remove();
+     *            if( wasInterrupted )          // reassert interrupt status on exit
+     *               current.interrupt();
+     *      }
+     *
+     *      void unlock() {
+     *         locked.set( false );
+     *         LockSupport.unpark( waiters.peek() );
+     *      }
+     *   };
+     *
+     * @since 1.0
+     */
+    class DECAF_API LockSupport {
+    private:
+
+        LockSupport();
+
+    public:
+
+        ~LockSupport();
+
+        /**
+         * Makes available the permit for the given thread, if it was not already available.
If
+         * the thread was blocked on park then it will unblock. Otherwise, its next call
to park
+         * is guaranteed not to block. This operation is not guaranteed to have any effect
at all
+         * if the given thread has not been started.
+         *
+         * @param thread the thread to unport, or NULL in which case the method has no effect.
+         */
+        static void unpark( decaf::lang::Thread* thread ) throw();
+
+        /**
+         * Disables the current thread for thread scheduling purposes unless the permit is
available.
+         *
+         * If the permit is available then it is consumed and the call returns immediately;
otherwise
+         * the current thread becomes disabled for thread scheduling purposes and lies dormant
until
+         * one of three things happens:
+         *
+         *   * Some other thread invokes unpark with the current thread as the target; or
+         *   * Some other thread interrupts the current thread; or
+         *   * The call spuriously (that is, for no reason) returns.
+         *
+         * This method does not report which of these caused the method to return. Callers
should
+         * re-check the conditions which caused the thread to park in the first place. Callers
may
+         * also determine, for example, the interrupt status of the thread upon return.
+         */
+        static void park() throw();
+
+        /**
+         * Disables the current thread for thread scheduling purposes, for up to the specified
+         * waiting time, unless the permit is available.
+         *
+         * If the permit is available then it is consumed and the call returns immediately;
+         * otherwise the current thread becomes disabled for thread scheduling purposes and
lies
+         * dormant until one of four things happens:
+         *
+         *   * Some other thread invokes unpark with the current thread as the target; or
+         *   * Some other thread interrupts the current thread; or
+         *   * The specified waiting time elapses; or
+         *   * The call spuriously (that is, for no reason) returns.
+         *
+         * This method does not report which of these caused the method to return. Callers
should
+         * re-check the conditions which caused the thread to park in the first place. Callers
may
+         * also determine, for example, the interrupt status of the thread, or the elapsed
time
+         * upon return.
+         *
+         * @param nanos the maximum number of nanoseconds to wait
+         */
+        static void parkNanos( long long nanos ) throw();
+
+        /**
+         * Disables the current thread for thread scheduling purposes, until the specified
deadline,
+         * unless the permit is available.
+         *
+         * If the permit is available then it is consumed and the call returns immediately;
otherwise
+         * the current thread becomes disabled for thread scheduling purposes and lies dormant
until
+         * one of four things happens:
+         *
+         *   * Some other thread invokes unpark with the current thread as the target; or
+         *   * Some other thread interrupts the current thread; or
+         *   * The specified deadline passes; or
+         *   * The call spuriously (that is, for no reason) returns.
+         *
+         * This method does not report which of these caused the method to return. Callers
should
+         * re-check the conditions which caused the thread to park in the first place. Callers
may
+         * also determine, for example, the interrupt status of the thread, or the current
time
+         * upon return.
+         *
+         * @param deadline the absolute time, in milliseconds from the Epoch, to wait until
+         */
+        static void parkUntil( long long deadline ) throw();
+
+    };
+
+}}}}
+
+#endif /* _DECAF_UTIL_CONCURRENT_LOCKSUPPORT_H_ */

Propchange: activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/util/concurrent/locks/LockSupport.h
------------------------------------------------------------------------------
    svn:eol-style = native

Modified: activemq/activemq-cpp/trunk/activemq-cpp/src/test/Makefile.am
URL: http://svn.apache.org/viewvc/activemq/activemq-cpp/trunk/activemq-cpp/src/test/Makefile.am?rev=820258&r1=820257&r2=820258&view=diff
==============================================================================
--- activemq/activemq-cpp/trunk/activemq-cpp/src/test/Makefile.am (original)
+++ activemq/activemq-cpp/trunk/activemq-cpp/src/test/Makefile.am Wed Sep 30 12:51:02 2009
@@ -128,6 +128,7 @@
     decaf/util/concurrent/atomic/AtomicBooleanTest.cpp \
     decaf/util/concurrent/atomic/AtomicIntegerTest.cpp \
     decaf/util/concurrent/atomic/AtomicReferenceTest.cpp \
+    decaf/util/concurrent/locks/LockSupportTest.cpp \
     main.cpp \
     testRegistry.cpp \
     util/teamcity/TeamCityProgressListener.cpp
@@ -254,6 +255,7 @@
     decaf/util/concurrent/atomic/AtomicBooleanTest.h \
     decaf/util/concurrent/atomic/AtomicIntegerTest.h \
     decaf/util/concurrent/atomic/AtomicReferenceTest.h \
+    decaf/util/concurrent/locks/LockSupportTest.h \
     util/teamcity/TeamCityProgressListener.h
 
 

Added: activemq/activemq-cpp/trunk/activemq-cpp/src/test/decaf/util/concurrent/locks/LockSupportTest.cpp
URL: http://svn.apache.org/viewvc/activemq/activemq-cpp/trunk/activemq-cpp/src/test/decaf/util/concurrent/locks/LockSupportTest.cpp?rev=820258&view=auto
==============================================================================
--- activemq/activemq-cpp/trunk/activemq-cpp/src/test/decaf/util/concurrent/locks/LockSupportTest.cpp
(added)
+++ activemq/activemq-cpp/trunk/activemq-cpp/src/test/decaf/util/concurrent/locks/LockSupportTest.cpp
Wed Sep 30 12:51:02 2009
@@ -0,0 +1,155 @@
+/*
+ * 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 "LockSupportTest.h"
+
+#include <decaf/lang/System.h>
+#include <decaf/lang/Thread.h>
+#include <decaf/lang/Runnable.h>
+#include <decaf/util/Date.h>
+#include <decaf/util/concurrent/locks/LockSupport.h>
+
+using namespace std;
+using namespace decaf;
+using namespace decaf::lang;
+using namespace decaf::util;
+using namespace decaf::util::concurrent;
+using namespace decaf::util::concurrent::locks;
+
+////////////////////////////////////////////////////////////////////////////////
+LockSupportTest::LockSupportTest() {
+}
+
+////////////////////////////////////////////////////////////////////////////////
+LockSupportTest::~LockSupportTest() {
+}
+
+////////////////////////////////////////////////////////////////////////////////
+class ParkTestThread : public Thread {
+public:
+
+    virtual void run() {
+        try{
+            LockSupport::park();
+        } catch(...) {
+            CPPUNIT_FAIL("Caught an unexpected exception");
+        }
+    }
+
+};
+
+////////////////////////////////////////////////////////////////////////////////
+void LockSupportTest::testPark() {
+
+    ParkTestThread t;
+
+    try {
+
+        t.start();
+        Thread::sleep( 1000 );
+        LockSupport::unpark( &t );
+        t.join();
+
+    } catch(...) {
+        CPPUNIT_FAIL("Caught an unexpected exception");
+    }
+}
+
+////////////////////////////////////////////////////////////////////////////////
+class ParkTest2Thread : public Thread {
+public:
+
+    virtual void run() {
+        try{
+            Thread::sleep( 1000 );
+            LockSupport::park();
+        } catch(...) {
+            CPPUNIT_FAIL("Caught an unexpected exception");
+        }
+    }
+
+};
+
+////////////////////////////////////////////////////////////////////////////////
+void LockSupportTest::testPark2() {
+
+    ParkTest2Thread t;
+
+    try {
+        t.start();
+        long long before = System::currentTimeMillis();
+        LockSupport::unpark( &t );
+        long long after = System::currentTimeMillis();
+        CPPUNIT_ASSERT( after - before < 1000 );
+        t.join();
+    } catch(...) {
+        CPPUNIT_FAIL("Caught an unexpected exception");
+    }
+}
+
+////////////////////////////////////////////////////////////////////////////////
+class ParkNanosTestThread : public Thread {
+public:
+
+    virtual void run() {
+        try{
+            LockSupport::parkNanos( 1111 );
+        } catch(...) {
+            CPPUNIT_FAIL("Caught an unexpected exception");
+        }
+    }
+};
+
+////////////////////////////////////////////////////////////////////////////////
+void LockSupportTest::testParkNanos() {
+
+    ParkNanosTestThread t;
+
+    try {
+        t.start();
+        t.join();
+    } catch(...) {
+        CPPUNIT_FAIL("Caught an unexpected exception");
+    }
+}
+
+////////////////////////////////////////////////////////////////////////////////
+class ParkUntilTestThread : public Thread {
+public:
+
+    virtual void run() {
+        try{
+            long long deadline = Date().getTime() + 100;
+            LockSupport::parkUntil( deadline );
+        } catch(...) {
+            CPPUNIT_FAIL("Caught an unexpected exception");
+        }
+    }
+};
+
+////////////////////////////////////////////////////////////////////////////////
+void LockSupportTest::testParkUntil() {
+
+    ParkUntilTestThread t;
+
+    try {
+        t.start();
+        t.join();
+    } catch(...) {
+        CPPUNIT_FAIL("Caught an unexpected exception");
+    }
+}

Propchange: activemq/activemq-cpp/trunk/activemq-cpp/src/test/decaf/util/concurrent/locks/LockSupportTest.cpp
------------------------------------------------------------------------------
    svn:eol-style = native

Added: activemq/activemq-cpp/trunk/activemq-cpp/src/test/decaf/util/concurrent/locks/LockSupportTest.h
URL: http://svn.apache.org/viewvc/activemq/activemq-cpp/trunk/activemq-cpp/src/test/decaf/util/concurrent/locks/LockSupportTest.h?rev=820258&view=auto
==============================================================================
--- activemq/activemq-cpp/trunk/activemq-cpp/src/test/decaf/util/concurrent/locks/LockSupportTest.h
(added)
+++ activemq/activemq-cpp/trunk/activemq-cpp/src/test/decaf/util/concurrent/locks/LockSupportTest.h
Wed Sep 30 12:51:02 2009
@@ -0,0 +1,53 @@
+/*
+ * 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_UTIL_CONCURRENT_LOCKS_LOCKSUPPORTTEST_H_
+#define _DECAF_UTIL_CONCURRENT_LOCKS_LOCKSUPPORTTEST_H_
+
+#include <cppunit/TestFixture.h>
+#include <cppunit/extensions/HelperMacros.h>
+
+namespace decaf {
+namespace util {
+namespace concurrent {
+namespace locks {
+
+    class LockSupportTest : public CppUnit::TestFixture {
+
+        CPPUNIT_TEST_SUITE( LockSupportTest );
+        CPPUNIT_TEST( testPark );
+        CPPUNIT_TEST( testPark2 );
+        CPPUNIT_TEST( testParkNanos );
+        CPPUNIT_TEST( testParkUntil );
+        CPPUNIT_TEST_SUITE_END();
+
+    public:
+
+        LockSupportTest();
+
+        virtual ~LockSupportTest();
+
+        void testPark();
+        void testPark2();
+        void testParkNanos();
+        void testParkUntil();
+
+    };
+
+}}}}
+
+#endif /* _DECAF_UTIL_CONCURRENT_LOCKS_LOCKSUPPORTTEST_H_ */

Propchange: activemq/activemq-cpp/trunk/activemq-cpp/src/test/decaf/util/concurrent/locks/LockSupportTest.h
------------------------------------------------------------------------------
    svn:eol-style = native

Modified: activemq/activemq-cpp/trunk/activemq-cpp/src/test/testRegistry.cpp
URL: http://svn.apache.org/viewvc/activemq/activemq-cpp/trunk/activemq-cpp/src/test/testRegistry.cpp?rev=820258&r1=820257&r2=820258&view=diff
==============================================================================
--- activemq/activemq-cpp/trunk/activemq-cpp/src/test/testRegistry.cpp (original)
+++ activemq/activemq-cpp/trunk/activemq-cpp/src/test/testRegistry.cpp Wed Sep 30 12:51:02
2009
@@ -240,6 +240,9 @@
 #include <decaf/util/concurrent/atomic/AtomicReferenceTest.h>
 CPPUNIT_TEST_SUITE_REGISTRATION( decaf::util::concurrent::atomic::AtomicReferenceTest );
 
+#include <decaf/util/concurrent/locks/LockSupportTest.h>
+CPPUNIT_TEST_SUITE_REGISTRATION( decaf::util::concurrent::locks::LockSupportTest );
+
 #include <decaf/util/DateTest.h>
 CPPUNIT_TEST_SUITE_REGISTRATION( decaf::util::DateTest );
 #include <decaf/util/UUIDTest.h>



Mime
View raw message