Author: tabish
Date: Mon Sep 14 19:23:32 2009
New Revision: 814791
URL: http://svn.apache.org/viewvc?rev=814791&view=rev
Log:
Implements Threads in Decaf instead of using APR, adds autoconf logic to detect
pthreads functions.
Added:
activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/internal/lang/
activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/internal/lang/ThreadImpl.h
(with props)
activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/internal/lang/unix/
activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/internal/lang/unix/ThreadImpl.cpp
(with props)
activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/internal/lang/windows/
activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/internal/lang/windows/ThreadImpl.cpp
(with props)
Modified:
activemq/activemq-cpp/trunk/activemq-cpp/configure.ac
activemq/activemq-cpp/trunk/activemq-cpp/m4/check_pthreads.m4
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/main/decaf/util/Config.h
activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/util/concurrent/Mutex.h
Modified: activemq/activemq-cpp/trunk/activemq-cpp/configure.ac
URL:
http://svn.apache.org/viewvc/activemq/activemq-cpp/trunk/activemq-cpp/configure.ac?rev=814791&r1=814790&r2=814791&view=diff
==============================================================================
--- activemq/activemq-cpp/trunk/activemq-cpp/configure.ac (original)
+++ activemq/activemq-cpp/trunk/activemq-cpp/configure.ac Mon Sep 14 19:23:32
2009
@@ -101,11 +101,16 @@
AC_CHECK_HEADERS([uuid.h uuid/uuid.h], [AC_DEFINE([HAVE_UUID_T], [1], [Define
if uuid_t exists.])])
AC_CHECK_HEADERS([objbase.h])
AC_CHECK_HEADERS([repcdce.h])
+AC_CHECK_HEADERS([signal.h])
+AC_CHECK_HEADERS([string.h])
+AC_CHECK_HEADERS([sched.h])
AC_CHECK_HEADERS([sys/filio.h])
AC_CHECK_HEADERS([sys/ioctl.h])
AC_CHECK_HEADERS([sys/select.h])
AC_CHECK_HEADERS([sys/time.h])
AC_CHECK_HEADERS([sys/timeb.h])
+AC_CHECK_HEADERS([sys/wait.h])
+AC_CHECK_HEADERS([sys/resource.h])
AC_CHECK_HEADERS([pthread.h])
AC_CHECK_FUNCS([ioctl select gettimeofday time ftime])
Modified: activemq/activemq-cpp/trunk/activemq-cpp/m4/check_pthreads.m4
URL:
http://svn.apache.org/viewvc/activemq/activemq-cpp/trunk/activemq-cpp/m4/check_pthreads.m4?rev=814791&r1=814790&r2=814791&view=diff
==============================================================================
--- activemq/activemq-cpp/trunk/activemq-cpp/m4/check_pthreads.m4 (original)
+++ activemq/activemq-cpp/trunk/activemq-cpp/m4/check_pthreads.m4 Mon Sep 14
19:23:32 2009
@@ -183,6 +183,10 @@
AC_CHECK_HEADERS([sched.h])
AC_CHECK_FUNCS([sched_yield])
fi
+
+ dnl ----------------------------- Check for non-posix pthreads methods
+ AC_CHECK_FUNCS([pthread_tryjoin_np pthread_timedjoin_np])
+
])
dnl
@@ -306,7 +310,4 @@
DECAF_CHECK_PTHREAD_RECURSIVE_MUTEX
DECAF_CHECK_PTHREAD_EXTRAS
- AC_CHECK_FUNCS([pthread_mutex_trylock pthread_tryjoin_np
pthread_timedjoin_np])
-
-
])
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=814791&r1=814790&r2=814791&view=diff
==============================================================================
--- activemq/activemq-cpp/trunk/activemq-cpp/src/main/Makefile.am (original)
+++ activemq/activemq-cpp/trunk/activemq-cpp/src/main/Makefile.am Mon Sep 14
19:23:32 2009
@@ -479,6 +479,7 @@
decaf/internal/io/StandardErrorOutputStream.cpp \
decaf/internal/io/StandardInputStream.cpp \
decaf/internal/io/StandardOutputStream.cpp \
+ decaf/internal/lang/unix/ThreadImpl.cpp \
decaf/internal/net/URIEncoderDecoder.cpp \
decaf/internal/net/URIHelper.cpp \
decaf/internal/nio/BufferFactory.cpp \
@@ -1081,6 +1082,7 @@
decaf/internal/io/StandardErrorOutputStream.h \
decaf/internal/io/StandardInputStream.h \
decaf/internal/io/StandardOutputStream.h \
+ decaf/internal/lang/ThreadImpl.h \
decaf/internal/net/URIEncoderDecoder.h \
decaf/internal/net/URIHelper.h \
decaf/internal/net/URIType.h \
@@ -1143,6 +1145,7 @@
decaf/lang/exceptions/IllegalArgumentException.h \
decaf/lang/exceptions/IllegalMonitorStateException.h \
decaf/lang/exceptions/IllegalStateException.h \
+ decaf/lang/exceptions/IllegalThreadStateException.h \
decaf/lang/exceptions/IndexOutOfBoundsException.h \
decaf/lang/exceptions/InterruptedException.h \
decaf/lang/exceptions/InvalidStateException.h \
Added:
activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/internal/lang/ThreadImpl.h
URL:
http://svn.apache.org/viewvc/activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/internal/lang/ThreadImpl.h?rev=814791&view=auto
==============================================================================
---
activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/internal/lang/ThreadImpl.h
(added)
+++
activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/internal/lang/ThreadImpl.h
Mon Sep 14 19:23:32 2009
@@ -0,0 +1,113 @@
+/*
+ * 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_INTERNAL_LANG_THREADIMPL_H_
+#define _DECAF_INTERNAL_LANG_THREADIMPL_H_
+
+#include <decaf/util/Config.h>
+
+namespace decaf {
+namespace lang{
+ class Thread;
+ class ThreadHandle;
+}
+namespace internal {
+namespace lang {
+
+ class DECAF_API ThreadImpl {
+ private:
+
+ ThreadImpl() {}
+
+ public:
+
+ /**
+ * Create a new OS Thread. When the new thread is created the given
start routine is
+ * called and the supplied argument is passed along with ThreadHandle
associated with
+ * this thread. If successful this method returns the active
ThreadHandle to the caller,
+ * however if the Thread cannot be created then a RuntimeException is
thrown.
+ *
+ * The method must be passed a pointer to the parent Thread instance
that is creating it
+ * so that the underlying OS thread functions can be used to associate
the running Thread.
+ *
+ * @param parent pinter to the Thread object instance that creates
this thread.
+ * @param threadEntry the method to call when the thread starts.
+ * @param userArg the value to pass into the threadEntry method when
the thread starts.
+ *
+ * @return a pointer to the newly created ThreadHandle for the caller
to store and use as
+ * a key to pass to the other thread utility methods.
+ *
+ * @throw NullPointerException if the parent or threadEntry pointers
are null.
+ * @throw RuntimeException if the thread cannot be created for some
reason.
+ */
+ static decaf::lang::ThreadHandle* create(
+ decaf::lang::Thread* parent,
+ void (*threadEntry)( decaf::lang::ThreadHandle* self, void* data ),
+ void* userArg );
+
+ /**
+ * Causes the current thread to sleep for the given time interval.
+ *
+ * @param mills time in milliseconds to sleep
+ * @param nanos additional time in nanoseconds [0-999999] to sleep
+ */
+ static void sleep( long long mills, long long nanos );
+
+ /**
+ * Causes the given thread to block until the specified thread
terminates.
+ *
+ * @param handle the handle to the Thread that should be joined.
+ */
+ static void join( decaf::lang::ThreadHandle* handle );
+
+ /**
+ * Causes the given thread to wait for the given time interval for the
specified thread
+ * to exit. If the thread does not terminate in time this method
returns normally.
+ *
+ * @param handle the handle to the Thread that should be joined.
+ * @param mills time in milliseconds to sleep
+ * @param nanos additional time in nanoseconds [0-999999] to sleep
+ */
+ static void join( decaf::lang::ThreadHandle* handle, long long mills,
long long nanos );
+
+ /**
+ * Sets the Scheduling priority of the specified thread to the new
value.
+ *
+ * @param handle the thread handle whose priority is to be altered
+ * @param priority the new priority value for the thread [0-20]
+ */
+ static void setPriority( decaf::lang::ThreadHandle* handle, unsigned
int priority );
+
+ /**
+ * Causes the current thread to give up its slot in the scheduler to
allow another
+ * thread time to run.
+ */
+ static void yeild();
+
+ /**
+ * Gets and returns the Current Thread Id as an 64bit long, the actual
type is OS
+ * dependent.
+ *
+ * @returns a 64bit long value that represents the OS specific Thread
Id.
+ */
+ static long long getThreadId();
+
+ };
+
+}}}
+
+#endif /* _DECAF_INTERNAL_LANG_THREADIMPL_H_ */
Propchange:
activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/internal/lang/ThreadImpl.h
------------------------------------------------------------------------------
svn:eol-style = native
Added:
activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/internal/lang/unix/ThreadImpl.cpp
URL:
http://svn.apache.org/viewvc/activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/internal/lang/unix/ThreadImpl.cpp?rev=814791&view=auto
==============================================================================
---
activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/internal/lang/unix/ThreadImpl.cpp
(added)
+++
activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/internal/lang/unix/ThreadImpl.cpp
Mon Sep 14 19:23:32 2009
@@ -0,0 +1,198 @@
+/*
+ * 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 <decaf/internal/lang/ThreadImpl.h>
+
+#include <decaf/lang/Math.h>
+#include <decaf/lang/Thread.h>
+#include <decaf/lang/exceptions/NullPointerException.h>
+#include <decaf/lang/exceptions/RuntimeException.h>
+#include <decaf/util/concurrent/TimeUnit.h>
+
+#if HAVE_PTHREAD_H
+#include <pthread.h>
+#endif
+#if HAVE_SIGNAL_H
+#include <signal.h>
+#endif
+#if HAVE_STRING_H
+#include <string.h>
+#endif
+#if HAVE_SCHED_H
+#include <sched.h>
+#endif
+#if HAVE_SYS_TIME_H
+#include <sys/time.h>
+#endif
+#if HAVE_UNISTD_H
+#include <unistd.h>
+#endif
+#if HAVE_TIME_H
+#include <time.h>
+#endif
+
+using namespace decaf;
+using namespace decaf::lang;
+using namespace decaf::lang::exceptions;
+using namespace decaf::internal;
+using namespace decaf::internal::lang;
+using namespace decaf::util::concurrent;
+
+////////////////////////////////////////////////////////////////////////////////
+namespace decaf{
+namespace lang{
+
+ class ThreadHandle {
+ public:
+
+ typedef void (*threadEntry)( decaf::lang::ThreadHandle* self, void*
data );
+
+ ThreadHandle() {
+ pthread_attr_init( &attributes );
+ running = false;
+ returnStatus = false;
+ userArg = NULL;
+ entryFunctionPtr = NULL;
+ }
+
+ ~ThreadHandle() {
+ pthread_attr_destroy( &attributes );
+ }
+
+ pthread_t thread;
+ pthread_attr_t attributes;
+ bool returnStatus;
+ threadEntry entryFunctionPtr;
+ void* userArg;
+ bool running;
+
+ };
+
+}}
+
+////////////////////////////////////////////////////////////////////////////////
+namespace{
+
+ void* threadWorker( void* arg ) {
+ ThreadHandle* handle = (ThreadHandle*)arg;
+ handle->running = true;
+ handle->entryFunctionPtr( handle, handle->userArg );
+ handle->running = false;
+ pthread_exit(0);
+ return NULL;
+ }
+}
+
+////////////////////////////////////////////////////////////////////////////////
+ThreadHandle* ThreadImpl::create( decaf::lang::Thread* parent,
+ void (*threadEntry)(
decaf::lang::ThreadHandle* self, void* data ),
+ void* userArg ) {
+
+ if( parent == NULL ) {
+ throw NullPointerException(
+ __FILE__, __LINE__, "Pointer to parent Thread object is null." );
+ }
+
+ if( threadEntry == NULL ) {
+ throw NullPointerException(
+ __FILE__, __LINE__, "Pointer to thread entry function is null." );
+ }
+
+ std::auto_ptr<ThreadHandle> handle( new ThreadHandle );
+ handle->entryFunctionPtr = threadEntry;
+ handle->userArg = userArg;
+
+ int result = pthread_create( &( handle->thread ), &( handle->attributes ),
threadWorker, handle.get() );
+
+ // Only try and set this if its not the default value.
+ if( parent->getPriority() != Thread::NORM_PRIORITY ) {
+ setPriority( handle.get(), parent->getPriority() );
+ }
+
+ if( result != 0 ) {
+ throw RuntimeException(
+ __FILE__, __LINE__, "Failed to create new Thread." );
+ }
+
+ return handle.release();
+}
+
+////////////////////////////////////////////////////////////////////////////////
+void ThreadImpl::yeild() {
+
+ #ifdef HAVE_PTHREAD_YIELD
+ pthread_yield();
+ #else
+ #ifdef HAVE_SCHED_YIELD
+ sched_yield();
+ #endif
+ #endif
+}
+
+////////////////////////////////////////////////////////////////////////////////
+void ThreadImpl::sleep( long long mills, long long nanos ) {
+
+ long long usecs = TimeUnit::MILLISECONDS.toMicros( mills ) +
+ TimeUnit::NANOSECONDS.toMicros( nanos );
+
+ struct timeval tv;
+ tv.tv_usec = usecs % 1000000;
+ tv.tv_sec = usecs / 1000000;
+ select( 0, NULL, NULL, NULL, &tv );
+}
+
+////////////////////////////////////////////////////////////////////////////////
+void ThreadImpl::join( decaf::lang::ThreadHandle* handle ) {
+
+ void* theReturn = 0;
+ pthread_join( handle->thread, &theReturn );
+}
+
+////////////////////////////////////////////////////////////////////////////////
+void ThreadImpl::join( decaf::lang::ThreadHandle* handle, long long mills,
long long nanos ) {
+
+ void* theReturn = NULL;
+
+#if HAVE_PTHREAD_TIMEDJOIN_NP
+
+ long long totalTime = TimeUnit::MILLISECONDS.toNanos( mills ) + nanos;
+
+ timespec time;
+ time.tv_nsec = totalTime % 1000000000;
+ time.tv_sec = totalTime / 1000000000;
+
+ pthread_timedjoin_np( handle->thread, &theReturn, &time );
+
+#endif
+
+ // TODO - Figure out something for platforms without the non-posix
functions.
+}
+
+////////////////////////////////////////////////////////////////////////////////
+void ThreadImpl::setPriority( decaf::lang::ThreadHandle* handle, unsigned int
priority ) {
+
+ // TODO
+ // int MAX_PRIORITY = sched_get_priority_max( SCHED_RR );
+ // int MIN_PRIORITY = sched_get_priority_min( SCHED_RR );
+ // int MID_PRIORITY = ( MAX_PRIORITY + MIN_PRIORITY ) / 2;
+
+}
+
+////////////////////////////////////////////////////////////////////////////////
+long long ThreadImpl::getThreadId() {
+ return (long long)pthread_self();
+}
Propchange:
activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/internal/lang/unix/ThreadImpl.cpp
------------------------------------------------------------------------------
svn:eol-style = native
Added:
activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/internal/lang/windows/ThreadImpl.cpp
URL:
http://svn.apache.org/viewvc/activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/internal/lang/windows/ThreadImpl.cpp?rev=814791&view=auto
==============================================================================
---
activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/internal/lang/windows/ThreadImpl.cpp
(added)
+++
activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/internal/lang/windows/ThreadImpl.cpp
Mon Sep 14 19:23:32 2009
@@ -0,0 +1,170 @@
+/*
+ * 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 <decaf/internal/lang/ThreadImpl.h>
+
+#include <decaf/lang/Math.h>
+#include <decaf/lang/Thread.h>
+#include <decaf/lang/exceptions/NullPointerException.h>
+#include <decaf/lang/exceptions/RuntimeException.h>
+#include <decaf/util/concurrent/TimeUnit.h>
+
+#if HAVE_PROCESS_H
+#include <process.h>
+#endif
+
+using namespace decaf;
+using namespace decaf::lang;
+using namespace decaf::lang::exceptions;
+using namespace decaf::internal;
+using namespace decaf::internal::lang;
+using namespace decaf::util::concurrent;
+
+////////////////////////////////////////////////////////////////////////////////
+namespace decaf{
+namespace lang{
+
+ class ThreadHandle {
+ public:
+
+ typedef void (*threadEntry)( decaf::lang::ThreadHandle* self, void*
data );
+
+ ThreadHandle() {
+ running = false;
+ returnStatus = false;
+ userArg = NULL;
+ entryFunctionPtr = NULL;
+ handle = NULL;
+ }
+
+ ~ThreadHandle() {
+ }
+
+ HANDLE handle;
+ bool returnStatus;
+ threadEntry entryFunctionPtr;
+ void* userArg;
+ bool running;
+
+ };
+
+}}
+
+////////////////////////////////////////////////////////////////////////////////
+namespace{
+
+ unsigned int __stdcall threadWorker( void* arg ) {
+ ThreadHandle* handle = (ThreadHandle*)arg;
+ handle->running = true;
+ handle->entryFunctionPtr( handle, handle->userArg );
+ handle->running = false;
+#ifndef _WIN32_WCE
+ _ endthreadex( 0 );
+#else
+ ExitThread( 0 );
+#endif
+ ::CloseHandle( handle->handle );
+
+ return NULL;
+ }
+}
+
+////////////////////////////////////////////////////////////////////////////////
+ThreadHandle* ThreadImpl::create( decaf::lang::Thread* parent,
+ void (*threadEntry)(
decaf::lang::ThreadHandle* self, void* data ),
+ void* userArg ) {
+
+ if( parent == NULL ) {
+ throw NullPointerException(
+ __FILE__, __LINE__, "Pointer to parent Thread object is null." );
+ }
+
+ if( threadEntry == NULL ) {
+ throw NullPointerException(
+ __FILE__, __LINE__, "Pointer to thread entry function is null." );
+ }
+
+ unsigned int threadId = 0;
+
+ std::auto_ptr<ThreadHandle> handle( new ThreadHandle );
+ handle->entryFunctionPtr = threadEntry;
+ handle->userArg = userArg;
+
+#ifndef _WIN32_WCE
+
+ handle->handle = (HANDLE)_beginthreadex( NULL, (DWORD)0, threadWorker,
handle.get(), 0, &threadId );
+
+#else
+
+ handle->hanlde = CreateThread( NULL, 0, threadWorker, handle.get(), 0,
&threadId ) );
+
+#endif
+
+ if( result != 0 ) {
+ throw RuntimeException(
+ __FILE__, __LINE__, "Failed to create new Thread." );
+ }
+
+ // Only try and set this if its not the default value.
+ if( parent->getPriority() != Thread::NORM_PRIORITY ) {
+ setPriority( handle.get(), parent->getPriority() );
+ }
+
+ return handle.release();
+}
+
+////////////////////////////////////////////////////////////////////////////////
+void ThreadImpl::yeild() {
+
+#ifndef _WIN32_WCE
+ SwitchToThread();
+#endif
+}
+
+////////////////////////////////////////////////////////////////////////////////
+void ThreadImpl::sleep( long long mills, long long nanos ) {
+
+ ::Sleep( mills );
+}
+
+////////////////////////////////////////////////////////////////////////////////
+void ThreadImpl::join( decaf::lang::ThreadHandle* handle ) {
+
+ ThreadImpl::join( handle, INFINITE, 0 );
+}
+
+////////////////////////////////////////////////////////////////////////////////
+void ThreadImpl::join( decaf::lang::ThreadHandle* handle, long long mills,
long long nanos ) {
+
+ unsigned int rv = WaitForSingleObject( handle->handle, mills );
+ ::CloseHandle( handle->handle );
+}
+
+////////////////////////////////////////////////////////////////////////////////
+void ThreadImpl::setPriority( decaf::lang::ThreadHandle* handle, unsigned int
priority ) {
+
+ // TODO
+ // int MAX_PRIORITY = sched_get_priority_max( SCHED_RR );
+ // int MIN_PRIORITY = sched_get_priority_min( SCHED_RR );
+ // int MID_PRIORITY = ( MAX_PRIORITY + MIN_PRIORITY ) / 2;
+
+}
+
+////////////////////////////////////////////////////////////////////////////////
+long long ThreadImpl::getThreadId() {
+ return (long long)::GetCurrentThreadId();
+}
Propchange:
activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/internal/lang/windows/ThreadImpl.cpp
------------------------------------------------------------------------------
svn:eol-style = native
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=814791&r1=814790&r2=814791&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 Mon
Sep 14 19:23:32 2009
@@ -21,11 +21,6 @@
#pragma warning( disable: 4311 )
#endif
-#include <apr.h>
-#include <apr_time.h>
-#include <apr_portable.h>
-#include <apr_thread_proc.h>
-
#include <decaf/internal/DecafRuntime.h>
#include <decaf/lang/Integer.h>
#include <decaf/lang/Long.h>
@@ -33,8 +28,11 @@
#include <decaf/lang/exceptions/RuntimeException.h>
#include <decaf/lang/exceptions/NullPointerException.h>
+#include <decaf/internal/lang/ThreadImpl.h>
+
using namespace decaf;
using namespace decaf::internal;
+using namespace decaf::internal::lang;
using namespace decaf::lang;
using namespace decaf::lang::exceptions;
@@ -54,7 +52,8 @@
/**
* APR Thread Handle
*/
- apr_thread_t* threadHandle;
+ //apr_thread_t* threadHandle;
+ std::auto_ptr<ThreadHandle> threadHandle;
/**
* Current state of this thread.
@@ -89,7 +88,8 @@
public:
- static void* APR_THREAD_FUNC runCallback( apr_thread_t* self, void*
param ) {
+ //static void* APR_THREAD_FUNC runCallback( apr_thread_t* self, void*
param ) {
+ static void runCallback( ThreadHandle* thread DECAF_UNUSED, void*
param ) {
// Get the instance.
ThreadProperties* properties = (ThreadProperties*)param;
@@ -122,8 +122,8 @@
// Indicate we are done.
properties->state = Thread::TERMINATED;
- apr_thread_exit( self, APR_SUCCESS );
- return NULL;
+ // apr_thread_exit( self, APR_SUCCESS );
+ // return NULL;
}
};
@@ -167,7 +167,6 @@
this->properties->state = Thread::NEW;
this->properties->priority = Thread::NORM_PRIORITY;
this->properties->task = task;
- this->properties->threadHandle = NULL;
this->properties->exHandler = NULL;
this->properties->parent = this;
}
@@ -182,30 +181,41 @@
}
////////////////////////////////////////////////////////////////////////////////
-void Thread::start() throw ( Exception )
-{
- if( this->properties->state > Thread::NEW ) {
- throw Exception(
- __FILE__, __LINE__,
- "Thread::start - Thread already started");
- }
+void Thread::start() throw (
decaf::lang::exceptions::IllegalThreadStateException,
+ decaf::lang::exceptions::RuntimeException ) {
- DecafRuntime* runtime = dynamic_cast<DecafRuntime*>( Runtime::getRuntime()
);
+ try {
- apr_status_t err = apr_thread_create(
- &this->properties->threadHandle,
- NULL,
- this->properties->runCallback,
- this->properties.get(),
- runtime->getGlobalPool() );
-
- if( err != APR_SUCCESS ) {
- throw Exception(
- __FILE__, __LINE__,
- "Thread::start - Could not start thread");
- }
+ if( this->properties->state > Thread::NEW ) {
+ throw RuntimeException(
+ __FILE__, __LINE__,
+ "Thread::start - Thread already started");
+ }
- this->properties->state = Thread::RUNNABLE;
+// DecafRuntime* runtime = dynamic_cast<DecafRuntime*>(
Runtime::getRuntime() );
+//
+// apr_status_t err = apr_thread_create(
+// &this->properties->threadHandle,
+// NULL,
+// this->properties->runCallback,
+// this->properties.get(),
+// runtime->getGlobalPool() );
+//
+// if( err != APR_SUCCESS ) {
+// throw Exception(
+// __FILE__, __LINE__,
+// "Thread::start - Could not start thread");
+// }
+
+ this->properties->threadHandle.reset( ThreadImpl::create(
+ this, this->properties->runCallback, this->properties.get() ) );
+
+ this->properties->state = Thread::RUNNABLE;
+ }
+ DECAF_CATCH_RETHROW( IllegalThreadStateException )
+ DECAF_CATCH_RETHROW( RuntimeException )
+ DECAF_CATCH_EXCEPTION_CONVERT( NullPointerException, RuntimeException )
+ DECAF_CATCHALL_THROW( RuntimeException )
}
////////////////////////////////////////////////////////////////////////////////
@@ -217,8 +227,9 @@
}
if( this->properties->state != Thread::TERMINATED ) {
- apr_status_t threadReturn;
- apr_thread_join( &threadReturn, this->properties->threadHandle );
+// apr_status_t threadReturn;
+// apr_thread_join( &threadReturn, this->properties->threadHandle );
+ ThreadImpl::join( this->properties->threadHandle.get() );
}
}
@@ -233,11 +244,11 @@
"Thread::join( millisecs ) - Value given {%d} is less than 0",
millisecs );
}
- this->join();
+ this->join( millisecs );
}
////////////////////////////////////////////////////////////////////////////////
-void Thread::join( long long millisecs DECAF_UNUSED, unsigned int nanos
DECAF_UNUSED )
+void Thread::join( long long millisecs, unsigned int nanos )
throw ( decaf::lang::exceptions::IllegalArgumentException,
decaf::lang::exceptions::InterruptedException ) {
@@ -253,7 +264,7 @@
"Thread::join( millisecs, nanos ) - Nanoseconds must be in range
[0...999999]" );
}
- this->join();
+ ThreadImpl::join( this->properties->threadHandle.get(), millisecs, nanos );
}
////////////////////////////////////////////////////////////////////////////////
@@ -289,17 +300,20 @@
// TODO -- Add in nanos
- apr_sleep( (apr_interval_time_t)(millisecs * 1000) );
+// apr_sleep( (apr_interval_time_t)(millisecs * 1000) );
+ ThreadImpl::sleep( millisecs, nanos );
}
////////////////////////////////////////////////////////////////////////////////
void Thread::yield() {
- apr_thread_yield();
+ //apr_thread_yield();
+ ThreadImpl::yeild();
}
////////////////////////////////////////////////////////////////////////////////
-unsigned long Thread::getId() {
- return (unsigned long)( apr_os_thread_current() );
+long long Thread::getId() {
+ //return (unsigned long)( apr_os_thread_current() );
+ return ThreadImpl::getThreadId();
}
////////////////////////////////////////////////////////////////////////////////
@@ -323,7 +337,7 @@
this->properties->priority = value;
- // TODO - Alter Threads actual priority.
+ ThreadImpl::setPriority( this->properties->threadHandle.get(), value );
}
////////////////////////////////////////////////////////////////////////////////
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=814791&r1=814790&r2=814791&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 Mon
Sep 14 19:23:32 2009
@@ -17,8 +17,10 @@
#ifndef _DECAF_LANG_THREAD_H_
#define _DECAF_LANG_THREAD_H_
+#include <decaf/lang/exceptions/IllegalThreadStateException.h>
#include <decaf/lang/exceptions/IllegalArgumentException.h>
#include <decaf/lang/exceptions/InterruptedException.h>
+#include <decaf/lang/exceptions/RuntimeException.h>
#include <decaf/lang/Exception.h>
#include <decaf/lang/Runnable.h>
#include <decaf/util/Config.h>
@@ -169,14 +171,15 @@
virtual ~Thread();
/**
- * Creates a system thread and starts it in a joinable mode.
- * Upon creation, the
- * run() method of either this object or the provided Runnable
- * object will be invoked in the context of this thread.
- * @exception runtime_error is thrown if the system could
- * not start the thread.
+ * Creates a system thread and starts it in a joinable mode. Upon
creation, the
+ * run() method of either this object or the provided Runnable object
will be
+ * invoked in the context of this thread.
+ *
+ * @throws IllegalThreadStateException if the thread has already been
started.
+ * @throws RuntimeException if the Thread cannot be created for some
reason.
*/
- virtual void start() throw ( Exception );
+ virtual void start() throw (
decaf::lang::exceptions::IllegalThreadStateException,
+ decaf::lang::exceptions::RuntimeException
);
/**
* Forces the Current Thread to wait until the thread exits.
@@ -336,7 +339,7 @@
* Obtains the Thread Id of the current thread
* @return Thread Id
*/
- static unsigned long getId();
+ static long long getId();
private:
Modified: activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/util/Config.h
URL:
http://svn.apache.org/viewvc/activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/util/Config.h?rev=814791&r1=814790&r2=814791&view=diff
==============================================================================
--- activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/util/Config.h
(original)
+++ activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/util/Config.h Mon
Sep 14 19:23:32 2009
@@ -65,6 +65,58 @@
#ifndef HAVE_WINDOWS_H
#define HAVE_WINDOWS_H
#endif
+ #ifndef HAVE_PROCESS_H
+ #define HAVE_PROCESS_H
+ #endif
+
+ #if defined(_MSC_VER) && _MSC_VER >= 1400
+ #ifndef _CRT_SECURE_NO_DEPRECATE
+ #define _CRT_SECURE_NO_DEPRECATE
+ #endif
+ #pragma warning(disable: 4996)
+ #endif
+
+ /* Has windows.h already been included? If so, our preferences don't
matter,
+ * but we will still need the winsock things no matter what was
included.
+ * If not, include a restricted set of windows headers to our tastes.
+ */
+ #ifndef _WINDOWS_
+ #ifndef WIN32_LEAN_AND_MEAN
+ #define WIN32_LEAN_AND_MEAN
+ #endif
+ #ifndef _WIN32_WINNT
+
+ /*
+ * Restrict the server to a subset of Windows XP header files by
default
+ */
+ #define _WIN32_WINNT 0x0501
+ #endif
+ #ifndef NOUSER
+ #define NOUSER
+ #endif
+ #ifndef NOMCX
+ #define NOMCX
+ #endif
+ #ifndef NOIME
+ #define NOIME
+ #endif
+ #include <windows.h>
+
+ /*
+ * Add a _very_few_ declarations missing from the restricted set
of headers
+ * (If this list becomes extensive, re-enable the required headers
above!)
+ * winsock headers were excluded by WIN32_LEAN_AND_MEAN, so
include them now
+ */
+ #define SW_HIDE 0
+ #ifndef _WIN32_WCE
+ #include <winsock2.h>
+ #include <ws2tcpip.h>
+ #include <mswsock.h>
+ #else
+ #include <winsock.h>
+ #endif
+ #endif /* !_WINDOWS_ */
+
#else
#ifndef HAVE_UUID_UUID_H
#define HAVE_UUID_UUID_H
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=814791&r1=814790&r2=814791&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
Mon Sep 14 19:23:32 2009
@@ -53,7 +53,7 @@
std::list<apr_thread_cond_t*> eventQ;
// Lock Status Members
- volatile unsigned long lock_owner;
+ volatile long long lock_owner;
volatile unsigned long lock_count;
private: