You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@qpid.apache.org by as...@apache.org on 2007/05/22 17:18:16 UTC

svn commit: r540608 - in /incubator/qpid/trunk/qpid/cpp: ./ src/ src/qpid/ src/qpid/broker/ src/qpid/client/ src/qpid/framing/ src/qpid/sys/ src/qpid/sys/apr/ src/qpid/sys/posix/ src/tests/

Author: astitcher
Date: Tue May 22 08:18:08 2007
New Revision: 540608

URL: http://svn.apache.org/viewvc?view=rev&rev=540608
Log:
* Split apart platform (threading etc.) from network io
  you can now use a posix platform implementation by configuring
  --disable-apr-platform
* Changed Time classes to distinguish between absolute times (AbsTime)
  and durations (Duration). This should avoid bugs caused by confusing
  the two types of time.

Added:
    incubator/qpid/trunk/qpid/cpp/src/qpid/sys/apr/Condition.h
      - copied, changed from r537157, incubator/qpid/trunk/qpid/cpp/src/qpid/sys/Condition.h
    incubator/qpid/trunk/qpid/cpp/src/qpid/sys/apr/Module.h
      - copied, changed from r537157, incubator/qpid/trunk/qpid/cpp/src/qpid/sys/Module.h
    incubator/qpid/trunk/qpid/cpp/src/qpid/sys/apr/Mutex.h
      - copied, changed from r537157, incubator/qpid/trunk/qpid/cpp/src/qpid/sys/Mutex.h
    incubator/qpid/trunk/qpid/cpp/src/qpid/sys/apr/Socket.h
      - copied, changed from r537157, incubator/qpid/trunk/qpid/cpp/src/qpid/sys/Socket.h
    incubator/qpid/trunk/qpid/cpp/src/qpid/sys/apr/Thread.h
      - copied, changed from r537157, incubator/qpid/trunk/qpid/cpp/src/qpid/sys/Thread.h
    incubator/qpid/trunk/qpid/cpp/src/qpid/sys/apr/Time.cpp
      - copied, changed from r537157, incubator/qpid/trunk/qpid/cpp/src/qpid/sys/Time.cpp
    incubator/qpid/trunk/qpid/cpp/src/qpid/sys/posix/Condition.h
      - copied, changed from r537157, incubator/qpid/trunk/qpid/cpp/src/qpid/sys/Condition.h
    incubator/qpid/trunk/qpid/cpp/src/qpid/sys/posix/Module.h
      - copied, changed from r537157, incubator/qpid/trunk/qpid/cpp/src/qpid/sys/Module.h
    incubator/qpid/trunk/qpid/cpp/src/qpid/sys/posix/Mutex.h
      - copied, changed from r537157, incubator/qpid/trunk/qpid/cpp/src/qpid/sys/Mutex.h
    incubator/qpid/trunk/qpid/cpp/src/qpid/sys/posix/PrivatePosix.h
    incubator/qpid/trunk/qpid/cpp/src/qpid/sys/posix/Socket.h
      - copied, changed from r537157, incubator/qpid/trunk/qpid/cpp/src/qpid/sys/Socket.h
    incubator/qpid/trunk/qpid/cpp/src/qpid/sys/posix/Thread.h
      - copied, changed from r537157, incubator/qpid/trunk/qpid/cpp/src/qpid/sys/Thread.h
    incubator/qpid/trunk/qpid/cpp/src/qpid/sys/posix/Time.cpp
      - copied, changed from r537157, incubator/qpid/trunk/qpid/cpp/src/qpid/sys/Time.cpp
Removed:
    incubator/qpid/trunk/qpid/cpp/src/qpid/sys/Time.cpp
Modified:
    incubator/qpid/trunk/qpid/cpp/   (props changed)
    incubator/qpid/trunk/qpid/cpp/configure.ac
    incubator/qpid/trunk/qpid/cpp/src/Makefile.am
    incubator/qpid/trunk/qpid/cpp/src/qpid/   (props changed)
    incubator/qpid/trunk/qpid/cpp/src/qpid/broker/   (props changed)
    incubator/qpid/trunk/qpid/cpp/src/qpid/broker/AutoDelete.cpp
    incubator/qpid/trunk/qpid/cpp/src/qpid/broker/AutoDelete.h
    incubator/qpid/trunk/qpid/cpp/src/qpid/broker/Broker.cpp
    incubator/qpid/trunk/qpid/cpp/src/qpid/broker/BrokerQueue.cpp
    incubator/qpid/trunk/qpid/cpp/src/qpid/broker/BrokerQueue.h
    incubator/qpid/trunk/qpid/cpp/src/qpid/client/   (props changed)
    incubator/qpid/trunk/qpid/cpp/src/qpid/client/Connector.cpp
    incubator/qpid/trunk/qpid/cpp/src/qpid/client/Connector.h
    incubator/qpid/trunk/qpid/cpp/src/qpid/framing/   (props changed)
    incubator/qpid/trunk/qpid/cpp/src/qpid/sys/   (props changed)
    incubator/qpid/trunk/qpid/cpp/src/qpid/sys/Condition.h
    incubator/qpid/trunk/qpid/cpp/src/qpid/sys/Module.h
    incubator/qpid/trunk/qpid/cpp/src/qpid/sys/Monitor.h
    incubator/qpid/trunk/qpid/cpp/src/qpid/sys/Mutex.h
    incubator/qpid/trunk/qpid/cpp/src/qpid/sys/ProducerConsumer.cpp
    incubator/qpid/trunk/qpid/cpp/src/qpid/sys/ProducerConsumer.h
    incubator/qpid/trunk/qpid/cpp/src/qpid/sys/Socket.h
    incubator/qpid/trunk/qpid/cpp/src/qpid/sys/Thread.h
    incubator/qpid/trunk/qpid/cpp/src/qpid/sys/Time.h
    incubator/qpid/trunk/qpid/cpp/src/qpid/sys/apr/   (props changed)
    incubator/qpid/trunk/qpid/cpp/src/qpid/sys/apr/APRAcceptor.cpp
    incubator/qpid/trunk/qpid/cpp/src/qpid/sys/apr/LFProcessor.cpp
    incubator/qpid/trunk/qpid/cpp/src/qpid/sys/apr/LFSessionContext.h
    incubator/qpid/trunk/qpid/cpp/src/qpid/sys/apr/Socket.cpp
    incubator/qpid/trunk/qpid/cpp/src/qpid/sys/apr/Thread.cpp
    incubator/qpid/trunk/qpid/cpp/src/qpid/sys/posix/   (props changed)
    incubator/qpid/trunk/qpid/cpp/src/qpid/sys/posix/EventChannelAcceptor.cpp
    incubator/qpid/trunk/qpid/cpp/src/qpid/sys/posix/EventChannelConnection.cpp
    incubator/qpid/trunk/qpid/cpp/src/qpid/sys/posix/Socket.cpp
    incubator/qpid/trunk/qpid/cpp/src/qpid/sys/posix/Thread.cpp
    incubator/qpid/trunk/qpid/cpp/src/tests/Makefile.am
    incubator/qpid/trunk/qpid/cpp/src/tests/ProducerConsumerTest.cpp
    incubator/qpid/trunk/qpid/cpp/src/tests/topic_listener.cpp
    incubator/qpid/trunk/qpid/cpp/src/tests/topic_publisher.cpp

Propchange: incubator/qpid/trunk/qpid/cpp/
------------------------------------------------------------------------------
--- svn:ignore (original)
+++ svn:ignore Tue May 22 08:18:08 2007
@@ -19,3 +19,9 @@
 configure.ac
 gen
 qpidc.spec.in
+.settings
+.cdtbuild
+.cdtproject
+.project
+.cdtconfigure.Build (Gnu)
+config.h.in

Modified: incubator/qpid/trunk/qpid/cpp/configure.ac
URL: http://svn.apache.org/viewvc/incubator/qpid/trunk/qpid/cpp/configure.ac?view=diff&rev=540608&r1=540607&r2=540608
==============================================================================
--- incubator/qpid/trunk/qpid/cpp/configure.ac (original)
+++ incubator/qpid/trunk/qpid/cpp/configure.ac Tue May 22 08:18:08 2007
@@ -90,26 +90,44 @@
 AC_SUBST(CPPUNIT_LIBS)
 AC_SUBST(CPPUNIT_CXXFLAGS)
 
-AC_ARG_ENABLE([apr],
-  [AS_HELP_STRING([--enable-apr],
-    [use the Apache Portable Runtime library (default yes)])],
+AC_ARG_ENABLE([apr-netio],
+  [AS_HELP_STRING([--enable-apr-netio],
+    [use the Apache Portable Runtime library for network IO (default yes)])],
   [case $enableval in
-    yes|no) enable_APR=$enableval;;
-    *) AC_MSG_ERROR([Invalid value for --enable-apr: $enableval]);;
+    yes|no) enable_APR_NETIO=$enableval;;
+    *) AC_MSG_ERROR([Invalid value for --enable-apr-netio: $enableval]);;
    esac],
-  [enable_APR=yes]
+  [enable_APR_NETIO=yes]
 )
-AM_CONDITIONAL([USE_APR], [test x$enable_APR = xyes])
+AM_CONDITIONAL([USE_APR_NETIO], [test x$enable_APR_NETIO = xyes])
+
+AC_ARG_ENABLE([apr-platform],
+  [AS_HELP_STRING([--enable-apr-platform],
+    [use the Apache Portable Runtime library for platform (default yes)])],
+  [case $enableval in
+    yes|no) enable_APR_PLATFORM=$enableval;;
+    *) AC_MSG_ERROR([Invalid value for --enable-apr-platform: $enableval]);;
+   esac],
+  [enable_APR_PLATFORM=yes]
+)
+AM_CONDITIONAL([USE_APR_PLATFORM], [test x$enable_APR_PLATFORM = xyes])
 
 APR_MINIMUM_VERSION=1.2.2
 AC_SUBST(APR_MINIMUM_VERSION)
 AC_SUBST(APR_CXXFLAGS)
-AC_SUBST(USE_APR)
+AC_SUBST(USE_APR_PLATFORM)
 
-if test "$enable_APR" = yes; then
+if test "$enable_APR_NETIO" = yes -o "$enable_APR_PLATFORM" = yes; then
   PKG_CHECK_MODULES([APR], [apr-1 >= $APR_MINIMUM_VERSION])
