You are viewing a plain text version of this content. The canonical link for it is here.
Posted to log4cxx-dev@logging.apache.org by ca...@apache.org on 2008/05/06 22:44:28 UTC
svn commit: r653917 - in /logging/log4cxx/trunk/src/main:
cpp/aprinitializer.cpp cpp/threadcxx.cpp include/log4cxx/helpers/thread.h
Author: carnold
Date: Tue May 6 13:44:28 2008
New Revision: 653917
URL: http://svn.apache.org/viewvc?rev=653917&view=rev
Log:
LOGCXX-265: Anachronism warnings
Modified:
logging/log4cxx/trunk/src/main/cpp/aprinitializer.cpp
logging/log4cxx/trunk/src/main/cpp/threadcxx.cpp
logging/log4cxx/trunk/src/main/include/log4cxx/helpers/thread.h
Modified: logging/log4cxx/trunk/src/main/cpp/aprinitializer.cpp
URL: http://svn.apache.org/viewvc/logging/log4cxx/trunk/src/main/cpp/aprinitializer.cpp?rev=653917&r1=653916&r2=653917&view=diff
==============================================================================
--- logging/log4cxx/trunk/src/main/cpp/aprinitializer.cpp (original)
+++ logging/log4cxx/trunk/src/main/cpp/aprinitializer.cpp Tue May 6 13:44:28 2008
@@ -31,8 +31,10 @@
bool APRInitializer::isDestructed = false;
-static void tlsDestruct(void* ptr) {
- delete ((ThreadSpecificData*) ptr);
+namespace {
+ void tlsDestruct(void* ptr) {
+ delete ((ThreadSpecificData*) ptr);
+ }
}
APRInitializer::APRInitializer() {
Modified: logging/log4cxx/trunk/src/main/cpp/threadcxx.cpp
URL: http://svn.apache.org/viewvc/logging/log4cxx/trunk/src/main/cpp/threadcxx.cpp?rev=653917&r1=653916&r2=653917&view=diff
==============================================================================
--- logging/log4cxx/trunk/src/main/cpp/threadcxx.cpp (original)
+++ logging/log4cxx/trunk/src/main/cpp/threadcxx.cpp Tue May 6 13:44:28 2008
@@ -26,34 +26,123 @@
using namespace log4cxx::helpers;
using namespace log4cxx;
-Thread::Thread() : thread(NULL), alive(0), interruptedStatus(0) {
-}
-
-Thread::~Thread() {
- join();
-}
+#if APR_HAS_THREADS
+namespace {
+ /**
+ * This class is used to encapsulate the parameters to
+ * Thread::run when they are passed to Thread::launcher.
+ *
+ */
+ class LaunchPackage {
+ public:
+ /**
+ * Placement new to create LaunchPackage in specified pool.
+ * LaunchPackage needs to be dynamically allocated since
+ * since a stack allocated instance may go out of scope
+ * before thread is launched.
+ */
+ static void* operator new(size_t sz, Pool& p) {
+ return p.palloc(sz);
+ }
+ /**
+ * operator delete would be called if exception during construction.
+ */
+ static void operator delete(void*, Pool& p) {
+ }
+ /**
+ * Create new instance.
+ */
+ LaunchPackage(Thread* t, Runnable r, void* d) : thread(t), runnable(r), data(d) {
+ }
+ /**
+ * Gets thread parameter.
+ * @return thread.
+ */
+ Thread* getThread() const {
+ return thread;
+ }
+
+ /**
+ * Gets runnable parameter.
+ * @return runnable.
+ */
+ Runnable getRunnable() const {
+ return runnable;
+ }
+ /**
+ * gets data parameter.
+ * @return thread.
+ */
+ void* getData() const {
+ return data;
+ }
+ private:
+ LaunchPackage(const LaunchPackage&);
+ LaunchPackage& operator=(const LaunchPackage&);
+ Thread* thread;
+ Runnable runnable;
+ void* data;
+ };
+
+ /**
+ * This object atomically sets the specified memory location
+ * to non-zero on construction and to zero on destruction.
+ * Used to maintain Thread.alive.
+ */
+ class LaunchStatus {
+ public:
+ /*
+ * Construct new instance.
+ * @param p address of memory to set to non-zero on construction, zero on destruction.
+ */
+ LaunchStatus(volatile unsigned int* p) : alive(p) {
+ apr_atomic_set32(alive, 0xFFFFFFFF);
+ }
+ /**
+ * Destructor.
+ */
+ ~LaunchStatus() {
+ apr_atomic_set32(alive, 0);
+ }
+
+ private:
+ LaunchStatus(const LaunchStatus&);
+ LaunchStatus& operator=(const LaunchStatus&);
+ volatile unsigned int* alive;
+ };
+
+ /**
+ * Get a key to the thread local storage used to hold the reference to
+ * the corresponding Thread object.
+ */
+ ThreadLocal& getThreadLocal() {
+ static ThreadLocal tls;
+ return tls;
+ }
+
+}
+
+void* LOG4CXX_THREAD_FUNC ThreadLaunch::launcher(apr_thread_t* thread, void* data) {
+ LaunchPackage* package = (LaunchPackage*) data;
+ ThreadLocal& tls = getThreadLocal();
+ tls.set(package->getThread());
+ LaunchStatus alive(&package->getThread()->alive);
+ void* retval = (package->getRunnable())(thread, package->getData());
+ apr_thread_exit(thread, 0);
+ return retval;
+}
+#endif
-Thread::LaunchPackage::LaunchPackage(Thread* t, Runnable r, void* d) : thread(t), runnable(r), data(d) {
-}
-Thread* Thread::LaunchPackage::getThread() const {
- return thread;
-}
-Runnable Thread::LaunchPackage::getRunnable() const {
- return runnable;
+Thread::Thread() : thread(NULL), alive(0), interruptedStatus(0) {
}
-void* Thread::LaunchPackage::getData() const {
- return data;
+Thread::~Thread() {
+ join();
}
-void* Thread::LaunchPackage::operator new(size_t sz, Pool& p) {
- return p.palloc(sz);
-}
-void Thread::LaunchPackage::operator delete(void* mem, Pool& p) {
-}
void Thread::run(Runnable start, void* data) {
#if APR_HAS_THREADS
@@ -73,7 +162,7 @@
// create LaunchPackage on the thread's memory pool
LaunchPackage* package = new(p) LaunchPackage(this, start, data);
stat = apr_thread_create(&thread, attrs,
- launcher, package, p.getAPRPool());
+ ThreadLaunch::launcher, package, p.getAPRPool());
if (stat != APR_SUCCESS) {
throw ThreadException(stat);
}
@@ -82,26 +171,7 @@
#endif
}
-
-Thread::LaunchStatus::LaunchStatus(volatile unsigned int* p) : alive(p) {
- apr_atomic_set32(alive, 0xFFFFFFFF);
-}
-
-Thread::LaunchStatus::~LaunchStatus() {
- apr_atomic_set32(alive, 0);
-}
-
-#if APR_HAS_THREADS
-void* LOG4CXX_THREAD_FUNC Thread::launcher(apr_thread_t* thread, void* data) {
- LaunchPackage* package = (LaunchPackage*) data;
- ThreadLocal& tls = getThreadLocal();
- tls.set(package->getThread());
- LaunchStatus alive(&package->getThread()->alive);
- void* retval = (package->getRunnable())(thread, package->getData());
- apr_thread_exit(thread, 0);
- return retval;
-}
-#endif
+
void Thread::join() {
@@ -117,10 +187,6 @@
#endif
}
-ThreadLocal& Thread::getThreadLocal() {
- static ThreadLocal tls;
- return tls;
-}
void Thread::currentThreadInterrupt() {
#if APR_HAS_THREADS
Modified: logging/log4cxx/trunk/src/main/include/log4cxx/helpers/thread.h
URL: http://svn.apache.org/viewvc/logging/log4cxx/trunk/src/main/include/log4cxx/helpers/thread.h?rev=653917&r1=653916&r2=653917&view=diff
==============================================================================
--- logging/log4cxx/trunk/src/main/include/log4cxx/helpers/thread.h (original)
+++ logging/log4cxx/trunk/src/main/include/log4cxx/helpers/thread.h Tue May 6 13:44:28 2008
@@ -41,7 +41,11 @@
class Pool;
class ThreadLocal;
- typedef void* (LOG4CXX_THREAD_FUNC *Runnable)(apr_thread_t* thread, void* data);
+ typedef void* (LOG4CXX_THREAD_FUNC *Runnable)(apr_thread_t* thread, void* data);
+ namespace ThreadLaunch {
+ extern "C" void* LOG4CXX_THREAD_FUNC launcher(apr_thread_t* thread, void* data);
+ }
+
/**
* This class implements an approximation of java.util.Thread.
*/
@@ -98,85 +102,7 @@
volatile unsigned int interruptedStatus;
Thread(const Thread&);
Thread& operator=(const Thread&);
-
- /**
- * This class is used to encapsulate the parameters to
- * Thread::run when they are passed to Thread::launcher.
- *
- */
- class LaunchPackage {
- public:
- /**
- * Placement new to create LaunchPackage in specified pool.
- * LaunchPackage needs to be dynamically allocated since
- * since a stack allocated instance may go out of scope
- * before thread is launched.
- */
- static void* operator new(size_t, Pool& p);
- /**
- * operator delete would be called if exception during construction.
- */
- static void operator delete(void*, Pool& p);
- /**
- * Create new instance.
- */
- LaunchPackage(Thread* thread, Runnable runnable, void* data);
- /**
- * Gets thread parameter.
- * @return thread.
- */
- Thread* getThread() const;
- /**
- * Gets runnable parameter.
- * @return runnable.
- */
- Runnable getRunnable() const;
- /**
- * gets data parameter.
- * @return thread.
- */
- void* getData() const;
- private:
- LaunchPackage(const LaunchPackage&);
- LaunchPackage& operator=(const LaunchPackage&);
- Thread* thread;
- Runnable runnable;
- void* data;
- };
-
- /**
- * This object atomically sets the specified memory location
- * to non-zero on construction and to zero on destruction.
- * Used to maintain Thread.alive.
- */
- class LaunchStatus {
- public:
- /*
- * Construct new instance.
- * @param p address of memory to set to non-zero on construction, zero on destruction.
- */
- LaunchStatus(volatile unsigned int* p);
- /**
- * Destructor.
- */
- ~LaunchStatus();
- private:
- LaunchStatus(const LaunchStatus&);
- LaunchStatus& operator=(const LaunchStatus&);
- volatile unsigned int* alive;
- };
-
- /**
- * This method runs on the created thread and sets up thread-local storage
- * used to keep the reference to the corresponding Thread object and
- * is responsible for maintaining Thread.alive.
- */
- static void* LOG4CXX_THREAD_FUNC launcher(apr_thread_t* thread, void* data);
- /**
- * Get a key to the thread local storage used to hold the reference to
- * the corresponding Thread object.
- */
- static ThreadLocal& getThreadLocal();
+ friend void* LOG4CXX_THREAD_FUNC ThreadLaunch::launcher(apr_thread_t* thread, void* data);
};
} // namespace helpers
} // namespace log4cxx