-  APR_CXXFLAGS="$APR_CFLAGS -DUSE_APR=1"
-  USE_APR=1
+  APR_CXXFLAGS="$APR_CFLAGS"
+  if test "$enable_APR_NETIO" = yes; then
+  	APR_CXXFLAGS+=" -DUSE_APR_NETIO=1"
+	USE_APR_NETIO=1
+  fi
+  if test "$enable_APR_PLATFORM" = yes; then
+  	APR_CXXFLAGS+=" -DUSE_APR_PLATFORM=1"
+	USE_APR_PLATFORM=1
+  fi
 fi
 
 AC_ARG_ENABLE([valgrind],

Modified: incubator/qpid/trunk/qpid/cpp/src/Makefile.am
URL: http://svn.apache.org/viewvc/incubator/qpid/trunk/qpid/cpp/src/Makefile.am?view=diff&rev=540608&r1=540607&r2=540608
==============================================================================
--- incubator/qpid/trunk/qpid/cpp/src/Makefile.am (original)
+++ incubator/qpid/trunk/qpid/cpp/src/Makefile.am Tue May 22 08:18:08 2007
@@ -30,44 +30,75 @@
 sbin_PROGRAMS = qpidd
 qpidd_SOURCES = qpidd.cpp
 
-apr_src = \
+apr_netio_src = \
   qpid/sys/apr/APRAcceptor.cpp \
   qpid/sys/apr/APRBase.cpp \
   qpid/sys/apr/APRPool.cpp \
   qpid/sys/apr/APRSocket.cpp \
   qpid/sys/apr/LFProcessor.cpp \
-  qpid/sys/apr/LFSessionContext.cpp \
-  qpid/sys/apr/Socket.cpp \
-  qpid/sys/apr/Thread.cpp
+  qpid/sys/apr/LFSessionContext.cpp
 
-apr_hdr = \
+apr_netio_hdr = \
   qpid/sys/apr/APRBase.h \
   qpid/sys/apr/APRPool.h \
   qpid/sys/apr/APRSocket.h \
   qpid/sys/apr/LFProcessor.h \
   qpid/sys/apr/LFSessionContext.h	
 
-posix_src = \
-  qpid/sys/posix/PosixAcceptor.cpp \
-  qpid/sys/posix/Socket.cpp \
-  qpid/sys/posix/Thread.cpp \
-  qpid/sys/posix/check.cpp \
+apr_plat_src = \
+  qpid/sys/apr/Socket.cpp \
+  qpid/sys/apr/Time.cpp \
+  qpid/sys/apr/Thread.cpp
+
+apr_plat_hdr = \
+  qpid/sys/apr/Condition.h \
+  qpid/sys/apr/Module.h \
+  qpid/sys/apr/Mutex.h \
+  qpid/sys/apr/Socket.h \
+  qpid/sys/apr/Thread.h
+
+posix_netio_src = \
   qpid/sys/posix/EventChannel.cpp \
+  qpid/sys/posix/EventChannelAcceptor.cpp \
+  qpid/sys/posix/EventChannelConnection.cpp \
   qpid/sys/posix/EventChannelThreads.cpp
 
-posix_hdr = \
-  qpid/sys/posix/check.h \
+posix_netio_hdr = \
   qpid/sys/posix/EventChannel.h \
   qpid/sys/posix/EventChannelThreads.h
 
-if USE_APR
- platform_dist=$(posix_src) $(posix_hdr)
- platform_src = $(apr_src)
- platform_hdr = $(apr_hdr)
+posix_plat_src = \
+  qpid/sys/posix/check.cpp \
+  qpid/sys/posix/Socket.cpp \
+  qpid/sys/posix/Time.cpp \
+  qpid/sys/posix/Thread.cpp
+
+posix_plat_hdr = \
+  qpid/sys/posix/check.h \
+  qpid/sys/posix/Condition.h \
+  qpid/sys/posix/Module.h \
+  qpid/sys/posix/Mutex.h \
+  qpid/sys/posix/Socket.h \
+  qpid/sys/posix/Thread.h
+
+if USE_APR_NETIO
+ platform_dist=$(posix_netio_src) $(posix_netio_hdr)
+ platform_src = $(apr_netio_src)
+ platform_hdr = $(apr_netio_hdr)
+else
+ platform_dist=$(apr_netio_src) $(apr_netio_hdr)
+ platform_src = $(posix_netio_src)
+ platform_hdr = $(posix_netio_hdr)
+endif
+
+if USE_APR_PLATFORM
+ platform_dist+=$(posix_plat_src) $(posix_plat_hdr)
+ platform_src += $(apr_plat_src)
+ platform_hdr += $(apr_plat_hdr)
 else
- platform_dist =$(apr_src) $(apr_hdr) $(generated_cpp) $(generated_h)
- platform_src = $(posix_src)
- platform_hdr = $(posix_hdr)
+ platform_dist+=$(apr_plat_src) $(apr_plat_hdr)
+ platform_src += $(posix_plat_src)
+ platform_hdr += $(posix_plat_hdr)
 endif
 
 lib_LTLIBRARIES = libqpidcommon.la libqpidbroker.la libqpidclient.la
@@ -111,7 +142,6 @@
   qpid/ExceptionHolder.cpp \
   qpid/QpidError.cpp \
   qpid/sys/Runnable.cpp \
-  qpid/sys/Time.cpp \
   qpid/sys/ProducerConsumer.cpp \
   qpid/CommonOptions.cpp
 

Propchange: incubator/qpid/trunk/qpid/cpp/src/qpid/
------------------------------------------------------------------------------
--- svn:ignore (added)
+++ svn:ignore Tue May 22 08:18:08 2007
@@ -0,0 +1,3 @@
+.deps
+.libs
+.dirstamp

Propchange: incubator/qpid/trunk/qpid/cpp/src/qpid/broker/
------------------------------------------------------------------------------
--- svn:ignore (original)
+++ svn:ignore Tue May 22 08:18:08 2007
@@ -2,3 +2,4 @@
 .libs
 Makefile
 Makefile.in
+.dirstamp

Modified: incubator/qpid/trunk/qpid/cpp/src/qpid/broker/AutoDelete.cpp
URL: http://svn.apache.org/viewvc/incubator/qpid/trunk/qpid/cpp/src/qpid/broker/AutoDelete.cpp?view=diff&rev=540608&r1=540607&r2=540608
==============================================================================
--- incubator/qpid/trunk/qpid/cpp/src/qpid/broker/AutoDelete.cpp (original)
+++ incubator/qpid/trunk/qpid/cpp/src/qpid/broker/AutoDelete.cpp Tue May 22 08:18:08 2007
@@ -25,7 +25,7 @@
 using namespace qpid::sys;
 
 AutoDelete::AutoDelete(QueueRegistry* const _registry, uint32_t _period)
-    : registry(_registry), period(_period), stopped(true) { }
+    : registry(_registry), period(_period*TIME_MSEC), stopped(true) { }
 
 void AutoDelete::add(Queue::shared_ptr const queue){
     Mutex::ScopedLock l(lock);
@@ -63,7 +63,7 @@
     Monitor::ScopedLock l(monitor);
     while(!stopped){
         process();
-        monitor.wait(period*TIME_MSEC);
+        monitor.wait(AbsTime(now(), period));
     }
 }
 

Modified: incubator/qpid/trunk/qpid/cpp/src/qpid/broker/AutoDelete.h
URL: http://svn.apache.org/viewvc/incubator/qpid/trunk/qpid/cpp/src/qpid/broker/AutoDelete.h?view=diff&rev=540608&r1=540607&r2=540608
==============================================================================
--- incubator/qpid/trunk/qpid/cpp/src/qpid/broker/AutoDelete.h (original)
+++ incubator/qpid/trunk/qpid/cpp/src/qpid/broker/AutoDelete.h Tue May 22 08:18:08 2007
@@ -26,6 +26,7 @@
 #include "BrokerQueue.h"
 #include "QueueRegistry.h"
 #include "qpid/sys/Thread.h"
+#include "qpid/sys/Runnable.h"
 
 namespace qpid {
     namespace broker{
@@ -34,7 +35,7 @@
             qpid::sys::Monitor monitor;            
             std::queue<Queue::shared_ptr> queues;
             QueueRegistry* const registry;
-            uint32_t period;
+            sys::Duration period;
             volatile bool stopped;
             qpid::sys::Thread runner;
             

Modified: incubator/qpid/trunk/qpid/cpp/src/qpid/broker/Broker.cpp
URL: http://svn.apache.org/viewvc/incubator/qpid/trunk/qpid/cpp/src/qpid/broker/Broker.cpp?view=diff&rev=540608&r1=540607&r2=540608
==============================================================================
--- incubator/qpid/trunk/qpid/cpp/src/qpid/broker/Broker.cpp (original)
+++ incubator/qpid/trunk/qpid/cpp/src/qpid/broker/Broker.cpp Tue May 22 08:18:08 2007
@@ -18,8 +18,8 @@
  * under the License.
  *
  */
-#include <iostream>
-#include <memory>
+
+#include "Broker.h"
 
 #include "qpid/framing/AMQFrame.h"
 #include "DirectExchange.h"
@@ -31,11 +31,15 @@
 #include "qpid/framing/ProtocolInitiation.h"
 #include "RecoveryManagerImpl.h"
 #include "Connection.h"
+#include "qpid/sys/Acceptor.h"
 #include "qpid/sys/ConnectionInputHandler.h"
 #include "qpid/sys/ConnectionInputHandlerFactory.h"
 #include "qpid/sys/TimeoutHandler.h"
 
-#include "Broker.h"
+#include <iostream>
+#include <memory>
+
+using qpid::sys::Acceptor;
 
 namespace qpid {
 namespace broker {

Modified: incubator/qpid/trunk/qpid/cpp/src/qpid/broker/BrokerQueue.cpp
URL: http://svn.apache.org/viewvc/incubator/qpid/trunk/qpid/cpp/src/qpid/broker/BrokerQueue.cpp?view=diff&rev=540608&r1=540607&r2=540608
==============================================================================
--- incubator/qpid/trunk/qpid/cpp/src/qpid/broker/BrokerQueue.cpp (original)
+++ incubator/qpid/trunk/qpid/cpp/src/qpid/broker/BrokerQueue.cpp Tue May 22 08:18:08 2007
@@ -44,11 +44,10 @@
     queueing(false),
     dispatching(false),
     next(0),
-    lastUsed(0),
     exclusive(0),
     persistenceId(0)
 {
-    if(autodelete) lastUsed = now()/TIME_MSEC;
+    if(autodelete) lastUsed = now();
 }
 
 Queue::~Queue(){}
@@ -135,7 +134,7 @@
                             "Exclusive access denied.") %getName());
         exclusive = c;
     }
-    if(autodelete && consumers.empty()) lastUsed = 0;
+    if(autodelete && consumers.empty()) lastUsed = FAR_FUTURE;
     consumers.push_back(c);
 }
 
@@ -144,7 +143,7 @@
     Consumers::iterator i = std::find(consumers.begin(), consumers.end(), c);
     if (i != consumers.end()) 
         consumers.erase(i);
-    if(autodelete && consumers.empty()) lastUsed = now()*TIME_MSEC;
+    if(autodelete && consumers.empty()) lastUsed = now();
     if(exclusive == c) exclusive = 0;
 }
 
@@ -193,7 +192,7 @@
 
 bool Queue::canAutoDelete() const{
     Mutex::ScopedLock locker(lock);
-    return lastUsed && (now()*TIME_MSEC - lastUsed > autodelete);
+    return Duration(lastUsed, now()) > autodelete;
 }
 
 void Queue::enqueue(TransactionContext* ctxt, Message::shared_ptr& msg)

Modified: incubator/qpid/trunk/qpid/cpp/src/qpid/broker/BrokerQueue.h
URL: http://svn.apache.org/viewvc/incubator/qpid/trunk/qpid/cpp/src/qpid/broker/BrokerQueue.h?view=diff&rev=540608&r1=540607&r2=540608
==============================================================================
--- incubator/qpid/trunk/qpid/cpp/src/qpid/broker/BrokerQueue.h (original)
+++ incubator/qpid/trunk/qpid/cpp/src/qpid/broker/BrokerQueue.h Tue May 22 08:18:08 2007
@@ -58,7 +58,7 @@
             typedef std::queue<Message::shared_ptr> Messages;
             
             const string name;
-            const uint32_t autodelete;
+            const sys::Duration autodelete;
             MessageStore* const store;
             const ConnectionToken* const owner;
             Consumers consumers;
@@ -67,7 +67,7 @@
             bool dispatching;
             int next;
             mutable qpid::sys::Mutex lock;
-            int64_t lastUsed;
+            sys::AbsTime lastUsed;
             Consumer* exclusive;
             mutable uint64_t persistenceId;
             framing::FieldTable settings;

Propchange: incubator/qpid/trunk/qpid/cpp/src/qpid/client/
------------------------------------------------------------------------------
--- svn:ignore (original)
+++ svn:ignore Tue May 22 08:18:08 2007
@@ -2,3 +2,4 @@
 .libs
 Makefile
 Makefile.in
+.dirstamp

Modified: incubator/qpid/trunk/qpid/cpp/src/qpid/client/Connector.cpp
URL: http://svn.apache.org/viewvc/incubator/qpid/trunk/qpid/cpp/src/qpid/client/Connector.cpp?view=diff&rev=540608&r1=540607&r2=540608
==============================================================================
--- incubator/qpid/trunk/qpid/cpp/src/qpid/client/Connector.cpp (original)
+++ incubator/qpid/trunk/qpid/cpp/src/qpid/client/Connector.cpp Tue May 22 08:18:08 2007
@@ -37,7 +37,6 @@
     send_buffer_size(buffer_size),
     version(ver), 
     closed(true),
-    lastIn(0), lastOut(0),
     timeout(0),
     idleIn(0), idleOut(0), 
     timeoutHandler(0),
@@ -100,7 +99,7 @@
     while(written < available && !closed){
 	ssize_t sent = socket.send(data + written, available-written);
         if(sent > 0) {
-            lastOut = now() * TIME_MSEC;
+            lastOut = now();
             written += sent;
         }
     }
@@ -124,9 +123,9 @@
 
 void Connector::checkIdle(ssize_t status){
     if(timeoutHandler){
-        Time t = now() * TIME_MSEC;
+        AbsTime t = now();
         if(status == Socket::SOCKET_TIMEOUT) {
-            if(idleIn && (t - lastIn > idleIn)){
+            if(idleIn && (Duration(lastIn, t) > idleIn)){
                 timeoutHandler->idleIn();
             }
         }
@@ -136,14 +135,14 @@
         else {
             lastIn = t;
         }
-        if(idleOut && (t - lastOut > idleOut)){
+        if(idleOut && (Duration(lastOut, t) > idleOut)){
             timeoutHandler->idleOut();
         }
     }
 }
 
 void Connector::setReadTimeout(uint16_t t){
-    idleIn = t * 1000;//t is in secs
+    idleIn = t * TIME_SEC;//t is in secs
     if(idleIn && (!timeout || idleIn < timeout)){
         timeout = idleIn;
         setSocketTimeout();
@@ -152,7 +151,7 @@
 }
 
 void Connector::setWriteTimeout(uint16_t t){
-    idleOut = t * 1000;//t is in secs
+    idleOut = t * TIME_SEC;//t is in secs
     if(idleOut && (!timeout || idleOut < timeout)){
         timeout = idleOut;
         setSocketTimeout();
@@ -160,7 +159,7 @@
 }
 
 void Connector::setSocketTimeout(){
-    socket.setTimeout(timeout*TIME_MSEC);
+    socket.setTimeout(timeout);
 }
 
 void Connector::setTimeoutHandler(TimeoutHandler* handler){

Modified: incubator/qpid/trunk/qpid/cpp/src/qpid/client/Connector.h
URL: http://svn.apache.org/viewvc/incubator/qpid/trunk/qpid/cpp/src/qpid/client/Connector.h?view=diff&rev=540608&r1=540607&r2=540608
==============================================================================
--- incubator/qpid/trunk/qpid/cpp/src/qpid/client/Connector.h (original)
+++ incubator/qpid/trunk/qpid/cpp/src/qpid/client/Connector.h Tue May 22 08:18:08 2007
@@ -30,8 +30,10 @@
 #include "qpid/sys/ShutdownHandler.h"
 #include "qpid/sys/TimeoutHandler.h"
 #include "qpid/sys/Thread.h"
+#include "qpid/sys/Runnable.h"
 #include "qpid/sys/Monitor.h"
 #include "qpid/sys/Socket.h"
+#include "qpid/sys/Time.h"
 
 namespace qpid {
 
@@ -48,11 +50,11 @@
     bool closed;
     sys::Mutex closedLock;
 
-    int64_t lastIn;
-    int64_t lastOut;
-    int64_t timeout;
-    uint32_t idleIn;
-    uint32_t idleOut;
+    sys::AbsTime lastIn;
+    sys::AbsTime lastOut;
+    sys::Duration timeout;
+    sys::Duration idleIn;
+    sys::Duration idleOut;
 
     sys::TimeoutHandler* timeoutHandler;
     sys::ShutdownHandler* shutdownHandler;

Propchange: incubator/qpid/trunk/qpid/cpp/src/qpid/framing/
------------------------------------------------------------------------------
--- svn:ignore (added)
+++ svn:ignore Tue May 22 08:18:08 2007
@@ -0,0 +1,3 @@
+.deps
+.libs
+.dirstamp

Propchange: incubator/qpid/trunk/qpid/cpp/src/qpid/sys/
------------------------------------------------------------------------------
--- svn:ignore (added)
+++ svn:ignore Tue May 22 08:18:08 2007
@@ -0,0 +1,3 @@
+.deps
+.libs
+.dirstamp

Modified: incubator/qpid/trunk/qpid/cpp/src/qpid/sys/Condition.h
URL: http://svn.apache.org/viewvc/incubator/qpid/trunk/qpid/cpp/src/qpid/sys/Condition.h?view=diff&rev=540608&r1=540607&r2=540608
==============================================================================
--- incubator/qpid/trunk/qpid/cpp/src/qpid/sys/Condition.h (original)
+++ incubator/qpid/trunk/qpid/cpp/src/qpid/sys/Condition.h Tue May 22 08:18:08 2007
@@ -22,107 +22,10 @@
  *
  */
 
-#include <sys/errno.h>
-#include <boost/noncopyable.hpp>
-#include "Mutex.h"
-#include "Time.h"
-
-#ifdef USE_APR
-#include <apr_thread_cond.h>
-#endif
-
-namespace qpid {
-namespace sys {
-
-/**
- * A condition variable for thread synchronization.
- */
-class Condition
-{
-  public:
-    inline Condition();
-    inline ~Condition();
-    inline void wait(Mutex&);
-    inline bool wait(Mutex&, const Time& absoluteTime);
-    inline void notify();
-    inline void notifyAll();
-
-  private:
-#ifdef USE_APR
-    apr_thread_cond_t* condition;
+#ifdef USE_APR_PLATFORM
+#include "apr/Condition.h"
 #else
-    pthread_cond_t condition;
+#include "posix/Condition.h"
 #endif
-};
-
-
-// APR ================================================================
-#ifdef USE_APR
-
-Condition::Condition() {
-    CHECK_APR_SUCCESS(apr_thread_cond_create(&condition, APRPool::get()));
-}
-
-Condition::~Condition() {
-    CHECK_APR_SUCCESS(apr_thread_cond_destroy(condition));
-}
-
-void Condition::wait(Mutex& mutex) {
-    CHECK_APR_SUCCESS(apr_thread_cond_wait(condition, mutex.mutex));
-}
-
-bool Condition::wait(Mutex& mutex, const Time& absoluteTime){
-    // APR uses microseconds.
-    apr_status_t status =
-        apr_thread_cond_timedwait(
-            condition, mutex.mutex, absoluteTime/TIME_USEC);
-    if(status != APR_TIMEUP) CHECK_APR_SUCCESS(status);
-    return status == 0;
-}
-
-void Condition::notify(){
-    CHECK_APR_SUCCESS(apr_thread_cond_signal(condition));
-}
-
-void Condition::notifyAll(){
-    CHECK_APR_SUCCESS(apr_thread_cond_broadcast(condition));
-}
-
-#else
-// POSIX ================================================================
-
-Condition::Condition() {
-    QPID_POSIX_THROW_IF(pthread_cond_init(&condition, 0));
-}
-
-Condition::~Condition() {
-    QPID_POSIX_THROW_IF(pthread_cond_destroy(&condition));
-}
-
-void Condition::wait(Mutex& mutex) {
-    QPID_POSIX_THROW_IF(pthread_cond_wait(&condition, &mutex.mutex));
-}
-
-bool Condition::wait(Mutex& mutex, const Time& absoluteTime){
-    struct timespec ts;
-    toTimespec(ts, absoluteTime);
-    int status = pthread_cond_timedwait(&condition, &mutex.mutex, &ts);
-    if (status != 0) {
-        if (status == ETIMEDOUT) return false;
-        throw QPID_POSIX_ERROR(status);
-    }
-    return true;
-}
-
-void Condition::notify(){
-    QPID_POSIX_THROW_IF(pthread_cond_signal(&condition));
-}
-
-void Condition::notifyAll(){
-    QPID_POSIX_THROW_IF(pthread_cond_broadcast(&condition));
-}
-#endif  /*USE_APR*/
-
 
-}}
 #endif  /*!_sys_Condition_h*/

Modified: incubator/qpid/trunk/qpid/cpp/src/qpid/sys/Module.h
URL: http://svn.apache.org/viewvc/incubator/qpid/trunk/qpid/cpp/src/qpid/sys/Module.h?view=diff&rev=540608&r1=540607&r2=540608
==============================================================================
--- incubator/qpid/trunk/qpid/cpp/src/qpid/sys/Module.h (original)
+++ incubator/qpid/trunk/qpid/cpp/src/qpid/sys/Module.h Tue May 22 08:18:08 2007
@@ -21,141 +21,12 @@
  * under the License.
  *
  */
-#include <boost/noncopyable.hpp>
-#include <iostream>
-#include "qpid/QpidError.h"
-
-namespace qpid {
-namespace sys {
-#if USE_APR
-#include <apr_dso.h>
-    typedef apr_dso_handle_t* dso_handle_t;
+ 
+#ifdef USE_APR_PLATFORM
+#include "apr/Module.h"
 #else 
-    typedef void* dso_handle_t;
+#include "posix/Module.h"
 #endif
-
-    template <class T> class Module : private boost::noncopyable
-    {
-        typedef T* create_t();
-        typedef void destroy_t(T*);
-        
-        dso_handle_t handle;
-        destroy_t* destroy;
-        T* ptr;
-
-        void load(const std::string& name);
-        void unload();
-        void* getSymbol(const std::string& name);
-
-    public:
-        Module(const std::string& name);
-        T* operator->(); 
-        T* get(); 
-        ~Module() throw();
-    };
-
-}
-}
-
-using namespace qpid::sys;
-
-template <class T> Module<T>::Module(const std::string& module) : destroy(0), ptr(0) 
-{
-    load(module);
-    //TODO: need a better strategy for symbol names to allow multiple
-    //modules to be loaded without clashes...
-
-    //Note: need the double cast to avoid errors in casting from void* to function pointer with -pedantic
-    create_t* create = reinterpret_cast<create_t*>(reinterpret_cast<intptr_t>(getSymbol("create")));
-    destroy = reinterpret_cast<destroy_t*>(reinterpret_cast<intptr_t>(getSymbol("destroy")));
-    ptr = create();
-}
-
-template <class T> T* Module<T>::operator->() 
-{ 
-    return ptr; 
-}
-
-template <class T> T* Module<T>::get() 
-{ 
-    return ptr; 
-}
-
-template <class T> Module<T>::~Module() throw()
-{
-    try {
-        if (handle && ptr) {
-            destroy(ptr);
-        }
-        if (handle) unload();
-    } catch (std::exception& e) {
-        std::cout << "Error while destroying module: " << e.what() << std::endl;
-    }
-    destroy = 0;
-    handle = 0;
-    ptr = 0;
-}
-
-// APR ================================================================
-#if USE_APR
-
-#include "apr/APRBase.h"
-#include "apr/APRPool.h"
-
-template <class T> void Module<T>::load(const std::string& name)
-{
-    CHECK_APR_SUCCESS(apr_dso_load(&handle, name.c_str(), APRPool::get()));
-}
-
-template <class T> void Module<T>::unload()
-{
-    CHECK_APR_SUCCESS(apr_dso_unload(handle));
-}
-
-template <class T> void* Module<T>::getSymbol(const std::string& name)
-{
-    apr_dso_handle_sym_t symbol;
-    CHECK_APR_SUCCESS(apr_dso_sym(&symbol, handle, name.c_str()));
-    return (void*) symbol;
-}
-
-// POSIX================================================================
-#else 
-
-#include <dlfcn.h>
-
-template <class T> void Module<T>::load(const std::string& name)
-{
-    dlerror();
-    handle = dlopen(name.c_str(), RTLD_NOW);
-    const char* error = dlerror();
-    if (error) {
-        THROW_QPID_ERROR(INTERNAL_ERROR, error);
-    }
-}
-
-template <class T> void Module<T>::unload()
-{
-    dlerror();
-    dlclose(handle);
-    const char* error = dlerror();
-    if (error) {
-        THROW_QPID_ERROR(INTERNAL_ERROR, error);
-    }
-}
-
-template <class T> void* Module<T>::getSymbol(const std::string& name)
-{
-    dlerror();
-    void* sym = dlsym(handle, name.c_str());
-    const char* error = dlerror();
-    if (error) {
-        THROW_QPID_ERROR(INTERNAL_ERROR, error);
-    }
-    return sym;
-}
-
-#endif //if USE_APR
 
 #endif //ifndef _sys_Module_h
 

Modified: incubator/qpid/trunk/qpid/cpp/src/qpid/sys/Monitor.h
URL: http://svn.apache.org/viewvc/incubator/qpid/trunk/qpid/cpp/src/qpid/sys/Monitor.h?view=diff&rev=540608&r1=540607&r2=540608
==============================================================================
--- incubator/qpid/trunk/qpid/cpp/src/qpid/sys/Monitor.h (original)
+++ incubator/qpid/trunk/qpid/cpp/src/qpid/sys/Monitor.h Tue May 22 08:18:08 2007
@@ -25,10 +25,6 @@
 #include <sys/errno.h>
 #include "Condition.h"
 
-#ifdef USE_APR
-#include <apr_thread_cond.h>
-#endif
-
 namespace qpid {
 namespace sys {
 
@@ -39,7 +35,7 @@
   public:
     using Condition::wait;
     inline void wait();
-    inline bool wait(const Time& absoluteTime);
+    inline bool wait(const AbsTime& absoluteTime);
 };
 
 
@@ -47,7 +43,7 @@
     Condition::wait(*this);
 }
 
-bool Monitor::wait(const Time& absoluteTime) {
+bool Monitor::wait(const AbsTime& absoluteTime) {
     return Condition::wait(*this, absoluteTime);
 }
 

Modified: incubator/qpid/trunk/qpid/cpp/src/qpid/sys/Mutex.h
URL: http://svn.apache.org/viewvc/incubator/qpid/trunk/qpid/cpp/src/qpid/sys/Mutex.h?view=diff&rev=540608&r1=540607&r2=540608
==============================================================================
--- incubator/qpid/trunk/qpid/cpp/src/qpid/sys/Mutex.h (original)
+++ incubator/qpid/trunk/qpid/cpp/src/qpid/sys/Mutex.h Tue May 22 08:18:08 2007
@@ -19,21 +19,9 @@
  *
  */
 
-#ifdef USE_APR
-#include <apr_thread_mutex.h>
-#include "apr/APRBase.h"
-#include "apr/APRPool.h"
-#else
-#include <pthread.h>
-#include "posix/check.h"
-#endif
-#include <boost/noncopyable.hpp>
-
 namespace qpid {
 namespace sys {
 
-class Condition;
-
 /**
  * Scoped lock template: calls lock() in ctor, unlock() in dtor.
  * L can be any class with lock() and unlock() functions.
@@ -57,109 +45,13 @@
   private:
     L& mutex;
 };
-    
-/**
- * Mutex lock.
- */
-class Mutex : private boost::noncopyable {
-  public:
-    typedef ScopedLock<Mutex> ScopedLock;
-    typedef ScopedUnlock<Mutex> ScopedUnlock;
-    
-    inline Mutex();
-    inline ~Mutex();
-    inline void lock();
-    inline void unlock();
-    inline void trylock();
 
-  protected:
-#ifdef USE_APR
-    apr_thread_mutex_t* mutex;
+}}
+    
+#ifdef USE_APR_PLATFORM
+#include "apr/Mutex.h"
 #else
-    pthread_mutex_t mutex;
+#include "posix/Mutex.h"
 #endif
-  friend class Condition;
-};
-
-#ifdef USE_APR
-// APR ================================================================
-
-Mutex::Mutex() {
-    CHECK_APR_SUCCESS(apr_thread_mutex_create(&mutex, APR_THREAD_MUTEX_NESTED, APRPool::get()));
-}
-
-Mutex::~Mutex(){
-    CHECK_APR_SUCCESS(apr_thread_mutex_destroy(mutex));
-}
-
-void Mutex::lock() {
-    CHECK_APR_SUCCESS(apr_thread_mutex_lock(mutex));
-}
-void Mutex::unlock() {
-    CHECK_APR_SUCCESS(apr_thread_mutex_unlock(mutex));
-}
-
-void Mutex::trylock() {
-    CHECK_APR_SUCCESS(apr_thread_mutex_trylock(mutex));
-}
-
-#else
-// POSIX ================================================================
-
-/**
- * PODMutex is a POD, can be static-initialized with
- * PODMutex m = QPID_PODMUTEX_INITIALIZER
- */
-struct PODMutex 
-{
-    typedef ScopedLock<PODMutex> ScopedLock;
-
-    inline void lock();
-    inline void unlock();
-    inline void trylock();
-
-    // Must be public to be a POD:
-    pthread_mutex_t mutex;
-};
-
-#define QPID_MUTEX_INITIALIZER { PTHREAD_MUTEX_INITIALIZER }
-
-
-void PODMutex::lock() {
-    QPID_POSIX_THROW_IF(pthread_mutex_lock(&mutex));
-}
-void PODMutex::unlock() {
-    QPID_POSIX_THROW_IF(pthread_mutex_unlock(&mutex));
-}
-
-void PODMutex::trylock() {
-    QPID_POSIX_THROW_IF(pthread_mutex_trylock(&mutex));
-}
-
-
-Mutex::Mutex() {
-    QPID_POSIX_THROW_IF(pthread_mutex_init(&mutex, 0));
-}
-
-Mutex::~Mutex(){
-    QPID_POSIX_THROW_IF(pthread_mutex_destroy(&mutex));
-}
-
-void Mutex::lock() {
-    QPID_POSIX_THROW_IF(pthread_mutex_lock(&mutex));
-}
-void Mutex::unlock() {
-    QPID_POSIX_THROW_IF(pthread_mutex_unlock(&mutex));
-}
-
-void Mutex::trylock() {
-    QPID_POSIX_THROW_IF(pthread_mutex_trylock(&mutex));
-}
-
-#endif // USE_APR
-
-}}
-
-
 
 #endif  /*!_sys_Mutex_h*/

Modified: incubator/qpid/trunk/qpid/cpp/src/qpid/sys/ProducerConsumer.cpp
URL: http://svn.apache.org/viewvc/incubator/qpid/trunk/qpid/cpp/src/qpid/sys/ProducerConsumer.cpp?view=diff&rev=540608&r1=540607&r2=540608
==============================================================================
--- incubator/qpid/trunk/qpid/cpp/src/qpid/sys/ProducerConsumer.cpp (original)
+++ incubator/qpid/trunk/qpid/cpp/src/qpid/sys/ProducerConsumer.cpp Tue May 22 08:18:08 2007
@@ -103,7 +103,7 @@
 }
 
 ProducerConsumer::ConsumerLock::ConsumerLock(
-    ProducerConsumer& p, const Time& timeout) : Lock(p)
+    ProducerConsumer& p, const Duration& timeout) : Lock(p)
 {
     if (isOk()) {
         // Don't wait if timeout==0
@@ -113,7 +113,7 @@
             return;
         }
         else {
-            Time deadline = now() + timeout;
+            AbsTime deadline(now(), timeout);
             ScopedIncrement<size_t> inc(pc.waiters);
             while (pc.items == 0 && !pc.shutdownFlag) {
                 if (!pc.monitor.wait(deadline)) {

Modified: incubator/qpid/trunk/qpid/cpp/src/qpid/sys/ProducerConsumer.h
URL: http://svn.apache.org/viewvc/incubator/qpid/trunk/qpid/cpp/src/qpid/sys/ProducerConsumer.h?view=diff&rev=540608&r1=540607&r2=540608
==============================================================================
--- incubator/qpid/trunk/qpid/cpp/src/qpid/sys/ProducerConsumer.h (original)
+++ incubator/qpid/trunk/qpid/cpp/src/qpid/sys/ProducerConsumer.h Tue May 22 08:18:08 2007
@@ -143,7 +143,7 @@
          * If isTimedOut() there was a timeout.
          * If neither then we were shutdown.
          */
-        ConsumerLock(ProducerConsumer& p, const Time& timeout);
+        ConsumerLock(ProducerConsumer& p, const Duration& timeout);
 
         /** Release locks */
         ~ConsumerLock();

Modified: incubator/qpid/trunk/qpid/cpp/src/qpid/sys/Socket.h
URL: http://svn.apache.org/viewvc/incubator/qpid/trunk/qpid/cpp/src/qpid/sys/Socket.h?view=diff&rev=540608&r1=540607&r2=540608
==============================================================================
--- incubator/qpid/trunk/qpid/cpp/src/qpid/sys/Socket.h (original)
+++ incubator/qpid/trunk/qpid/cpp/src/qpid/sys/Socket.h Tue May 22 08:18:08 2007
@@ -22,67 +22,10 @@
  *
  */
 
-#include <string>
-#include "Time.h"
-
-#ifdef USE_APR
-#include <apr_network_io.h>
-#endif
-
-namespace qpid {
-namespace sys {
-
-class Socket
-{
-  public:
-    /** Create an initialized TCP socket */
-    static Socket createTcp();
-
-    /** Create a socket wrapper for descriptor. */
-#ifdef USE_APR
-    Socket(apr_socket_t* descriptor = 0);
-#else
-    Socket(int descriptor = 0);
-#endif
-    
-    /** Set timeout for read and write */
-    void setTimeout(Time interval);
-
-    void connect(const std::string& host, int port);
-
-    void close();
-
-    enum { SOCKET_TIMEOUT=-2, SOCKET_EOF=-3 } ErrorCode;
-
-    /** Returns bytes sent or an ErrorCode value < 0. */
-    ssize_t send(const void* data, size_t size);
-
-    /**
-     * Returns bytes received, an ErrorCode value < 0 or 0
-     * if the connection closed in an orderly manner.
-     */
-    ssize_t recv(void* data, size_t size);
-
-    /** Bind to a port and start listening.
-     *@param port 0 means choose an available port.
-     *@param backlog maximum number of pending connections.
-     *@return The bound port.
-     */
-    int listen(int port = 0, int backlog = 10);
-
-    /** Get file descriptor */
-    int fd(); 
-    
-  private:
-#ifdef USE_APR    
-    apr_socket_t* socket;
+#ifdef USE_APR_PLATFORM
+#include "apr/Socket.h"
 #else
-    void init() const;
-    mutable int socket;         // Initialized on demand. 
+#include "posix/Socket.h"
 #endif
-};
-
-}}
-
 
 #endif  /*!_sys_Socket_h*/

Modified: incubator/qpid/trunk/qpid/cpp/src/qpid/sys/Thread.h
URL: http://svn.apache.org/viewvc/incubator/qpid/trunk/qpid/cpp/src/qpid/sys/Thread.h?view=diff&rev=540608&r1=540607&r2=540608
==============================================================================
--- incubator/qpid/trunk/qpid/cpp/src/qpid/sys/Thread.h (original)
+++ incubator/qpid/trunk/qpid/cpp/src/qpid/sys/Thread.h Tue May 22 08:18:08 2007
@@ -22,121 +22,10 @@
  *
  */
 
-#include "Runnable.h"
-
-#ifdef USE_APR
-#include <apr_thread_proc.h>
-#include <apr_portable.h>
-#include "apr/APRPool.h"
-#include "apr/APRBase.h"
+#ifdef USE_APR_PLATFORM
+#include "apr/Thread.h"
 #else
-#include "posix/check.h"
-#include <pthread.h>
+#include "posix/Thread.h"
 #endif
-
-namespace qpid {
-namespace sys {
-
-class Thread
-{
-  public:
-    inline static Thread current();
-    inline static void yield();
-
-    inline Thread();
-    inline explicit Thread(qpid::sys::Runnable*);
-    inline explicit Thread(qpid::sys::Runnable&);
-    
-    inline void join();
-
-    inline long id();
-        
-  private:
-#ifdef USE_APR
-    static void* APR_THREAD_FUNC runRunnable(apr_thread_t* thread, void *data);
-    inline Thread(apr_thread_t* t);
-    apr_thread_t* thread;
-#else
-    static void* runRunnable(void* runnable);
-    inline Thread(pthread_t);
-    pthread_t thread;
-#endif    
-};
-
-
-Thread::Thread() : thread(0) {}
-
-// APR ================================================================
-#ifdef USE_APR
-
-Thread::Thread(Runnable* runnable) {
-    CHECK_APR_SUCCESS(
-        apr_thread_create(&thread, 0, runRunnable, runnable, APRPool::get()));
-}
-
-Thread::Thread(Runnable& runnable) {
-    CHECK_APR_SUCCESS(
-        apr_thread_create(&thread, 0, runRunnable, &runnable, APRPool::get()));
-}
-
-void Thread::join(){
-    apr_status_t status;
-    if (thread != 0) 
-        CHECK_APR_SUCCESS(apr_thread_join(&status, thread));
-}
-
-long Thread::id() {
-    return long(thread);
-}
-
-Thread::Thread(apr_thread_t* t) : thread(t) {}
-
-Thread Thread::current(){
-    apr_thread_t* thr;
-    apr_os_thread_t osthr = apr_os_thread_current();
-    CHECK_APR_SUCCESS(apr_os_thread_put(&thr, &osthr, APRPool::get()));
-    return Thread(thr);
-}
-
-void Thread::yield() 
-{
-    apr_thread_yield();
-}
-
-
-// POSIX ================================================================
-#else
-
-Thread::Thread(Runnable* runnable) {
-    QPID_POSIX_THROW_IF(pthread_create(&thread, NULL, runRunnable, runnable));
-}
-
-Thread::Thread(Runnable& runnable) {
-    QPID_POSIX_THROW_IF(pthread_create(&thread, NULL, runRunnable, &runnable));
-}
-
-void Thread::join(){
-    QPID_POSIX_THROW_IF(pthread_join(thread, 0));
-}
-
-long Thread::id() {
-    return long(thread);
-}
-
-Thread::Thread(pthread_t thr) : thread(thr) {}
-
-Thread Thread::current() {
-    return Thread(pthread_self());
-}
-
-void Thread::yield() 
-{
-    QPID_POSIX_THROW_IF(pthread_yield());
-}
-
-
-#endif
-
-}}
 
 #endif  /*!_sys_Thread_h*/

Modified: incubator/qpid/trunk/qpid/cpp/src/qpid/sys/Time.h
URL: http://svn.apache.org/viewvc/incubator/qpid/trunk/qpid/cpp/src/qpid/sys/Time.h?view=diff&rev=540608&r1=540607&r2=540608
==============================================================================
--- incubator/qpid/trunk/qpid/cpp/src/qpid/sys/Time.h (original)
+++ incubator/qpid/trunk/qpid/cpp/src/qpid/sys/Time.h Tue May 22 08:18:08 2007
@@ -23,36 +23,76 @@
  */
 
 #include <stdint.h>
-
-#ifdef USE_APR
-#include <apr_time.h>
-#else
-#include <time.h>
-#endif
+#include <limits>
 
 namespace qpid {
 namespace sys {
 
-/** Time in nanoseconds */
-typedef int64_t Time;
+class Duration;
+
+/** Times in nanoseconds */
+class AbsTime {
+    int64_t time_ns;
+
+	friend class Duration;
+	
+public:
+	inline AbsTime() {}
+	inline AbsTime(const AbsTime& time0, const Duration& duration);
+	// Default asignment operation fine
+	// Default copy constructor fine
+	 
+	static AbsTime now();
+	inline static AbsTime FarFuture();
+};
+
+class Duration {
+    int64_t nanosecs;
+
+	friend class AbsTime;
+
+public:
+	inline Duration(int64_t time0);
+	inline explicit Duration(const AbsTime& time0);
+	inline explicit Duration(const AbsTime& start, const AbsTime& finish);
+	inline operator int64_t() const;
+};
+
+
+AbsTime::AbsTime(const AbsTime& time0, const Duration& duration0) :
+	time_ns(time0.time_ns+duration0.nanosecs)
+{}
+
+AbsTime AbsTime::FarFuture() { AbsTime ff; ff.time_ns = std::numeric_limits<int64_t>::max(); return ff;}
+
+inline AbsTime now() { return AbsTime::now(); }
+
+Duration::Duration(int64_t time0) :
+	nanosecs(time0)
+{}
+
+Duration::Duration(const AbsTime& time0) :
+	nanosecs(time0.time_ns)
+{}
+
+Duration::Duration(const AbsTime& start, const AbsTime& finish) :
+	nanosecs(finish.time_ns - start.time_ns)
+{}
 
-Time now();
+Duration::operator int64_t() const
+{ return nanosecs; }
 
 /** Nanoseconds per second. */
-const Time TIME_SEC  = 1000*1000*1000;
+const Duration TIME_SEC  = 1000*1000*1000;
 /** Nanoseconds per millisecond */
-const Time TIME_MSEC = 1000*1000;
+const Duration TIME_MSEC = 1000*1000;
 /** Nanoseconds per microseconds. */
-const Time TIME_USEC = 1000;
+const Duration TIME_USEC = 1000;
 /** Nanoseconds per nanosecond. */
-const Time TIME_NSEC = 1;
-
-#ifndef USE_APR
-struct timespec toTimespec(const Time& t);
-struct timespec& toTimespec(struct timespec& ts, const Time& t);
-Time toTime(const struct timespec& ts);
-#endif
+const Duration TIME_NSEC = 1;
 
+/** Time greater than any other time */
+const AbsTime FAR_FUTURE = AbsTime::FarFuture();
 }}
 
 #endif  /*!_sys_Time_h*/

Propchange: incubator/qpid/trunk/qpid/cpp/src/qpid/sys/apr/
------------------------------------------------------------------------------
--- svn:ignore (added)
+++ svn:ignore Tue May 22 08:18:08 2007
@@ -0,0 +1 @@
+.deps

Modified: incubator/qpid/trunk/qpid/cpp/src/qpid/sys/apr/APRAcceptor.cpp
URL: http://svn.apache.org/viewvc/incubator/qpid/trunk/qpid/cpp/src/qpid/sys/apr/APRAcceptor.cpp?view=diff&rev=540608&r1=540607&r2=540608
==============================================================================
--- incubator/qpid/trunk/qpid/cpp/src/qpid/sys/apr/APRAcceptor.cpp (original)
+++ incubator/qpid/trunk/qpid/cpp/src/qpid/sys/apr/APRAcceptor.cpp Tue May 22 08:18:08 2007
@@ -20,6 +20,7 @@
  */
 #include "qpid/sys/Acceptor.h"
 #include "qpid/sys/ConnectionInputHandlerFactory.h"
+#include "qpid/sys/Mutex.h"
 #include "LFProcessor.h"
 #include "LFSessionContext.h"
 #include "APRBase.h"

Copied: incubator/qpid/trunk/qpid/cpp/src/qpid/sys/apr/Condition.h (from r537157, incubator/qpid/trunk/qpid/cpp/src/qpid/sys/Condition.h)
URL: http://svn.apache.org/viewvc/incubator/qpid/trunk/qpid/cpp/src/qpid/sys/apr/Condition.h?view=diff&rev=540608&p1=incubator/qpid/trunk/qpid/cpp/src/qpid/sys/Condition.h&r1=537157&p2=incubator/qpid/trunk/qpid/cpp/src/qpid/sys/apr/Condition.h&r2=540608
==============================================================================
--- incubator/qpid/trunk/qpid/cpp/src/qpid/sys/Condition.h (original)
+++ incubator/qpid/trunk/qpid/cpp/src/qpid/sys/apr/Condition.h Tue May 22 08:18:08 2007
@@ -1,5 +1,5 @@
-#ifndef _sys_Condition_h
-#define _sys_Condition_h
+#ifndef _sys_apr_Condition_h
+#define _sys_apr_Condition_h
 
 /*
  *
@@ -22,14 +22,13 @@
  *
  */
 
+#include "APRPool.h"
+#include "qpid/sys/Mutex.h"
+#include "qpid/sys/Time.h"
+
 #include <sys/errno.h>
 #include <boost/noncopyable.hpp>
-#include "Mutex.h"
-#include "Time.h"
-
-#ifdef USE_APR
 #include <apr_thread_cond.h>
-#endif
 
 namespace qpid {
 namespace sys {
@@ -43,22 +42,15 @@
     inline Condition();
     inline ~Condition();
     inline void wait(Mutex&);
-    inline bool wait(Mutex&, const Time& absoluteTime);
+    inline bool wait(Mutex&, const AbsTime& absoluteTime);
     inline void notify();
     inline void notifyAll();
 
   private:
-#ifdef USE_APR
     apr_thread_cond_t* condition;
-#else
-    pthread_cond_t condition;
-#endif
 };
 
 
-// APR ================================================================
-#ifdef USE_APR
-
 Condition::Condition() {
     CHECK_APR_SUCCESS(apr_thread_cond_create(&condition, APRPool::get()));
 }
@@ -71,11 +63,11 @@
     CHECK_APR_SUCCESS(apr_thread_cond_wait(condition, mutex.mutex));
 }
 
-bool Condition::wait(Mutex& mutex, const Time& absoluteTime){
+bool Condition::wait(Mutex& mutex, const AbsTime& absoluteTime){
     // APR uses microseconds.
     apr_status_t status =
         apr_thread_cond_timedwait(
-            condition, mutex.mutex, absoluteTime/TIME_USEC);
+            condition, mutex.mutex, Duration(now(), absoluteTime)/TIME_USEC);
     if(status != APR_TIMEUP) CHECK_APR_SUCCESS(status);
     return status == 0;
 }
@@ -88,41 +80,5 @@
     CHECK_APR_SUCCESS(apr_thread_cond_broadcast(condition));
 }
 
-#else
-// POSIX ================================================================
-
-Condition::Condition() {
-    QPID_POSIX_THROW_IF(pthread_cond_init(&condition, 0));
-}
-
-Condition::~Condition() {
-    QPID_POSIX_THROW_IF(pthread_cond_destroy(&condition));
-}
-
-void Condition::wait(Mutex& mutex) {
-    QPID_POSIX_THROW_IF(pthread_cond_wait(&condition, &mutex.mutex));
-}
-
-bool Condition::wait(Mutex& mutex, const Time& absoluteTime){
-    struct timespec ts;
-    toTimespec(ts, absoluteTime);
-    int status = pthread_cond_timedwait(&condition, &mutex.mutex, &ts);
-    if (status != 0) {
-        if (status == ETIMEDOUT) return false;
-        throw QPID_POSIX_ERROR(status);
-    }
-    return true;
-}
-
-void Condition::notify(){
-    QPID_POSIX_THROW_IF(pthread_cond_signal(&condition));
-}
-
-void Condition::notifyAll(){
-    QPID_POSIX_THROW_IF(pthread_cond_broadcast(&condition));
-}
-#endif  /*USE_APR*/
-
-
 }}
-#endif  /*!_sys_Condition_h*/
+#endif  /*!_sys_apr_Condition_h*/

Modified: incubator/qpid/trunk/qpid/cpp/src/qpid/sys/apr/LFProcessor.cpp
URL: http://svn.apache.org/viewvc/incubator/qpid/trunk/qpid/cpp/src/qpid/sys/apr/LFProcessor.cpp?view=diff&rev=540608&r1=540607&r2=540608
==============================================================================
--- incubator/qpid/trunk/qpid/cpp/src/qpid/sys/apr/LFProcessor.cpp (original)
+++ incubator/qpid/trunk/qpid/cpp/src/qpid/sys/apr/LFProcessor.cpp Tue May 22 08:18:08 2007
@@ -20,6 +20,7 @@
  */
 #include <sstream>
 #include "qpid/QpidError.h"
+#include "qpid/sys/Mutex.h"
 #include "LFProcessor.h"
 #include "APRBase.h"
 #include "LFSessionContext.h"

Modified: incubator/qpid/trunk/qpid/cpp/src/qpid/sys/apr/LFSessionContext.h
URL: http://svn.apache.org/viewvc/incubator/qpid/trunk/qpid/cpp/src/qpid/sys/apr/LFSessionContext.h?view=diff&rev=540608&r1=540607&r2=540608
==============================================================================
--- incubator/qpid/trunk/qpid/cpp/src/qpid/sys/apr/LFSessionContext.h (original)
+++ incubator/qpid/trunk/qpid/cpp/src/qpid/sys/apr/LFSessionContext.h Tue May 22 08:18:08 2007
@@ -30,6 +30,7 @@
 #include "qpid/framing/AMQFrame.h"
 #include "qpid/framing/Buffer.h"
 #include "qpid/sys/Monitor.h"
+#include "qpid/sys/Mutex.h"
 #include "qpid/sys/ConnectionOutputHandler.h"
 #include "qpid/sys/ConnectionInputHandler.h"
 

Copied: incubator/qpid/trunk/qpid/cpp/src/qpid/sys/apr/Module.h (from r537157, incubator/qpid/trunk/qpid/cpp/src/qpid/sys/Module.h)
URL: http://svn.apache.org/viewvc/incubator/qpid/trunk/qpid/cpp/src/qpid/sys/apr/Module.h?view=diff&rev=540608&p1=incubator/qpid/trunk/qpid/cpp/src/qpid/sys/Module.h&r1=537157&p2=incubator/qpid/trunk/qpid/cpp/src/qpid/sys/apr/Module.h&r2=540608
==============================================================================
--- incubator/qpid/trunk/qpid/cpp/src/qpid/sys/Module.h (original)
+++ incubator/qpid/trunk/qpid/cpp/src/qpid/sys/apr/Module.h Tue May 22 08:18:08 2007
@@ -1,5 +1,5 @@
-#ifndef _sys_Module_h
-#define _sys_Module_h
+#ifndef _sys_apr_Module_h
+#define _sys_apr_Module_h
 
 /*
  *
@@ -21,43 +21,39 @@
  * under the License.
  *
  */
+
+#include "qpid/QpidError.h"
+#include "APRBase.h"
+#include "APRPool.h"
+
 #include <boost/noncopyable.hpp>
 #include <iostream>
-#include "qpid/QpidError.h"
+#include <apr_dso.h>
 
 namespace qpid {
 namespace sys {
-#if USE_APR
-#include <apr_dso.h>
-    typedef apr_dso_handle_t* dso_handle_t;
-#else 
-    typedef void* dso_handle_t;
-#endif
-
-    template <class T> class Module : private boost::noncopyable
-    {
-        typedef T* create_t();
-        typedef void destroy_t(T*);
-        
-        dso_handle_t handle;
-        destroy_t* destroy;
-        T* ptr;
-
-        void load(const std::string& name);
-        void unload();
-        void* getSymbol(const std::string& name);
-
-    public:
-        Module(const std::string& name);
-        T* operator->(); 
-        T* get(); 
-        ~Module() throw();
-    };
 
-}
-}
+typedef apr_dso_handle_t* dso_handle_t;
 
-using namespace qpid::sys;
+template <class T> class Module : private boost::noncopyable
+{
+    typedef T* create_t();
+    typedef void destroy_t(T*);
+    
+    dso_handle_t handle;
+    destroy_t* destroy;
+    T* ptr;
+
+    void load(const std::string& name);
+    void unload();
+    void* getSymbol(const std::string& name);
+
+public:
+    Module(const std::string& name);
+    T* operator->(); 
+    T* get(); 
+    ~Module() throw();
+};
 
 template <class T> Module<T>::Module(const std::string& module) : destroy(0), ptr(0) 
 {
@@ -96,12 +92,6 @@
     ptr = 0;
 }
 
-// APR ================================================================
-#if USE_APR
-
-#include "apr/APRBase.h"
-#include "apr/APRPool.h"
-
 template <class T> void Module<T>::load(const std::string& name)
 {
     CHECK_APR_SUCCESS(apr_dso_load(&handle, name.c_str(), APRPool::get()));
@@ -119,43 +109,6 @@
     return (void*) symbol;
 }
 
-// POSIX================================================================
-#else 
-
-#include <dlfcn.h>
-
-template <class T> void Module<T>::load(const std::string& name)
-{
-    dlerror();
-    handle = dlopen(name.c_str(), RTLD_NOW);
-    const char* error = dlerror();
-    if (error) {
-        THROW_QPID_ERROR(INTERNAL_ERROR, error);
-    }
-}
-
-template <class T> void Module<T>::unload()
-{
-    dlerror();
-    dlclose(handle);
-    const char* error = dlerror();
-    if (error) {
-        THROW_QPID_ERROR(INTERNAL_ERROR, error);
-    }
-}
-
-template <class T> void* Module<T>::getSymbol(const std::string& name)
-{
-    dlerror();
-    void* sym = dlsym(handle, name.c_str());
-    const char* error = dlerror();
-    if (error) {
-        THROW_QPID_ERROR(INTERNAL_ERROR, error);
-    }
-    return sym;
-}
-
-#endif //if USE_APR
-
-#endif //ifndef _sys_Module_h
+}}
+#endif //ifndef _sys_apr_Module_h
 

Copied: incubator/qpid/trunk/qpid/cpp/src/qpid/sys/apr/Mutex.h (from r537157, incubator/qpid/trunk/qpid/cpp/src/qpid/sys/Mutex.h)
URL: http://svn.apache.org/viewvc/incubator/qpid/trunk/qpid/cpp/src/qpid/sys/apr/Mutex.h?view=diff&rev=540608&p1=incubator/qpid/trunk/qpid/cpp/src/qpid/sys/Mutex.h&r1=537157&p2=incubator/qpid/trunk/qpid/cpp/src/qpid/sys/apr/Mutex.h&r2=540608
==============================================================================
--- incubator/qpid/trunk/qpid/cpp/src/qpid/sys/Mutex.h (original)
+++ incubator/qpid/trunk/qpid/cpp/src/qpid/sys/apr/Mutex.h Tue May 22 08:18:08 2007
@@ -1,5 +1,5 @@
-#ifndef _sys_Mutex_h
-#define _sys_Mutex_h
+#ifndef _sys_apr_Mutex_h
+#define _sys_apr_Mutex_h
 
 /*
  *
@@ -19,15 +19,11 @@
  *
  */
 
-#ifdef USE_APR
-#include <apr_thread_mutex.h>
-#include "apr/APRBase.h"
-#include "apr/APRPool.h"
-#else
-#include <pthread.h>
-#include "posix/check.h"
-#endif
+#include "APRBase.h"
+#include "APRPool.h"
+
 #include <boost/noncopyable.hpp>
+#include <apr_thread_mutex.h>
 
 namespace qpid {
 namespace sys {
@@ -35,30 +31,6 @@
 class Condition;
 
 /**
- * Scoped lock template: calls lock() in ctor, unlock() in dtor.
- * L can be any class with lock() and unlock() functions.
- */
-template <class L>
-class ScopedLock
-{
-  public:
-    ScopedLock(L& l) : mutex(l) { l.lock(); }
-    ~ScopedLock() { mutex.unlock(); }
-  private:
-    L& mutex;
-};
-
-template <class L>
-class ScopedUnlock
-{
-  public:
-    ScopedUnlock(L& l) : mutex(l) { l.unlock(); }
-    ~ScopedUnlock() { mutex.lock(); }
-  private:
-    L& mutex;
-};
-    
-/**
  * Mutex lock.
  */
 class Mutex : private boost::noncopyable {
@@ -73,17 +45,10 @@
     inline void trylock();
 
   protected:
-#ifdef USE_APR
     apr_thread_mutex_t* mutex;
-#else
-    pthread_mutex_t mutex;
-#endif
   friend class Condition;
 };
 
-#ifdef USE_APR
-// APR ================================================================
-
 Mutex::Mutex() {
     CHECK_APR_SUCCESS(apr_thread_mutex_create(&mutex, APR_THREAD_MUTEX_NESTED, APRPool::get()));
 }
@@ -103,63 +68,5 @@
     CHECK_APR_SUCCESS(apr_thread_mutex_trylock(mutex));
 }
 
-#else
-// POSIX ================================================================
-
-/**
- * PODMutex is a POD, can be static-initialized with
- * PODMutex m = QPID_PODMUTEX_INITIALIZER
- */
-struct PODMutex 
-{
-    typedef ScopedLock<PODMutex> ScopedLock;
-
-    inline void lock();
-    inline void unlock();
-    inline void trylock();
-
-    // Must be public to be a POD:
-    pthread_mutex_t mutex;
-};
-
-#define QPID_MUTEX_INITIALIZER { PTHREAD_MUTEX_INITIALIZER }
-
-
-void PODMutex::lock() {
-    QPID_POSIX_THROW_IF(pthread_mutex_lock(&mutex));
-}
-void PODMutex::unlock() {
-    QPID_POSIX_THROW_IF(pthread_mutex_unlock(&mutex));
-}
-
-void PODMutex::trylock() {
-    QPID_POSIX_THROW_IF(pthread_mutex_trylock(&mutex));
-}
-
-
-Mutex::Mutex() {
-    QPID_POSIX_THROW_IF(pthread_mutex_init(&mutex, 0));
-}
-
-Mutex::~Mutex(){
-    QPID_POSIX_THROW_IF(pthread_mutex_destroy(&mutex));
-}
-
-void Mutex::lock() {
-    QPID_POSIX_THROW_IF(pthread_mutex_lock(&mutex));
-}
-void Mutex::unlock() {
-    QPID_POSIX_THROW_IF(pthread_mutex_unlock(&mutex));
-}
-
-void Mutex::trylock() {
-    QPID_POSIX_THROW_IF(pthread_mutex_trylock(&mutex));
-}
-
-#endif // USE_APR
-
 }}
-
-
-
-#endif  /*!_sys_Mutex_h*/
+#endif  /*!_sys_apr_Mutex_h*/

Modified: incubator/qpid/trunk/qpid/cpp/src/qpid/sys/apr/Socket.cpp
URL: http://svn.apache.org/viewvc/incubator/qpid/trunk/qpid/cpp/src/qpid/sys/apr/Socket.cpp?view=diff&rev=540608&r1=540607&r2=540608
==============================================================================
--- incubator/qpid/trunk/qpid/cpp/src/qpid/sys/apr/Socket.cpp (original)
+++ incubator/qpid/trunk/qpid/cpp/src/qpid/sys/apr/Socket.cpp Tue May 22 08:18:08 2007
@@ -20,7 +20,7 @@
  */
 
 
-#include "qpid/sys/Socket.h"
+#include "Socket.h"
 #include "APRBase.h"
 #include "APRPool.h"
 
@@ -40,7 +40,7 @@
     socket = s;
 }
 
-void Socket::setTimeout(Time interval) {
+void Socket::setTimeout(const Duration& interval) {
     apr_socket_timeout_set(socket, interval/TIME_USEC);
 }
 

Copied: incubator/qpid/trunk/qpid/cpp/src/qpid/sys/apr/Socket.h (from r537157, incubator/qpid/trunk/qpid/cpp/src/qpid/sys/Socket.h)
URL: http://svn.apache.org/viewvc/incubator/qpid/trunk/qpid/cpp/src/qpid/sys/apr/Socket.h?view=diff&rev=540608&p1=incubator/qpid/trunk/qpid/cpp/src/qpid/sys/Socket.h&r1=537157&p2=incubator/qpid/trunk/qpid/cpp/src/qpid/sys/apr/Socket.h&r2=540608
==============================================================================
--- incubator/qpid/trunk/qpid/cpp/src/qpid/sys/Socket.h (original)
+++ incubator/qpid/trunk/qpid/cpp/src/qpid/sys/apr/Socket.h Tue May 22 08:18:08 2007
@@ -1,5 +1,5 @@
-#ifndef _sys_Socket_h
-#define _sys_Socket_h
+#ifndef _sys_apr_Socket_h
+#define _sys_apr_Socket_h
 
 /*
  *
@@ -23,11 +23,9 @@
  */
 
 #include <string>
-#include "Time.h"
+#include "qpid/sys/Time.h"
 
-#ifdef USE_APR
 #include <apr_network_io.h>
-#endif
 
 namespace qpid {
 namespace sys {
@@ -39,14 +37,10 @@
     static Socket createTcp();
 
     /** Create a socket wrapper for descriptor. */
-#ifdef USE_APR
     Socket(apr_socket_t* descriptor = 0);
-#else
-    Socket(int descriptor = 0);
-#endif
     
     /** Set timeout for read and write */
-    void setTimeout(Time interval);
+    void setTimeout(const Duration& interval);
 
     void connect(const std::string& host, int port);
 
@@ -74,15 +68,8 @@
     int fd(); 
     
   private:
-#ifdef USE_APR    
     apr_socket_t* socket;
-#else
-    void init() const;
-    mutable int socket;         // Initialized on demand. 
-#endif
 };
 
 }}
-
-
 #endif  /*!_sys_Socket_h*/

Modified: incubator/qpid/trunk/qpid/cpp/src/qpid/sys/apr/Thread.cpp
URL: http://svn.apache.org/viewvc/incubator/qpid/trunk/qpid/cpp/src/qpid/sys/apr/Thread.cpp?view=diff&rev=540608&r1=540607&r2=540608
==============================================================================
--- incubator/qpid/trunk/qpid/cpp/src/qpid/sys/apr/Thread.cpp (original)
+++ incubator/qpid/trunk/qpid/cpp/src/qpid/sys/apr/Thread.cpp Tue May 22 08:18:08 2007
@@ -19,7 +19,8 @@
  *
  */
 
-#include "qpid/sys/Thread.h"
+#include "Thread.h"
+#include "qpid/sys/Runnable.h"
 
 using namespace qpid::sys;
 using qpid::sys::Runnable;

Copied: incubator/qpid/trunk/qpid/cpp/src/qpid/sys/apr/Thread.h (from r537157, incubator/qpid/trunk/qpid/cpp/src/qpid/sys/Thread.h)
URL: http://svn.apache.org/viewvc/incubator/qpid/trunk/qpid/cpp/src/qpid/sys/apr/Thread.h?view=diff&rev=540608&p1=incubator/qpid/trunk/qpid/cpp/src/qpid/sys/Thread.h&r1=537157&p2=incubator/qpid/trunk/qpid/cpp/src/qpid/sys/apr/Thread.h&r2=540608
==============================================================================
--- incubator/qpid/trunk/qpid/cpp/src/qpid/sys/Thread.h (original)
+++ incubator/qpid/trunk/qpid/cpp/src/qpid/sys/apr/Thread.h Tue May 22 08:18:08 2007
@@ -1,5 +1,5 @@
-#ifndef _sys_Thread_h
-#define _sys_Thread_h
+#ifndef _sys_apr_Thread_h
+#define _sys_apr_Thread_h
 
 /*
  *
@@ -22,21 +22,17 @@
  *
  */
 
-#include "Runnable.h"
+#include "APRPool.h"
+#include "APRBase.h"
 
-#ifdef USE_APR
 #include <apr_thread_proc.h>
 #include <apr_portable.h>
-#include "apr/APRPool.h"
-#include "apr/APRBase.h"
-#else
-#include "posix/check.h"
-#include <pthread.h>
-#endif
 
 namespace qpid {
 namespace sys {
 
+class Runnable;
+
 class Thread
 {
   public:
@@ -52,23 +48,13 @@
     inline long id();
         
   private:
-#ifdef USE_APR
     static void* APR_THREAD_FUNC runRunnable(apr_thread_t* thread, void *data);
     inline Thread(apr_thread_t* t);
     apr_thread_t* thread;
-#else
-    static void* runRunnable(void* runnable);
-    inline Thread(pthread_t);
-    pthread_t thread;
-#endif    
 };
 
-
 Thread::Thread() : thread(0) {}
 
-// APR ================================================================
-#ifdef USE_APR
-
 Thread::Thread(Runnable* runnable) {
     CHECK_APR_SUCCESS(
         apr_thread_create(&thread, 0, runRunnable, runnable, APRPool::get()));
@@ -103,40 +89,5 @@
     apr_thread_yield();
 }
 
-
-// POSIX ================================================================
-#else
-
-Thread::Thread(Runnable* runnable) {
-    QPID_POSIX_THROW_IF(pthread_create(&thread, NULL, runRunnable, runnable));
-}
-
-Thread::Thread(Runnable& runnable) {
-    QPID_POSIX_THROW_IF(pthread_create(&thread, NULL, runRunnable, &runnable));
-}
-
-void Thread::join(){
-    QPID_POSIX_THROW_IF(pthread_join(thread, 0));
-}
-
-long Thread::id() {
-    return long(thread);
-}
-
-Thread::Thread(pthread_t thr) : thread(thr) {}
-
-Thread Thread::current() {
-    return Thread(pthread_self());
-}
-
-void Thread::yield() 
-{
-    QPID_POSIX_THROW_IF(pthread_yield());
-}
-
-
-#endif
-
 }}
-
-#endif  /*!_sys_Thread_h*/
+#endif  /*!_sys_apr_Thread_h*/

Copied: incubator/qpid/trunk/qpid/cpp/src/qpid/sys/apr/Time.cpp (from r537157, incubator/qpid/trunk/qpid/cpp/src/qpid/sys/Time.cpp)
URL: http://svn.apache.org/viewvc/incubator/qpid/trunk/qpid/cpp/src/qpid/sys/apr/Time.cpp?view=diff&rev=540608&p1=incubator/qpid/trunk/qpid/cpp/src/qpid/sys/Time.cpp&r1=537157&p2=incubator/qpid/trunk/qpid/cpp/src/qpid/sys/apr/Time.cpp&r2=540608
==============================================================================
--- incubator/qpid/trunk/qpid/cpp/src/qpid/sys/Time.cpp (original)
+++ incubator/qpid/trunk/qpid/cpp/src/qpid/sys/apr/Time.cpp Tue May 22 08:18:08 2007
@@ -19,42 +19,18 @@
  *
  */
 
-#include "Time.h"
+#include "qpid/sys/Time.h"
+
+#include <apr_time.h>
 
 namespace qpid {
 namespace sys {
-
-// APR ================================================================
-#if USE_APR
-
-Time now() { return apr_time_now() * TIME_USEC; }
-
-// POSIX================================================================
-#else 
-
-Time now() {
-    struct timespec ts;
-    clock_gettime(CLOCK_REALTIME, &ts);
-    return toTime(ts);
-}
-
-struct timespec toTimespec(const Time& t) {
-    struct timespec ts;
-    toTimespec(ts, t);
-    return ts;
-}
-
-struct timespec& toTimespec(struct timespec& ts, const Time& t) {
-    ts.tv_sec  = t / TIME_SEC;
-    ts.tv_nsec = t % TIME_SEC;
-    return  ts;
+	
+AbsTime AbsTime::now() {
+    AbsTime time_now;
+    time_now.time_ns = apr_time_now() * TIME_USEC;
+    return time_now;
 }
 
-Time toTime(const struct timespec& ts) {
-    return ts.tv_sec*TIME_SEC + ts.tv_nsec;
-}
-
-
-#endif
 }}
 

Propchange: incubator/qpid/trunk/qpid/cpp/src/qpid/sys/posix/
------------------------------------------------------------------------------
--- svn:ignore (added)
+++ svn:ignore Tue May 22 08:18:08 2007
@@ -0,0 +1,3 @@
+.deps
+.libs
+.dirstamp

Copied: incubator/qpid/trunk/qpid/cpp/src/qpid/sys/posix/Condition.h (from r537157, incubator/qpid/trunk/qpid/cpp/src/qpid/sys/Condition.h)
URL: http://svn.apache.org/viewvc/incubator/qpid/trunk/qpid/cpp/src/qpid/sys/posix/Condition.h?view=diff&rev=540608&p1=incubator/qpid/trunk/qpid/cpp/src/qpid/sys/Condition.h&r1=537157&p2=incubator/qpid/trunk/qpid/cpp/src/qpid/sys/posix/Condition.h&r2=540608
==============================================================================
--- incubator/qpid/trunk/qpid/cpp/src/qpid/sys/Condition.h (original)
+++ incubator/qpid/trunk/qpid/cpp/src/qpid/sys/posix/Condition.h Tue May 22 08:18:08 2007
@@ -1,5 +1,5 @@
-#ifndef _sys_Condition_h
-#define _sys_Condition_h
+#ifndef _sys_posix_Condition_h
+#define _sys_posix_Condition_h
 
 /*
  *
@@ -22,14 +22,14 @@
  *
  */
 
+#include "PrivatePosix.h"
+
+#include "qpid/sys/Mutex.h"
+#include "qpid/sys/Time.h"
+
+#include <time.h>
 #include <sys/errno.h>
 #include <boost/noncopyable.hpp>
-#include "Mutex.h"
-#include "Time.h"
-
-#ifdef USE_APR
-#include <apr_thread_cond.h>
-#endif
 
 namespace qpid {
 namespace sys {
@@ -43,54 +43,14 @@
     inline Condition();
     inline ~Condition();
     inline void wait(Mutex&);
-    inline bool wait(Mutex&, const Time& absoluteTime);
+    inline bool wait(Mutex&, const AbsTime& absoluteTime);
     inline void notify();
     inline void notifyAll();
 
   private:
-#ifdef USE_APR
-    apr_thread_cond_t* condition;
-#else
     pthread_cond_t condition;
-#endif
 };
 
-
-// APR ================================================================
-#ifdef USE_APR
-
-Condition::Condition() {
-    CHECK_APR_SUCCESS(apr_thread_cond_create(&condition, APRPool::get()));
-}
-
-Condition::~Condition() {
-    CHECK_APR_SUCCESS(apr_thread_cond_destroy(condition));
-}
-
-void Condition::wait(Mutex& mutex) {
-    CHECK_APR_SUCCESS(apr_thread_cond_wait(condition, mutex.mutex));
-}
-
-bool Condition::wait(Mutex& mutex, const Time& absoluteTime){
-    // APR uses microseconds.
-    apr_status_t status =
-        apr_thread_cond_timedwait(
-            condition, mutex.mutex, absoluteTime/TIME_USEC);
-    if(status != APR_TIMEUP) CHECK_APR_SUCCESS(status);
-    return status == 0;
-}
-
-void Condition::notify(){
-    CHECK_APR_SUCCESS(apr_thread_cond_signal(condition));
-}
-
-void Condition::notifyAll(){
-    CHECK_APR_SUCCESS(apr_thread_cond_broadcast(condition));
-}
-
-#else
-// POSIX ================================================================
-
 Condition::Condition() {
     QPID_POSIX_THROW_IF(pthread_cond_init(&condition, 0));
 }
@@ -103,9 +63,9 @@
     QPID_POSIX_THROW_IF(pthread_cond_wait(&condition, &mutex.mutex));
 }
 
-bool Condition::wait(Mutex& mutex, const Time& absoluteTime){
+bool Condition::wait(Mutex& mutex, const AbsTime& absoluteTime){
     struct timespec ts;
-    toTimespec(ts, absoluteTime);
+    toTimespec(ts, Duration(absoluteTime));
     int status = pthread_cond_timedwait(&condition, &mutex.mutex, &ts);
     if (status != 0) {
         if (status == ETIMEDOUT) return false;
@@ -121,8 +81,6 @@
 void Condition::notifyAll(){
     QPID_POSIX_THROW_IF(pthread_cond_broadcast(&condition));
 }
-#endif  /*USE_APR*/
-
 
 }}
-#endif  /*!_sys_Condition_h*/
+#endif  /*!_sys_posix_Condition_h*/

Modified: incubator/qpid/trunk/qpid/cpp/src/qpid/sys/posix/EventChannelAcceptor.cpp
URL: http://svn.apache.org/viewvc/incubator/qpid/trunk/qpid/cpp/src/qpid/sys/posix/EventChannelAcceptor.cpp?view=diff&rev=540608&r1=540607&r2=540608
==============================================================================
--- incubator/qpid/trunk/qpid/cpp/src/qpid/sys/posix/EventChannelAcceptor.cpp (original)
+++ incubator/qpid/trunk/qpid/cpp/src/qpid/sys/posix/EventChannelAcceptor.cpp Tue May 22 08:18:08 2007
@@ -51,9 +51,9 @@
         int16_t port_, int backlog, int nThreads, bool trace_
     );
         
-    int getPort() const;
+    uint16_t getPort() const;
     
-    void run(ConnectionInputHandlerFactory& factory);
+    void run(ConnectionInputHandlerFactory* factory);
 
     void shutdown();
 
@@ -96,17 +96,17 @@
     threads(EventChannelThreads::create(EventChannel::create(), nThreads))
 { }
     
-int EventChannelAcceptor::getPort() const {
+uint16_t EventChannelAcceptor::getPort() const {
     return port;                // Immutable no need for lock.
 }
     
-void EventChannelAcceptor::run(ConnectionInputHandlerFactory& f) {
+void EventChannelAcceptor::run(ConnectionInputHandlerFactory* f) {
     {
         Mutex::ScopedLock l(lock);
         if (!isRunning && !isShutdown) {
             isRunning = true;
-            factory = &f;
-            threads->post(acceptEvent);
+            factory = f;
+            threads->postEvent(acceptEvent);
         }
     }
     threads->join();            // Wait for shutdown.
@@ -143,7 +143,7 @@
     int fd = acceptEvent.getAcceptedDesscriptor();
     connections.push_back(
         new EventChannelConnection(threads, *factory, fd, fd, isTrace));
-    threads->post(acceptEvent); // Keep accepting.
+    threads->postEvent(acceptEvent); // Keep accepting.
 }
 
 }} // namespace qpid::sys

Modified: incubator/qpid/trunk/qpid/cpp/src/qpid/sys/posix/EventChannelConnection.cpp
URL: http://svn.apache.org/viewvc/incubator/qpid/trunk/qpid/cpp/src/qpid/sys/posix/EventChannelConnection.cpp?view=diff&rev=540608&r1=540607&r2=540608
==============================================================================
--- incubator/qpid/trunk/qpid/cpp/src/qpid/sys/posix/EventChannelConnection.cpp (original)
+++ incubator/qpid/trunk/qpid/cpp/src/qpid/sys/posix/EventChannelConnection.cpp Tue May 22 08:18:08 2007
@@ -140,7 +140,7 @@
         writeFd, out.start(), out.available(),
         boost::bind(&EventChannelConnection::closeOnException,
                     this, &EventChannelConnection::endWrite));
-    threads->post(writeEvent);
+    threads->postEvent(writeEvent);
 }
 
 // ScopedBusy ctor increments busyThreads.
@@ -180,7 +180,7 @@
     // Non blocking read, as much as we can swallow.
     readEvent = ReadEvent(
         readFd, in.start(), in.available(), readCallback,true);
-    threads->post(readEvent);
+    threads->postEvent(readEvent);
 }
 
 // Completion of initial read, expect protocolInit.

Copied: incubator/qpid/trunk/qpid/cpp/src/qpid/sys/posix/Module.h (from r537157, incubator/qpid/trunk/qpid/cpp/src/qpid/sys/Module.h)
URL: http://svn.apache.org/viewvc/incubator/qpid/trunk/qpid/cpp/src/qpid/sys/posix/Module.h?view=diff&rev=540608&p1=incubator/qpid/trunk/qpid/cpp/src/qpid/sys/Module.h&r1=537157&p2=incubator/qpid/trunk/qpid/cpp/src/qpid/sys/posix/Module.h&r2=540608
==============================================================================
--- incubator/qpid/trunk/qpid/cpp/src/qpid/sys/Module.h (original)
+++ incubator/qpid/trunk/qpid/cpp/src/qpid/sys/posix/Module.h Tue May 22 08:18:08 2007
@@ -1,5 +1,5 @@
-#ifndef _sys_Module_h
-#define _sys_Module_h
+#ifndef _sys_posix_Module_h
+#define _sys_posix_Module_h
 
 /*
  *
@@ -21,43 +21,37 @@
  * under the License.
  *
  */
+ 
+#include "qpid/QpidError.h"
+
 #include <boost/noncopyable.hpp>
 #include <iostream>
-#include "qpid/QpidError.h"
+#include <dlfcn.h>
 
 namespace qpid {
 namespace sys {
-#if USE_APR
-#include <apr_dso.h>
-    typedef apr_dso_handle_t* dso_handle_t;
-#else 
-    typedef void* dso_handle_t;
-#endif
-
-    template <class T> class Module : private boost::noncopyable
-    {
-        typedef T* create_t();
-        typedef void destroy_t(T*);
-        
-        dso_handle_t handle;
-        destroy_t* destroy;
-        T* ptr;
-
-        void load(const std::string& name);
-        void unload();
-        void* getSymbol(const std::string& name);
-
-    public:
-        Module(const std::string& name);
-        T* operator->(); 
-        T* get(); 
-        ~Module() throw();
-    };
 
-}
-}
+typedef void* dso_handle_t;
 
-using namespace qpid::sys;
+template <class T> class Module : private boost::noncopyable
+{
+    typedef T* create_t();
+    typedef void destroy_t(T*);
+    
+    dso_handle_t handle;
+    destroy_t* destroy;
+    T* ptr;
+
+    void load(const std::string& name);
+    void unload();
+    void* getSymbol(const std::string& name);
+
+public:
+    Module(const std::string& name);
+    T* operator->(); 
+    T* get(); 
+    ~Module() throw();
+};
 
 template <class T> Module<T>::Module(const std::string& module) : destroy(0), ptr(0) 
 {
@@ -96,34 +90,6 @@
     ptr = 0;
 }
 
-// APR ================================================================
-#if USE_APR
-
-#include "apr/APRBase.h"
-#include "apr/APRPool.h"
-
-template <class T> void Module<T>::load(const std::string& name)
-{
-    CHECK_APR_SUCCESS(apr_dso_load(&handle, name.c_str(), APRPool::get()));
-}
-
-template <class T> void Module<T>::unload()
-{
-    CHECK_APR_SUCCESS(apr_dso_unload(handle));
-}
-
-template <class T> void* Module<T>::getSymbol(const std::string& name)
-{
-    apr_dso_handle_sym_t symbol;
-    CHECK_APR_SUCCESS(apr_dso_sym(&symbol, handle, name.c_str()));
-    return (void*) symbol;
-}
-
-// POSIX================================================================
-#else 
-
-#include <dlfcn.h>
-
 template <class T> void Module<T>::load(const std::string& name)
 {
     dlerror();
@@ -155,7 +121,6 @@
     return sym;
 }
 
-#endif //if USE_APR
-
-#endif //ifndef _sys_Module_h
+}}
+#endif //ifndef _sys_posix_Module_h
 

Copied: incubator/qpid/trunk/qpid/cpp/src/qpid/sys/posix/Mutex.h (from r537157, incubator/qpid/trunk/qpid/cpp/src/qpid/sys/Mutex.h)
URL: http://svn.apache.org/viewvc/incubator/qpid/trunk/qpid/cpp/src/qpid/sys/posix/Mutex.h?view=diff&rev=540608&p1=incubator/qpid/trunk/qpid/cpp/src/qpid/sys/Mutex.h&r1=537157&p2=incubator/qpid/trunk/qpid/cpp/src/qpid/sys/posix/Mutex.h&r2=540608
==============================================================================
--- incubator/qpid/trunk/qpid/cpp/src/qpid/sys/Mutex.h (original)
+++ incubator/qpid/trunk/qpid/cpp/src/qpid/sys/posix/Mutex.h Tue May 22 08:18:08 2007
@@ -1,5 +1,5 @@
-#ifndef _sys_Mutex_h
-#define _sys_Mutex_h
+#ifndef _sys_posix_Mutex_h
+#define _sys_posix_Mutex_h
 
 /*
  *
@@ -19,14 +19,9 @@
  *
  */
 
-#ifdef USE_APR
-#include <apr_thread_mutex.h>
-#include "apr/APRBase.h"
-#include "apr/APRPool.h"
-#else
+#include "check.h"
+
 #include <pthread.h>
-#include "posix/check.h"
-#endif
 #include <boost/noncopyable.hpp>
 
 namespace qpid {
@@ -35,34 +30,12 @@
 class Condition;
 
 /**
- * Scoped lock template: calls lock() in ctor, unlock() in dtor.
- * L can be any class with lock() and unlock() functions.
- */
-template <class L>
-class ScopedLock
-{
-  public:
-    ScopedLock(L& l) : mutex(l) { l.lock(); }
-    ~ScopedLock() { mutex.unlock(); }
-  private:
-    L& mutex;
-};
-
-template <class L>
-class ScopedUnlock
-{
-  public:
-    ScopedUnlock(L& l) : mutex(l) { l.unlock(); }
-    ~ScopedUnlock() { mutex.lock(); }
-  private:
-    L& mutex;
-};
-    
-/**
  * Mutex lock.
  */
 class Mutex : private boost::noncopyable {
-  public:
+    friend class Condition;
+
+public:
     typedef ScopedLock<Mutex> ScopedLock;
     typedef ScopedUnlock<Mutex> ScopedUnlock;
     
@@ -72,40 +45,36 @@
     inline void unlock();
     inline void trylock();
 
-  protected:
-#ifdef USE_APR
-    apr_thread_mutex_t* mutex;
-#else
+protected:
     pthread_mutex_t mutex;
-#endif
-  friend class Condition;
 };
 
-#ifdef USE_APR
-// APR ================================================================
-
-Mutex::Mutex() {
-    CHECK_APR_SUCCESS(apr_thread_mutex_create(&mutex, APR_THREAD_MUTEX_NESTED, APRPool::get()));
-}
-
-Mutex::~Mutex(){
-    CHECK_APR_SUCCESS(apr_thread_mutex_destroy(mutex));
-}
-
-void Mutex::lock() {
-    CHECK_APR_SUCCESS(apr_thread_mutex_lock(mutex));
-}
-void Mutex::unlock() {
-    CHECK_APR_SUCCESS(apr_thread_mutex_unlock(mutex));
-}
-
-void Mutex::trylock() {
-    CHECK_APR_SUCCESS(apr_thread_mutex_trylock(mutex));
+/**
+ * Initialise a recursive mutex attr for use in creating mutexes later
+ * (we use pthread_once to make sure it is initialised exactly once)
+ */
+namespace {
+	pthread_once_t  onceControl = PTHREAD_ONCE_INIT;
+	pthread_mutexattr_t mutexattr;
+	
+	void initMutexattr()  {
+		pthread_mutexattr_init(&mutexattr);
+		pthread_mutexattr_settype(&mutexattr, PTHREAD_MUTEX_RECURSIVE);
+	}
+	
+	struct RecursiveMutexattr {
+		RecursiveMutexattr() {
+			pthread_once(&onceControl, initMutexattr);
+		}
+		
+		operator const pthread_mutexattr_t*() const {
+			return &mutexattr;
+		}
+	};
+	
+	RecursiveMutexattr recursiveMutexattr;
 }
 
-#else
-// POSIX ================================================================
-
 /**
  * PODMutex is a POD, can be static-initialized with
  * PODMutex m = QPID_PODMUTEX_INITIALIZER
@@ -124,7 +93,6 @@
 
 #define QPID_MUTEX_INITIALIZER { PTHREAD_MUTEX_INITIALIZER }
 
-
 void PODMutex::lock() {
     QPID_POSIX_THROW_IF(pthread_mutex_lock(&mutex));
 }
@@ -136,9 +104,8 @@
     QPID_POSIX_THROW_IF(pthread_mutex_trylock(&mutex));
 }
 
-
 Mutex::Mutex() {
-    QPID_POSIX_THROW_IF(pthread_mutex_init(&mutex, 0));
+    QPID_POSIX_THROW_IF(pthread_mutex_init(&mutex, recursiveMutexattr));
 }
 
 Mutex::~Mutex(){
@@ -156,10 +123,5 @@
     QPID_POSIX_THROW_IF(pthread_mutex_trylock(&mutex));
 }
 
-#endif // USE_APR
-
 }}
-
-
-
-#endif  /*!_sys_Mutex_h*/
+#endif  /*!_sys_posix_Mutex_h*/

Added: incubator/qpid/trunk/qpid/cpp/src/qpid/sys/posix/PrivatePosix.h
URL: http://svn.apache.org/viewvc/incubator/qpid/trunk/qpid/cpp/src/qpid/sys/posix/PrivatePosix.h?view=auto&rev=540608
==============================================================================
--- incubator/qpid/trunk/qpid/cpp/src/qpid/sys/posix/PrivatePosix.h (added)
+++ incubator/qpid/trunk/qpid/cpp/src/qpid/sys/posix/PrivatePosix.h Tue May 22 08:18:08 2007
@@ -0,0 +1,39 @@
+#ifndef _sys_posix_PrivatePosix_h
+#define _sys_posix_PrivatePosix_h
+
+/*
+ *
+ * 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 "qpid/sys/Time.h"
+
+struct timespec;
+struct timeval;
+
+namespace qpid {
+namespace sys {
+
+struct timespec& toTimespec(struct timespec& ts, const Duration& t);
+struct timeval& toTimeval(struct timeval& tv, const Duration& t);
+Duration toTime(const struct timespec& ts);
+
+}}
+
+#endif  /*!_sys_posix_PrivatePosix_h*/

Modified: incubator/qpid/trunk/qpid/cpp/src/qpid/sys/posix/Socket.cpp
URL: http://svn.apache.org/viewvc/incubator/qpid/trunk/qpid/cpp/src/qpid/sys/posix/Socket.cpp?view=diff&rev=540608&r1=540607&r2=540608
==============================================================================
--- incubator/qpid/trunk/qpid/cpp/src/qpid/sys/posix/Socket.cpp (original)
+++ incubator/qpid/trunk/qpid/cpp/src/qpid/sys/posix/Socket.cpp Tue May 22 08:18:08 2007
@@ -19,6 +19,12 @@
  *
  */
 
+#include "qpid/sys/Socket.h"
+
+#include "qpid/QpidError.h"
+#include "check.h"
+#include "PrivatePosix.h"
+
 #include <sys/socket.h>
 #include <sys/errno.h>
 #include <netinet/in.h>
@@ -26,10 +32,6 @@
 
 #include <boost/format.hpp>
 
-#include "qpid/QpidError.h"
-#include "check.h"
-#include "qpid/sys/Socket.h"
-
 using namespace qpid::sys;
 
 Socket Socket::createTcp() 
@@ -41,11 +43,10 @@
 
 Socket::Socket(int descriptor) : socket(descriptor) {}
 
-void Socket::setTimeout(Time interval)
+void Socket::setTimeout(const Duration& interval)
 {
     struct timeval tv;
-    tv.tv_sec = interval/TIME_SEC;
-    tv.tv_usec = (interval%TIME_SEC)/TIME_USEC;
+    toTimeval(tv, interval);
     setsockopt(socket, SOL_SOCKET, SO_SNDTIMEO, &tv, sizeof(tv));
     setsockopt(socket, SOL_SOCKET, SO_RCVTIMEO, &tv, sizeof(tv));
 }

Copied: incubator/qpid/trunk/qpid/cpp/src/qpid/sys/posix/Socket.h (from r537157, incubator/qpid/trunk/qpid/cpp/src/qpid/sys/Socket.h)
URL: http://svn.apache.org/viewvc/incubator/qpid/trunk/qpid/cpp/src/qpid/sys/posix/Socket.h?view=diff&rev=540608&p1=incubator/qpid/trunk/qpid/cpp/src/qpid/sys/Socket.h&r1=537157&p2=incubator/qpid/trunk/qpid/cpp/src/qpid/sys/posix/Socket.h&r2=540608
==============================================================================
--- incubator/qpid/trunk/qpid/cpp/src/qpid/sys/Socket.h (original)
+++ incubator/qpid/trunk/qpid/cpp/src/qpid/sys/posix/Socket.h Tue May 22 08:18:08 2007
@@ -1,5 +1,5 @@
-#ifndef _sys_Socket_h
-#define _sys_Socket_h
+#ifndef _sys_posix_Socket_h
+#define _sys_posix_Socket_h
 
 /*
  *
@@ -23,11 +23,7 @@
  */
 
 #include <string>
-#include "Time.h"
-
-#ifdef USE_APR
-#include <apr_network_io.h>
-#endif
+#include "qpid/sys/Time.h"
 
 namespace qpid {
 namespace sys {
@@ -39,14 +35,10 @@
     static Socket createTcp();
 
     /** Create a socket wrapper for descriptor. */
-#ifdef USE_APR
-    Socket(apr_socket_t* descriptor = 0);
-#else
     Socket(int descriptor = 0);
-#endif
     
     /** Set timeout for read and write */
-    void setTimeout(Time interval);
+    void setTimeout(const Duration& interval);
 
     void connect(const std::string& host, int port);
 
@@ -74,12 +66,8 @@
     int fd(); 
     
   private:
-#ifdef USE_APR    
-    apr_socket_t* socket;
-#else
     void init() const;
     mutable int socket;         // Initialized on demand. 
-#endif
 };
 
 }}

Modified: incubator/qpid/trunk/qpid/cpp/src/qpid/sys/posix/Thread.cpp
URL: http://svn.apache.org/viewvc/incubator/qpid/trunk/qpid/cpp/src/qpid/sys/posix/Thread.cpp?view=diff&rev=540608&r1=540607&r2=540608
==============================================================================
--- incubator/qpid/trunk/qpid/cpp/src/qpid/sys/posix/Thread.cpp (original)
+++ incubator/qpid/trunk/qpid/cpp/src/qpid/sys/posix/Thread.cpp Tue May 22 08:18:08 2007
@@ -19,7 +19,8 @@
  *
  */
 
-#include "qpid/sys/Thread.h"
+#include "Thread.h"
+#include "qpid/sys/Runnable.h"
 
 void* qpid::sys::Thread::runRunnable(void* p)
 {

Copied: incubator/qpid/trunk/qpid/cpp/src/qpid/sys/posix/Thread.h (from r537157, incubator/qpid/trunk/qpid/cpp/src/qpid/sys/Thread.h)
URL: http://svn.apache.org/viewvc/incubator/qpid/trunk/qpid/cpp/src/qpid/sys/posix/Thread.h?view=diff&rev=540608&p1=incubator/qpid/trunk/qpid/cpp/src/qpid/sys/Thread.h&r1=537157&p2=incubator/qpid/trunk/qpid/cpp/src/qpid/sys/posix/Thread.h&r2=540608
==============================================================================
--- incubator/qpid/trunk/qpid/cpp/src/qpid/sys/Thread.h (original)
+++ incubator/qpid/trunk/qpid/cpp/src/qpid/sys/posix/Thread.h Tue May 22 08:18:08 2007
@@ -1,5 +1,5 @@
-#ifndef _sys_Thread_h
-#define _sys_Thread_h
+#ifndef _sys_posix_Thread_h
+#define _sys_posix_Thread_h
 
 /*
  *
@@ -22,21 +22,14 @@
  *
  */
 
-#include "Runnable.h"
-
-#ifdef USE_APR
-#include <apr_thread_proc.h>
-#include <apr_portable.h>
-#include "apr/APRPool.h"
-#include "apr/APRBase.h"
-#else
-#include "posix/check.h"
+#include "check.h"
 #include <pthread.h>
-#endif
 
 namespace qpid {
 namespace sys {
 
+class Runnable;
+
 class Thread
 {
   public:
@@ -52,61 +45,14 @@
     inline long id();
         
   private:
-#ifdef USE_APR
-    static void* APR_THREAD_FUNC runRunnable(apr_thread_t* thread, void *data);
-    inline Thread(apr_thread_t* t);
-    apr_thread_t* thread;
-#else
     static void* runRunnable(void* runnable);
     inline Thread(pthread_t);
     pthread_t thread;
-#endif    
 };
 
 
 Thread::Thread() : thread(0) {}
 
-// APR ================================================================
-#ifdef USE_APR
-
-Thread::Thread(Runnable* runnable) {
-    CHECK_APR_SUCCESS(
-        apr_thread_create(&thread, 0, runRunnable, runnable, APRPool::get()));
-}
-
-Thread::Thread(Runnable& runnable) {
-    CHECK_APR_SUCCESS(
-        apr_thread_create(&thread, 0, runRunnable, &runnable, APRPool::get()));
-}
-
-void Thread::join(){
-    apr_status_t status;
-    if (thread != 0) 
-        CHECK_APR_SUCCESS(apr_thread_join(&status, thread));
-}
-
-long Thread::id() {
-    return long(thread);
-}
-
-Thread::Thread(apr_thread_t* t) : thread(t) {}
-
-Thread Thread::current(){
-    apr_thread_t* thr;
-    apr_os_thread_t osthr = apr_os_thread_current();
-    CHECK_APR_SUCCESS(apr_os_thread_put(&thr, &osthr, APRPool::get()));
-    return Thread(thr);
-}
-
-void Thread::yield() 
-{
-    apr_thread_yield();
-}
-
-
-// POSIX ================================================================
-#else
-
 Thread::Thread(Runnable* runnable) {
     QPID_POSIX_THROW_IF(pthread_create(&thread, NULL, runRunnable, runnable));
 }
@@ -116,7 +62,8 @@
 }
 
 void Thread::join(){
-    QPID_POSIX_THROW_IF(pthread_join(thread, 0));
+    if (thread != 0)
+        QPID_POSIX_THROW_IF(pthread_join(thread, 0));
 }
 
 long Thread::id() {
@@ -135,8 +82,5 @@
 }
 
 
-#endif
-
 }}
-
-#endif  /*!_sys_Thread_h*/
+#endif  /*!_sys_posix_Thread_h*/

Copied: incubator/qpid/trunk/qpid/cpp/src/qpid/sys/posix/Time.cpp (from r537157, incubator/qpid/trunk/qpid/cpp/src/qpid/sys/Time.cpp)
URL: http://svn.apache.org/viewvc/incubator/qpid/trunk/qpid/cpp/src/qpid/sys/posix/Time.cpp?view=diff&rev=540608&p1=incubator/qpid/trunk/qpid/cpp/src/qpid/sys/Time.cpp&r1=537157&p2=incubator/qpid/trunk/qpid/cpp/src/qpid/sys/posix/Time.cpp&r2=540608
==============================================================================
--- incubator/qpid/trunk/qpid/cpp/src/qpid/sys/Time.cpp (original)
+++ incubator/qpid/trunk/qpid/cpp/src/qpid/sys/posix/Time.cpp Tue May 22 08:18:08 2007
@@ -19,42 +19,39 @@
  *
  */
 
-#include "Time.h"
+#include "PrivatePosix.h"
 
-namespace qpid {
-namespace sys {
-
-// APR ================================================================
-#if USE_APR
+#include "qpid/sys/Time.h"
 
-Time now() { return apr_time_now() * TIME_USEC; }
+#include <time.h>
+#include <sys/time.h>
 
-// POSIX================================================================
-#else 
+namespace qpid {
+namespace sys {
 
-Time now() {
+AbsTime AbsTime::now() {
     struct timespec ts;
     clock_gettime(CLOCK_REALTIME, &ts);
-    return toTime(ts);
+    AbsTime time_now;
+    time_now.time_ns = toTime(ts).nanosecs;
+    return time_now;
 }
 
-struct timespec toTimespec(const Time& t) {
-    struct timespec ts;
-    toTimespec(ts, t);
+struct timespec& toTimespec(struct timespec& ts, const Duration& t) {
+    ts.tv_sec  = t / TIME_SEC;
+    ts.tv_nsec = t % TIME_SEC;
     return ts;
 }
 
-struct timespec& toTimespec(struct timespec& ts, const Time& t) {
-    ts.tv_sec  = t / TIME_SEC;
-    ts.tv_nsec = t % TIME_SEC;
-    return  ts;
+struct timeval& toTimeval(struct timeval& tv, const Duration& t) {
+    tv.tv_sec = t/TIME_SEC;
+    tv.tv_usec = (t%TIME_SEC)/TIME_USEC;
+    return tv;
 }
 
-Time toTime(const struct timespec& ts) {
+Duration toTime(const struct timespec& ts) {
     return ts.tv_sec*TIME_SEC + ts.tv_nsec;
 }
 
-
-#endif
 }}
 

Modified: incubator/qpid/trunk/qpid/cpp/src/tests/Makefile.am
URL: http://svn.apache.org/viewvc/incubator/qpid/trunk/qpid/cpp/src/tests/Makefile.am?view=diff&rev=540608&r1=540607&r2=540608
==============================================================================
--- incubator/qpid/trunk/qpid/cpp/src/tests/Makefile.am (original)
+++ incubator/qpid/trunk/qpid/cpp/src/tests/Makefile.am Tue May 22 08:18:08 2007
@@ -1,5 +1,5 @@
 AM_CXXFLAGS = $(WARNING_CFLAGS) $(CPPUNIT_CXXFLAGS)   $(APR_CXXFLAGS)
-INCLUDES =  -I$(srcdir)/.. -I$(srcdir)/../gen -I$(builddir)/../gen
+INCLUDES =  -I$(srcdir)/.. -I$(srcdir)/../gen -I$(top_builddir)/src/gen
 
 # Unit tests
 broker_unit_tests =	\

Modified: incubator/qpid/trunk/qpid/cpp/src/tests/ProducerConsumerTest.cpp
URL: http://svn.apache.org/viewvc/incubator/qpid/trunk/qpid/cpp/src/tests/ProducerConsumerTest.cpp?view=diff&rev=540608&r1=540607&r2=540608
==============================================================================
--- incubator/qpid/trunk/qpid/cpp/src/tests/ProducerConsumerTest.cpp (original)
+++ incubator/qpid/trunk/qpid/cpp/src/tests/ProducerConsumerTest.cpp Tue May 22 08:18:08 2007
@@ -74,9 +74,9 @@
         return count;
     }
 
-    bool waitFor(int i, Time timeout=TIME_SEC) {
+    bool waitFor(int i, Duration timeout=TIME_SEC) {
         Lock l(*this);
-        Time deadline = timeout+now();
+        AbsTime deadline(now(), timeout);
         while (count != i) {
             if (!wait(deadline))
                 return false;
@@ -116,8 +116,8 @@
 
     struct ConsumeTimeoutRunnable : public Runnable {
         ProducerConsumerTest& test;
-        Time timeout;
-        ConsumeTimeoutRunnable(ProducerConsumerTest& test_, const Time& t)
+        Duration timeout;
+        ConsumeTimeoutRunnable(ProducerConsumerTest& test_, const Duration& t)
             : test(test_), timeout(t) {}
         void run() { test.consumeTimeout(timeout); }
     };
@@ -143,7 +143,7 @@
         consumeInternal(consumer);
     };
 
-    void consumeTimeout(const Time& timeout) {
+    void consumeTimeout(const Duration& timeout) {
         ProducerConsumer::ConsumerLock consumer(pc, timeout);
         consumeInternal(consumer);
     };

Modified: incubator/qpid/trunk/qpid/cpp/src/tests/topic_listener.cpp
URL: http://svn.apache.org/viewvc/incubator/qpid/trunk/qpid/cpp/src/tests/topic_listener.cpp?view=diff&rev=540608&r1=540607&r2=540608
==============================================================================
--- incubator/qpid/trunk/qpid/cpp/src/tests/topic_listener.cpp (original)
+++ incubator/qpid/trunk/qpid/cpp/src/tests/topic_listener.cpp Tue May 22 08:18:08 2007
@@ -56,7 +56,7 @@
     const bool transactional;
     bool init;
     int count;
-    Time start;
+    AbsTime start;
     
     void shutdown();
     void report();
@@ -159,8 +159,8 @@
 }
 
 void Listener::report(){
-    Time finish = now();
-    Time time = finish - start;
+    AbsTime finish = now();
+    Duration time(start, finish);
     stringstream reportstr;
     reportstr << "Received " << count << " messages in "
               << time/TIME_MSEC << " ms.";

Modified: incubator/qpid/trunk/qpid/cpp/src/tests/topic_publisher.cpp
URL: http://svn.apache.org/viewvc/incubator/qpid/trunk/qpid/cpp/src/tests/topic_publisher.cpp?view=diff&rev=540608&r1=540607&r2=540608
==============================================================================
--- incubator/qpid/trunk/qpid/cpp/src/tests/topic_publisher.cpp (original)
+++ incubator/qpid/trunk/qpid/cpp/src/tests/topic_publisher.cpp Tue May 22 08:18:08 2007
@@ -183,7 +183,7 @@
 int64_t Publisher::publish(int msgs, int listeners, int size){
     Message msg;
     msg.setData(generateData(size));
-    Time start = now();
+    AbsTime start = now();
     {
         Monitor::ScopedLock l(monitor);
         for(int i = 0; i < msgs; i++){
@@ -201,8 +201,8 @@
         waitForCompletion(listeners);
     }
 
-    Time finish = now();
-    return finish - start; 
+    AbsTime finish = now();
+    return Duration(start, finish); 
 }
 
 string Publisher::generateData(int size){