tuscany-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jsdelf...@apache.org
Subject svn commit: r895165 [1/4] - in /tuscany/sca-cpp/trunk: ./ components/cache/ etc/ kernel/ modules/ modules/atom/ modules/eval/ modules/http/ modules/json/ modules/scdl/ modules/server/ test/store-script/
Date Sat, 02 Jan 2010 10:27:29 GMT
Author: jsdelfino
Date: Sat Jan  2 10:27:26 2010
New Revision: 895165

URL: http://svn.apache.org/viewvc?rev=895165&view=rev
Log:
Performance improvements when running both in multi-threaded and pre-forked HTTPD. Changed memory management to use Apache APR pools instead of ref counting pointers as it's much faster and easier to integrate with the Python and Ruby interpreters. Changed to use simple pool-based string and stream implementations instead of the STL ones, which cause a lots of mutex locks in a multi-threaded environment. Added build options to compile with threading and profiling.

Added:
    tuscany/sca-cpp/trunk/kernel/fstream.hpp
    tuscany/sca-cpp/trunk/kernel/mem-test.cpp
    tuscany/sca-cpp/trunk/kernel/sstream.hpp
    tuscany/sca-cpp/trunk/kernel/stream.hpp
    tuscany/sca-cpp/trunk/kernel/string-test.cpp
    tuscany/sca-cpp/trunk/kernel/string.hpp
Removed:
    tuscany/sca-cpp/trunk/kernel/slist.hpp
Modified:
    tuscany/sca-cpp/trunk/components/cache/mcache-client-test.cpp
    tuscany/sca-cpp/trunk/components/cache/mcache-test.cpp
    tuscany/sca-cpp/trunk/components/cache/mcache.cpp
    tuscany/sca-cpp/trunk/components/cache/mcache.hpp
    tuscany/sca-cpp/trunk/components/cache/memcached-server-test
    tuscany/sca-cpp/trunk/components/cache/memcached-test
    tuscany/sca-cpp/trunk/configure.ac
    tuscany/sca-cpp/trunk/etc/git-exclude
    tuscany/sca-cpp/trunk/kernel/Makefile.am
    tuscany/sca-cpp/trunk/kernel/debug.hpp
    tuscany/sca-cpp/trunk/kernel/dynlib.hpp
    tuscany/sca-cpp/trunk/kernel/element.hpp
    tuscany/sca-cpp/trunk/kernel/function.hpp
    tuscany/sca-cpp/trunk/kernel/gc.hpp
    tuscany/sca-cpp/trunk/kernel/kernel-test.cpp
    tuscany/sca-cpp/trunk/kernel/list.hpp
    tuscany/sca-cpp/trunk/kernel/monad.hpp
    tuscany/sca-cpp/trunk/kernel/parallel-test.cpp
    tuscany/sca-cpp/trunk/kernel/parallel.hpp
    tuscany/sca-cpp/trunk/kernel/tree.hpp
    tuscany/sca-cpp/trunk/kernel/value.hpp
    tuscany/sca-cpp/trunk/kernel/xml-test.cpp
    tuscany/sca-cpp/trunk/kernel/xml.hpp
    tuscany/sca-cpp/trunk/kernel/xsd-test.cpp
    tuscany/sca-cpp/trunk/modules/Makefile.am
    tuscany/sca-cpp/trunk/modules/atom/atom-test.cpp
    tuscany/sca-cpp/trunk/modules/atom/atom.hpp
    tuscany/sca-cpp/trunk/modules/eval/driver.hpp
    tuscany/sca-cpp/trunk/modules/eval/environment.hpp
    tuscany/sca-cpp/trunk/modules/eval/eval-shell.cpp
    tuscany/sca-cpp/trunk/modules/eval/eval-test.cpp
    tuscany/sca-cpp/trunk/modules/eval/eval.hpp
    tuscany/sca-cpp/trunk/modules/eval/io.hpp
    tuscany/sca-cpp/trunk/modules/eval/primitive.hpp
    tuscany/sca-cpp/trunk/modules/http/curl-test.cpp
    tuscany/sca-cpp/trunk/modules/http/curl.hpp
    tuscany/sca-cpp/trunk/modules/http/httpd.hpp
    tuscany/sca-cpp/trunk/modules/json/json-test.cpp
    tuscany/sca-cpp/trunk/modules/json/json.hpp
    tuscany/sca-cpp/trunk/modules/scdl/scdl-test.cpp
    tuscany/sca-cpp/trunk/modules/scdl/scdl.hpp
    tuscany/sca-cpp/trunk/modules/server/client-test.cpp
    tuscany/sca-cpp/trunk/modules/server/impl-test.cpp
    tuscany/sca-cpp/trunk/modules/server/mod-cpp.hpp
    tuscany/sca-cpp/trunk/modules/server/mod-eval.cpp
    tuscany/sca-cpp/trunk/modules/server/mod-scm.hpp
    tuscany/sca-cpp/trunk/modules/server/mod-wiring.cpp
    tuscany/sca-cpp/trunk/test/store-script/store-script-test.cpp

Modified: tuscany/sca-cpp/trunk/components/cache/mcache-client-test.cpp
URL: http://svn.apache.org/viewvc/tuscany/sca-cpp/trunk/components/cache/mcache-client-test.cpp?rev=895165&r1=895164&r2=895165&view=diff
==============================================================================
--- tuscany/sca-cpp/trunk/components/cache/mcache-client-test.cpp (original)
+++ tuscany/sca-cpp/trunk/components/cache/mcache-client-test.cpp Sat Jan  2 10:27:26 2010
@@ -24,8 +24,8 @@
  */
 
 #include <assert.h>
-#include <iostream>
-#include <string>
+#include "stream.hpp"
+#include "string.hpp"
 
 #include "list.hpp"
 #include "value.hpp"
@@ -36,46 +36,46 @@
 namespace tuscany {
 namespace cache {
 
-const std::string url("http://localhost:8090/mcache");
+const string url("http://localhost:8090/mcache");
 
 bool testCache() {
     http::CURLSession cs;
 
     const list<value> i = list<value>()
-            << (list<value>() << "name" << std::string("Apple"))
-            << (list<value>() << "price" << std::string("$2.99"));
-    const list<value> a = mklist<value>(std::string("item"), std::string("cart-53d67a61-aa5e-4e5e-8401-39edeba8b83b"), i);
+            + (list<value>() + "name" + string("Apple"))
+            + (list<value>() + "price" + string("$2.99"));
+    const list<value> a = mklist<value>(string("item"), string("cart-53d67a61-aa5e-4e5e-8401-39edeba8b83b"), i);
 
-    const failable<value, std::string> id = http::post(a, url, cs);
+    const failable<value> id = http::post(a, url, cs);
     assert(hasContent(id));
     {
-        const failable<value, std::string> val = http::get(url + "/" + std::string(content(id)), cs);
+        const failable<value> val = http::get(url + "/" + content(id), cs);
         assert(hasContent(val));
         assert(content(val) == a);
     }
 
     const list<value> j = list<value>()
-            << (list<value>() << "name" << std::string("Apple"))
-            << (list<value>() << "price" << std::string("$3.55"));
-    const list<value> b = mklist<value>(std::string("item"), std::string("cart-53d67a61-aa5e-4e5e-8401-39edeba8b83b"), j);
+            + (list<value>() + "name" + string("Apple"))
+            + (list<value>() + "price" + string("$3.55"));
+    const list<value> b = mklist<value>(string("item"), string("cart-53d67a61-aa5e-4e5e-8401-39edeba8b83b"), j);
 
     {
-        const failable<value, std::string> r = http::put(b, url + "/" + std::string(content(id)), cs);
+        const failable<value> r = http::put(b, url + "/" + content(id), cs);
         assert(hasContent(r));
         assert(content(r) == value(true));
     }
     {
-        const failable<value, std::string> val = http::get(url + "/" + std::string(content(id)), cs);
+        const failable<value> val = http::get(url + "/" + content(id), cs);
         assert(hasContent(val));
         assert(content(val) == b);
     }
     {
-        const failable<value, std::string> r = http::del(url + "/" + std::string(content(id)), cs);
+        const failable<value> r = http::del(url + "/" + content(id), cs);
         assert(hasContent(r));
         assert(content(r) == value(true));
     }
     {
-        const failable<value, std::string> val = http::get(url + "/" + std::string(content(id)), cs);
+        const failable<value> val = http::get(url + "/" + content(id), cs);
         assert(!hasContent(val));
     }
 
@@ -89,7 +89,7 @@
     getLoop(const value& id, const value& entry, http::CURLSession cs) : id(id), entry(entry), cs(cs) {
     }
     const bool operator()() const {
-        const failable<value, std::string> val = http::get(url + "/" + std::string(id), cs);
+        const failable<value> val = http::get(url + "/" + id, cs);
         assert(hasContent(val));
         assert(content(val) == entry);
         return true;
@@ -98,16 +98,16 @@
 
 bool testGetPerf() {
     const list<value> i = list<value>()
-            << (list<value>() << "name" << std::string("Apple"))
-            << (list<value>() << "price" << std::string("$4.55"));
-    const value a = mklist<value>(std::string("item"), std::string("cart-53d67a61-aa5e-4e5e-8401-39edeba8b83b"), i);
+            + (list<value>() + "name" + string("Apple"))
+            + (list<value>() + "price" + string("$4.55"));
+    const value a = mklist<value>(string("item"), string("cart-53d67a61-aa5e-4e5e-8401-39edeba8b83b"), i);
 
     http::CURLSession cs;
-    const failable<value, std::string> id = http::post(a, url, cs);
+    const failable<value> id = http::post(a, url, cs);
     assert(hasContent(id));
 
     const lambda<bool()> gl = getLoop(content(id), a, cs);
-    std::cout << "Cache get test " << time(gl, 5, 200) << " ms" << std::endl;
+    cout << "Cache get test " << time(gl, 5, 200) << " ms" << endl;
 
     return true;
 }
@@ -116,12 +116,12 @@
 }
 
 int main() {
-    std::cout << "Testing..." << std::endl;
+    tuscany::cout << "Testing..." << tuscany::endl;
 
     tuscany::cache::testCache();
     tuscany::cache::testGetPerf();
 
-    std::cout << "OK" << std::endl;
+    tuscany::cout << "OK" << tuscany::endl;
 
     return 0;
 }

Modified: tuscany/sca-cpp/trunk/components/cache/mcache-test.cpp
URL: http://svn.apache.org/viewvc/tuscany/sca-cpp/trunk/components/cache/mcache-test.cpp?rev=895165&r1=895164&r2=895165&view=diff
==============================================================================
--- tuscany/sca-cpp/trunk/components/cache/mcache-test.cpp (original)
+++ tuscany/sca-cpp/trunk/components/cache/mcache-test.cpp Sat Jan  2 10:27:26 2010
@@ -24,8 +24,8 @@
  */
 
 #include <assert.h>
-#include <iostream>
-#include <string>
+#include "stream.hpp"
+#include "string.hpp"
 #include "perf.hpp"
 #include "mcache.hpp"
 
@@ -35,10 +35,10 @@
 bool testMemCached() {
     MemCached ch;
 
-    assert(hasContent(post("a", std::string("AAA"), ch)));
-    assert(get("a", ch) == value(std::string("AAA")));
-    assert(hasContent(put("a", std::string("aaa"), ch)));
-    assert(get("a", ch) == value(std::string("aaa")));
+    assert(hasContent(post("a", string("AAA"), ch)));
+    assert((get("a", ch)) == value(string("AAA")));
+    assert(hasContent(put("a", string("aaa"), ch)));
+    assert((get("a", ch)) == value(string("aaa")));
     assert(hasContent(del("a", ch)));
     assert(!hasContent(get("a", ch)));
 
@@ -50,18 +50,17 @@
     getLoop(MemCached& ch) : ch(ch) {
     }
     const bool operator()() const {
-        assert(get("c", ch) == value(std::string("CCC")));
+        assert((get("c", ch)) == value(string("CCC")));
         return true;
     }
 };
 
 bool testGetPerf() {
     MemCached ch;
-    assert(hasContent(post("c", std::string("CCC"), ch)));
+    assert(hasContent(post("c", string("CCC"), ch)));
 
     const lambda<bool()> gl = getLoop(ch);
-    std::cout << "Memcached get test " << time(gl, 5, 200) << " ms" << std::endl;
-
+    cout << "Memcached get test " << time(gl, 5, 200) << " ms" << endl;
     return true;
 }
 
@@ -69,12 +68,12 @@
 }
 
 int main() {
-    std::cout << "Testing..." << std::endl;
+    tuscany::cout << "Testing..." << tuscany::endl;
 
     tuscany::cache::testMemCached();
     tuscany::cache::testGetPerf();
 
-    std::cout << "OK" << std::endl;
+    tuscany::cout << "OK" << tuscany::endl;
 
     return 0;
 }

Modified: tuscany/sca-cpp/trunk/components/cache/mcache.cpp
URL: http://svn.apache.org/viewvc/tuscany/sca-cpp/trunk/components/cache/mcache.cpp?rev=895165&r1=895164&r2=895165&view=diff
==============================================================================
--- tuscany/sca-cpp/trunk/components/cache/mcache.cpp (original)
+++ tuscany/sca-cpp/trunk/components/cache/mcache.cpp Sat Jan  2 10:27:26 2010
@@ -25,7 +25,7 @@
 
 #include <apr_uuid.h>
 
-#include <string>
+#include "string.hpp"
 
 #include "function.hpp"
 #include "list.hpp"
@@ -41,7 +41,7 @@
 /**
  * Get an item from the cache.
  */
-const failable<value, std::string> get(const list<value>& params) {
+const failable<value> get(const list<value>& params) {
     return cache::get(car(params), ch);
 }
 
@@ -53,34 +53,34 @@
     apr_uuid_get(&uuid);
     char buf[APR_UUID_FORMATTED_LENGTH];
     apr_uuid_format(buf, &uuid);
-    return value(std::string(buf, APR_UUID_FORMATTED_LENGTH));
+    return value(string(buf, APR_UUID_FORMATTED_LENGTH));
 }
 
-const failable<value, std::string> post(const list<value>& params) {
+const failable<value> post(const list<value>& params) {
     const value id = uuidValue();
-    const failable<bool, std::string> val = cache::post(id, car(params), ch);
+    const failable<bool> val = cache::post(id, car(params), ch);
     if (!hasContent(val))
-        return mkfailure<value, std::string>(reason(val));
+        return mkfailure<value>(reason(val));
     return id;
 }
 
 /**
  * Put an item into the cache.
  */
-const failable<value, std::string> put(const list<value>& params) {
-    const failable<bool, std::string> val = cache::put(car(params), cadr(params), ch);
+const failable<value> put(const list<value>& params) {
+    const failable<bool> val = cache::put(car(params), cadr(params), ch);
     if (!hasContent(val))
-        return mkfailure<value, std::string>(reason(val));
+        return mkfailure<value>(reason(val));
     return value(content(val));
 }
 
 /**
  * Delete an item from the cache.
  */
-const failable<value, std::string> del(const list<value>& params) {
-    const failable<bool, std::string> val = cache::del(car(params), ch);
+const failable<value> del(const list<value>& params) {
+    const failable<bool> val = cache::del(car(params), ch);
     if (!hasContent(val))
-        return mkfailure<value, std::string>(reason(val));
+        return mkfailure<value>(reason(val));
     return value(content(val));
 }
 
@@ -99,7 +99,7 @@
         return tuscany::cache::put(cdr(params));
     if (func == "delete")
         return tuscany::cache::del(cdr(params));
-    return tuscany::mkfailure<tuscany::value, std::string>(std::string("Function not supported: ") + std::string(func));
+    return tuscany::mkfailure<tuscany::value>(tuscany::string("Function not supported: ") + func);
 }
 
 }

Modified: tuscany/sca-cpp/trunk/components/cache/mcache.hpp
URL: http://svn.apache.org/viewvc/tuscany/sca-cpp/trunk/components/cache/mcache.hpp?rev=895165&r1=895164&r2=895165&view=diff
==============================================================================
--- tuscany/sca-cpp/trunk/components/cache/mcache.hpp (original)
+++ tuscany/sca-cpp/trunk/components/cache/mcache.hpp Sat Jan  2 10:27:26 2010
@@ -34,8 +34,7 @@
 #include "apr_memcache.h"
 #include "apr_network_io.h"
 
-#include <string>
-#include <sstream>
+#include "string.hpp"
 #include "list.hpp"
 #include "value.hpp"
 #include "monad.hpp"
@@ -56,7 +55,7 @@
         init("localhost", 11211);
     }
 
-    MemCached(const std::string host, const int port) {
+    MemCached(const string host, const int port) {
         apr_pool_create(&pool, NULL);
         apr_memcache_create(pool, 1, 0, &mc);
         init(host, port);
@@ -70,22 +69,22 @@
     apr_pool_t* pool;
     apr_memcache_t* mc;
 
-    friend const failable<bool, std::string> post(const value& key, const value& val, const MemCached& cache);
-    friend const failable<bool, std::string> put(const value& key, const value& val, const MemCached& cache);
-    friend const failable<value, std::string> get(const value& key, const MemCached& cache);
-    friend const failable<bool, std::string> del(const value& key, const MemCached& cache);
+    friend const failable<bool> post(const value& key, const value& val, const MemCached& cache);
+    friend const failable<bool> put(const value& key, const value& val, const MemCached& cache);
+    friend const failable<value> get(const value& key, const MemCached& cache);
+    friend const failable<bool> del(const value& key, const MemCached& cache);
 
     /**
      * Initialize the memcached context.
      */
-    const failable<bool, std::string> init(const std::string& host, const int port) {
+    const failable<bool> init(const string& host, const int port) {
         apr_memcache_server_t *server;
-        const apr_status_t sc = apr_memcache_server_create(pool, host.c_str(), (apr_port_t)port, 0, 1, 1, 60, &server);
+        const apr_status_t sc = apr_memcache_server_create(pool, c_str(host), (apr_port_t)port, 0, 1, 1, 60, &server);
         if (sc != APR_SUCCESS)
-            return mkfailure<bool, std::string>("Could not create server");
+            return mkfailure<bool>("Could not create server");
         const apr_status_t as = apr_memcache_add_server(mc, server);
         if (as != APR_SUCCESS)
-            return mkfailure<bool, std::string>("Could not add server");
+            return mkfailure<bool>("Could not add server");
         return true;
     }
 
@@ -94,15 +93,15 @@
 /**
  * Post a new item to the cache.
  */
-const failable<bool, std::string> post(const value& key, const value& val, const MemCached& cache) {
+const failable<bool> post(const value& key, const value& val, const MemCached& cache) {
     debug(key, "cache::post::key");
     debug(val, "cache::post::value");
 
-    const std::string ks(eval::writeValue(key));
-    const std::string vs(eval::writeValue(val));
-    const apr_status_t rc = apr_memcache_add(cache.mc, ks.c_str(), const_cast<char*>(vs.c_str()), vs.size(), 0, 27);
+    const string ks(eval::writeValue(key));
+    const string vs(eval::writeValue(val));
+    const apr_status_t rc = apr_memcache_add(cache.mc, c_str(ks), const_cast<char*>(c_str(vs)), length(vs), 0, 27);
     if (rc != APR_SUCCESS)
-        return mkfailure<bool, std::string>("Could not add entry");
+        return mkfailure<bool>("Could not add entry");
 
     debug(true, "cache::post::result");
     return true;
@@ -111,15 +110,15 @@
 /**
  * Update an item in the cache. If the item doesn't exist it is added.
  */
-const failable<bool, std::string> put(const value& key, const value& val, const MemCached& cache) {
+const failable<bool> put(const value& key, const value& val, const MemCached& cache) {
     debug(key, "cache::put::key");
     debug(val, "cache::put::value");
 
-    const std::string ks(eval::writeValue(key));
-    const std::string vs(eval::writeValue(val));
-    const apr_status_t rc = apr_memcache_set(cache.mc, ks.c_str(), const_cast<char*>(vs.c_str()), vs.size(), 0, 27);
+    const string ks(eval::writeValue(key));
+    const string vs(eval::writeValue(val));
+    const apr_status_t rc = apr_memcache_set(cache.mc, c_str(ks), const_cast<char*>(c_str(vs)), length(vs), 0, 27);
     if (rc != APR_SUCCESS)
-        return mkfailure<bool, std::string>("Could not add entry");
+        return mkfailure<bool>("Could not add entry");
 
     debug(true, "cache::put::result");
     return true;
@@ -128,25 +127,24 @@
 /**
  * Get an item from the cache.
  */
-const failable<value, std::string> get(const value& key, const MemCached& cache) {
+const failable<value> get(const value& key, const MemCached& cache) {
     debug(key, "cache::get::key");
 
-    const std::string ks(eval::writeValue(key));
-
+    const string ks(eval::writeValue(key));
     apr_pool_t* vpool;
     const apr_status_t pc = apr_pool_create(&vpool, cache.pool);
     if (pc != APR_SUCCESS)
-        return mkfailure<value, std::string>("Could not allocate memory");
+        return mkfailure<value>("Could not allocate memory");
 
     char *data;
     apr_size_t size;
-    const apr_status_t rc = apr_memcache_getp(cache.mc, cache.pool, ks.c_str(), &data, &size, NULL);
+    const apr_status_t rc = apr_memcache_getp(cache.mc, cache.pool, c_str(ks), &data, &size, NULL);
     if (rc != APR_SUCCESS) {
         apr_pool_destroy(vpool);
-        return mkfailure<value, std::string>("Could not get entry");
+        return mkfailure<value>("Could not get entry");
     }
 
-    const value val(eval::readValue(std::string(data, size)));
+    const value val(eval::readValue(string(data, size)));
     apr_pool_destroy(vpool);
 
     debug(val, "cache::get::result");
@@ -156,14 +154,13 @@
 /**
  * Delete an item from the cache
  */
-const failable<bool, std::string> del(const value& key, const MemCached& cache) {
+const failable<bool> del(const value& key, const MemCached& cache) {
     debug(key, "cache::delete::key");
 
-    std::ostringstream kos;
-    kos << key;
-    const apr_status_t rc = apr_memcache_delete(cache.mc, kos.str().c_str(), 0);
+    const string ks(eval::writeValue(key));
+    const apr_status_t rc = apr_memcache_delete(cache.mc, c_str(ks), 0);
     if (rc != APR_SUCCESS)
-        return mkfailure<bool, std::string>("Could not delete entry");
+        return mkfailure<bool>("Could not delete entry");
 
     debug(true, "cache::delete::result");
     return true;

Modified: tuscany/sca-cpp/trunk/components/cache/memcached-server-test
URL: http://svn.apache.org/viewvc/tuscany/sca-cpp/trunk/components/cache/memcached-server-test?rev=895165&r1=895164&r2=895165&view=diff
==============================================================================
--- tuscany/sca-cpp/trunk/components/cache/memcached-server-test (original)
+++ tuscany/sca-cpp/trunk/components/cache/memcached-server-test Sat Jan  2 10:27:26 2010
@@ -35,7 +35,7 @@
 sleep 2
 
 # Test
-./mcache-client-test 2>/dev/null
+./mcache-client-test
 rc=$?
 
 # Cleanup

Modified: tuscany/sca-cpp/trunk/components/cache/memcached-test
URL: http://svn.apache.org/viewvc/tuscany/sca-cpp/trunk/components/cache/memcached-test?rev=895165&r1=895164&r2=895165&view=diff
==============================================================================
--- tuscany/sca-cpp/trunk/components/cache/memcached-test (original)
+++ tuscany/sca-cpp/trunk/components/cache/memcached-test Sat Jan  2 10:27:26 2010
@@ -23,7 +23,7 @@
 sleep 1
 
 # Test
-./mcache-test 2>/dev/null
+./mcache-test
 rc=$?
 
 # Cleanup

Modified: tuscany/sca-cpp/trunk/configure.ac
URL: http://svn.apache.org/viewvc/tuscany/sca-cpp/trunk/configure.ac?rev=895165&r1=895164&r2=895165&view=diff
==============================================================================
--- tuscany/sca-cpp/trunk/configure.ac (original)
+++ tuscany/sca-cpp/trunk/configure.ac Sat Jan  2 10:27:26 2010
@@ -39,7 +39,7 @@
 # Check for running on Darwin
 AC_MSG_CHECKING([if running on Darwin])
 UNAME=`uname -s`
-if test "x$UNAME" = "xDarwin"; then
+if test "${UNAME}" = "Darwin"; then
   AC_DEFINE([IS_DARWIN], [1], [Set to 1 when running on Darwin - Mac OSX])
   AC_MSG_RESULT(yes)
   AC_SUBST([libsuffix],[".dylib"])
@@ -49,14 +49,14 @@
   AC_SUBST([libsuffix],[".so"])
   is_darwin=false
 fi
-AM_CONDITIONAL([DARWIN], [test x$is_darmin = xtrue])
+AM_CONDITIONAL([DARWIN], [test "${is_darmin}" = "true"])
 
 # Configure CURL_INCLUDE and CURL_LIB
 AC_MSG_CHECKING([for curl])
 AC_ARG_WITH([curl], [AC_HELP_STRING([--with-curl=PATH], [path to installed curl [default=/usr]])], [
-  CURL_INCLUDE="$withval/include"
-  CURL_LIB="$withval/lib"
-  AC_MSG_RESULT("$withval")
+  CURL_INCLUDE="${withval}/include"
+  CURL_LIB="${withval}/lib"
+  AC_MSG_RESULT("${withval}")
 ], [
   CURL_INCLUDE="/usr/include"
   CURL_LIB="/usr/lib"
@@ -68,9 +68,9 @@
 # Configure LIBXML2_INCLUDE and LIBXML2_LIB
 AC_MSG_CHECKING([for libxml2])
 AC_ARG_WITH([libxml2], [AC_HELP_STRING([--with-libxml2=PATH], [path to installed libxml2 [default=/usr]])], [
-  LIBXML2_INCLUDE="$withval/include/libxml2"
-  LIBXML2_LIB="$withval/lib"
-  AC_MSG_RESULT("$withval")
+  LIBXML2_INCLUDE="${withval}/include/libxml2"
+  LIBXML2_LIB="${withval}/lib"
+  AC_MSG_RESULT("${withval}")
 ], [
   LIBXML2_INCLUDE="/usr/include/libxml2"
   LIBXML2_LIB="/usr/lib"
@@ -83,16 +83,16 @@
 AC_MSG_CHECKING([for js-include])
 AC_ARG_WITH([js-include], [AC_HELP_STRING([--with-js-include=PATH], [path to installed SpiderMonkey include dir
              [default=/usr/include/xulrunner-1.9.1.5/unstable]])], [
-  JS_INCLUDE="$withval"
-  AC_MSG_RESULT("$withval")
+  JS_INCLUDE="${withval}"
+  AC_MSG_RESULT("${withval}")
 ], [
   JS_INCLUDE="/usr/include/xulrunner-1.9.1.5/unstable"
   AC_MSG_RESULT(/usr/include/xulrunner-1.9.1.5/unstable)
 ])
 AC_MSG_CHECKING([for js-lib])
 AC_ARG_WITH([js-lib], [AC_HELP_STRING([--with-js-lib=PATH], [path to installed SpiderMonkey lib dir [default=/usr/lib/xulrunner-1.9.1.5]])], [
-  JS_LIB="$withval"
-  AC_MSG_RESULT("$withval")
+  JS_LIB="${withval}"
+  AC_MSG_RESULT("${withval}")
 ], [
   JS_LIB="/usr/lib/xulrunner-1.9.1.5"
   AC_MSG_RESULT(/usr/lib/xulrunner-1.9.1.5)
@@ -103,9 +103,9 @@
 # Configure APR and HTTPD
 AC_MSG_CHECKING([for apr])
 AC_ARG_WITH([apr], [AC_HELP_STRING([--with-apr=PATH], [path to installed apr [default=/usr/local/apache2]])], [
-  APR_INCLUDE="$withval/include"
-  APR_LIB="$withval/lib"
-  AC_MSG_RESULT("$withval")
+  APR_INCLUDE="${withval}/include"
+  APR_LIB="${withval}/lib"
+  AC_MSG_RESULT("${withval}")
 ], [
   APR_INCLUDE="/usr/local/apache2/include"
   APR_LIB="/usr/local/apache2/lib"
@@ -116,8 +116,8 @@
 
 AC_MSG_CHECKING([for httpd])
 AC_ARG_WITH([httpd], [AC_HELP_STRING([--with-httpd=PATH], [path to installed httpd [default=/usr/local/apache2]])], [
-  HTTPD_INCLUDE="$withval/include"
-  AC_MSG_RESULT("$withval")
+  HTTPD_INCLUDE="${withval}/include"
+  AC_MSG_RESULT("${withval}")
 ], [
   HTTPD_INCLUDE="/usr/local/apache2/include"
   AC_MSG_RESULT(/usr/local/apache2/lib)
@@ -125,20 +125,20 @@
 AC_SUBST(HTTPD_INCLUDE)
 
 # Checks for libraries.
-original_LIBS="$LIBS"
+original_LIBS="${LIBS}"
 AC_MSG_NOTICE([checking for libraries])
-LIBS="-L$CURL_LIB $original_LIBS"
+LIBS="-L${CURL_LIB} ${original_LIBS}"
 AC_CHECK_LIB([curl], [curl_global_init], [], [AC_MSG_ERROR([couldn't find a suitable libcurl, use --with-curl=PATH])])
-LIBS="-L$JS_LIB $original_LIBS"
+LIBS="-L${JS_LIB} ${original_LIBS}"
 AC_CHECK_LIB([mozjs], [JS_NewContext], [], [AC_MSG_ERROR([couldn't find a suitable libmozjs, use --with-js-lib=PATH])])
-LIBS="$original_LIBS"
+LIBS="${original_LIBS}"
 AC_CHECK_LIB([pthread], [pthread_create], [], [AC_MSG_ERROR([couldn't find a suitable libpthread])])
-LIBS="-L$LIBXML2_LIB $original_LIBS"
+LIBS="-L${LIBXML2_LIB} ${original_LIBS}"
 AC_CHECK_LIB([xml2], [xmlInitParser], [], [AC_MSG_ERROR([couldn't find a suitable libxml2, use --with-libxml2=PATH])])
-LIBS="-L$APR_LIB $original_LIBS"
+LIBS="-L${APR_LIB} ${original_LIBS}"
 AC_CHECK_LIB([apr-1], [apr_pool_initialize], [], [AC_MSG_ERROR([couldn't find a suitable libapr-1, use --with-apr=PATH])])
 AC_CHECK_LIB([aprutil-1], [apr_memcache_replace], [], [AC_MSG_ERROR([couldn't find a suitable libaprutil-1, use --with-apr=PATH])])
-LIBS="$original_LIBS"
+LIBS="${original_LIBS}"
 
 # Checks for header files.
 AC_MSG_NOTICE([checking for header files])
@@ -158,9 +158,12 @@
 AC_CHECK_FUNCS([gettimeofday select])
 
 # Configure GCC C++ compile options
-# Configure debugging, profiling and compile-time warnings
-AC_MSG_CHECKING([whether to compile for debugging and profiling])
-AC_ARG_ENABLE(maintainer-mode, [AS_HELP_STRING([--enable-maintainer-mode], [compile for debugging and profiling [default=no]])],
+cxxflags=""
+ldflags="${LDFLAGS}"
+
+# Configure debugging and compile-time warnings
+AC_MSG_CHECKING([whether to compile with debugging and compile-time warnings])
+AC_ARG_ENABLE(maintainer-mode, [AS_HELP_STRING([--enable-maintainer-mode], [compile with debugging and compile-time warnings [default=no]])],
 [ case "${enableval}" in
   no)
     AC_MSG_RESULT(no)
@@ -171,23 +174,63 @@
     ;;
   esac ],
 [ AC_MSG_RESULT(no)])
-if test "$want_maintainer_mode" = "true"; then
-  AC_SUBST([CXXFLAGS], [" -D_REENTRANT -D_DEBUG -O0 -g3 -pg -Werror -Wall -Wextra -Wno-ignored-qualifiers -Winit-self -Wmissing-include-dirs -Wcast-qual -Wcast-align -Wwrite-strings -Wpointer-arith -Wconversion -Waddress -Wlogical-op -Wredundant-decls -std=c++0x -fmessage-length=0"])
-  AC_SUBST([LDFLAGS], ["${LDFLAGS} -lpthread -pg"])
+if test "${want_maintainer_mode}" = "true"; then
+  cxxflags="${cxxflags} -D_DEBUG -O0 -g3 -Werror -Wall -Wextra -Wno-ignored-qualifiers -Winit-self -Wmissing-include-dirs -Wcast-qual -Wcast-align -Wwrite-strings -Wpointer-arith -Wconversion -Waddress -Wlogical-op -Wredundant-decls -std=c++0x -fmessage-length=0"
+  ldflags="${ldflags} -pg"
 else
-  AC_SUBST([CXXFLAGS], [" -D_REENTRANT -O3 -std=c++0x -fmessage-length=0"])
-  AC_SUBST([LDFLAGS], ["${LDFLAGS} -lpthread"])
+  cxxflags="${cxxflags} -O3 -std=c++0x -fmessage-length=0"
+fi
+
+# Configure profiling
+AC_MSG_CHECKING([whether to compile with profiling])
+AC_ARG_ENABLE(profiling, [AS_HELP_STRING([--enable-profiling], [compile with profiling [default=no]])],
+[ case "${enableval}" in
+  no)
+    AC_MSG_RESULT(no)
+    ;;
+  *)
+    AC_MSG_RESULT(yes)
+    want_profiling=true
+    ;;
+  esac ],
+[ AC_MSG_RESULT(no)])
+if test "${want_profiling}" = "true"; then
+  cxxflags="${cxxflags} -pg"
+  ldflags="${ldflags} -pg"
+fi
+
+# Configure multi-threading support
+AC_MSG_CHECKING([whether to compile for multi-threaded execution])
+AC_ARG_ENABLE(threads, [AS_HELP_STRING([--enable-threads], [compile for multi-threaded execution [default=no]])],
+[ case "${enableval}" in
+  no)
+    AC_MSG_RESULT(no)
+    ;;
+  *)
+    AC_MSG_RESULT(yes)
+    want_threads=true
+    ;;
+  esac ],
+[ AC_MSG_RESULT(no)])
+if test "${want_threads}" = "true"; then
+  LIBS="${original_LIBS}"
+  AC_CHECK_LIB([pthread], [pthread_create], [], [AC_MSG_ERROR([couldn't find a suitable libpthread])])
+  LIBS="${original_LIBS}"
+  cxxflags="${cxxflags} -D_REENTRANT"
+  ldflags="${ldflags} -lpthread"
 fi
+AC_SUBST([CXXFLAGS], ["${cxxflags}"])
+AC_SUBST([LDFLAGS], ["${ldflags}"])
 
 # Configure exuberant ctags
 TAGSFILE="`pwd`/tags"
-AC_SUBST([CTAGSFLAGS], ["${CTAGSFLAGS} --c++-kinds=+p --fields=+iaS --extra=+q --append --tag-relative=yes -f $TAGSFILE"])
+AC_SUBST([CTAGSFLAGS], ["${CTAGSFLAGS} --c++-kinds=+p --fields=+iaS --extra=+q --append --tag-relative=yes -f ${TAGSFILE}"])
 
 # Configure TUSCANY_SCACPP
-TUSCANY_SCACPP=`echo "$TUSCANY_SCACPP"`
-if test "$TUSCANY_SCACPP" = ""; then
+TUSCANY_SCACPP=`echo "${TUSCANY_SCACPP}"`
+if test "${TUSCANY_SCACPP}" = ""; then
   SCAPWD=`pwd`
-  AC_SUBST([TUSCANY_SCACPP], ["$SCAPWD"])
+  AC_SUBST([TUSCANY_SCACPP], ["${SCAPWD}"])
 fi
 
 # Configure Doxygen build
@@ -199,15 +242,15 @@
     ;;
   *)
     AC_MSG_RESULT(yes)
-    AC_PATH_PROG(DOXYGEN, doxygen, , $PATH)
-    if test "$DOXYGEN" = ""; then
+    AC_PATH_PROG(DOXYGEN, doxygen, , ${PATH})
+    if test "${DOXYGEN}" = ""; then
       AC_MSG_ERROR([could not find doxygen])
     fi
     want_doxygen=true
     ;;
   esac ],
 [ AC_MSG_RESULT(no)])
-AM_CONDITIONAL([WANT_DOXYGEN], [test "$want_doxygen" = "true"])
+AM_CONDITIONAL([WANT_DOXYGEN], [test "${want_doxygen}" = "true"])
 
 AC_CONFIG_FILES([Makefile
                  kernel/Makefile

Modified: tuscany/sca-cpp/trunk/etc/git-exclude
URL: http://svn.apache.org/viewvc/tuscany/sca-cpp/trunk/etc/git-exclude?rev=895165&r1=895164&r2=895165&view=diff
==============================================================================
--- tuscany/sca-cpp/trunk/etc/git-exclude (original)
+++ tuscany/sca-cpp/trunk/etc/git-exclude Sat Jan  2 10:27:26 2010
@@ -61,17 +61,21 @@
 
 # Specific ignores
 kernel-test
-xsd-test
-parallel-test
+string-test
+mem-test
 xml-test
+xsd-test
 atom-test
 eval-test
 eval-shell
 json-test
+cache-test
 client-test
 mcache-test
 mcache-client-test
 curl-test
 scdl-test
+store-function-test
+store-object-test
 store-script-test
 

Modified: tuscany/sca-cpp/trunk/kernel/Makefile.am
URL: http://svn.apache.org/viewvc/tuscany/sca-cpp/trunk/kernel/Makefile.am?rev=895165&r1=895164&r2=895165&view=diff
==============================================================================
--- tuscany/sca-cpp/trunk/kernel/Makefile.am (original)
+++ tuscany/sca-cpp/trunk/kernel/Makefile.am Sat Jan  2 10:27:26 2010
@@ -15,7 +15,7 @@
 #  specific language governing permissions and limitations
 #  under the License.
 
-noinst_PROGRAMS = kernel-test parallel-test xml-test xsd-test
+noinst_PROGRAMS = string-test kernel-test mem-test parallel-test xml-test xsd-test
 
 testdir=$(prefix)/test
 test_LTLIBRARIES = libdynlib-test.la
@@ -25,12 +25,18 @@
 
 INCLUDES = -I. -I$(top_builddir)/kernel -I${LIBXML2_INCLUDE} -I${APR_INCLUDE}
 
-kernel_test_SOURCES = kernel-test.cpp
-kernel_test_LDADD = -L${LIBXML2_LIB} -lxml2 -L${APR_LIB} -lapr-1 -laprutil-1
+string_test_SOURCES = string-test.cpp
+string_test_LDADD = -L${LIBXML2_LIB} -lxml2 -L${APR_LIB} -lapr-1 -laprutil-1
 
 libdynlib_test_la_SOURCES = dynlib-test.cpp
 libdynlib_test_la_LIBADD = -L${APR_LIB} -lapr-1 -laprutil-1
 
+kernel_test_SOURCES = kernel-test.cpp
+kernel_test_LDADD = -L${LIBXML2_LIB} -lxml2 -L${APR_LIB} -lapr-1 -laprutil-1
+
+mem_test_SOURCES = mem-test.cpp
+mem_test_LDADD = -L${APR_LIB} -lapr-1 -laprutil-1
+
 parallel_test_SOURCES = parallel-test.cpp
 parallel_test_LDADD = -L${LIBXML2_LIB} -lxml2 -L${APR_LIB} -lapr-1 -laprutil-1
 
@@ -40,4 +46,4 @@
 xsd_test_SOURCES = xsd-test.cpp
 xsd_test_LDADD = -L${LIBXML2_LIB} -lxml2 -L${APR_LIB} -lapr-1 -laprutil-1
 
-TESTS = kernel-test parallel-test xml-test
+TESTS = string-test kernel-test mem-test parallel-test xml-test

Modified: tuscany/sca-cpp/trunk/kernel/debug.hpp
URL: http://svn.apache.org/viewvc/tuscany/sca-cpp/trunk/kernel/debug.hpp?rev=895165&r1=895164&r2=895165&view=diff
==============================================================================
--- tuscany/sca-cpp/trunk/kernel/debug.hpp (original)
+++ tuscany/sca-cpp/trunk/kernel/debug.hpp Sat Jan  2 10:27:26 2010
@@ -23,24 +23,15 @@
 #define tuscany_debug_hpp
 
 /**
- * Functions to help log and debug.
+ * Debug functions and macros.
  */
 
-#include <string>
-#include <ostream>
-
 namespace tuscany
 {
 
 #ifdef _DEBUG
 
-/**
- * Debug log.
- */
-template<typename V> const bool debug(const V& v, const std::string& msg) {
-    std::cerr << msg << ": " << v << std::endl;
-    return true;
-}
+//#define _DEBUG_WATCH
 
 /**
  * Increment / decrement a debug counter.
@@ -55,20 +46,18 @@
     return true;
 }
 
-/**
- * Attribute used to mark unused parameters.
- */
-#define unused __attribute__ ((unused))
-
 #else
 
-#define debug(v, msg)
-
 #define debug_inc(c)
 #define debug_dec(c)
 
-#define unused
+#endif
 
+/**
+ * Attribute used to mark unused parameters.
+ */
+#ifndef unused
+#define unused __attribute__ ((unused))
 #endif
 
 }

Modified: tuscany/sca-cpp/trunk/kernel/dynlib.hpp
URL: http://svn.apache.org/viewvc/tuscany/sca-cpp/trunk/kernel/dynlib.hpp?rev=895165&r1=895164&r2=895165&view=diff
==============================================================================
--- tuscany/sca-cpp/trunk/kernel/dynlib.hpp (original)
+++ tuscany/sca-cpp/trunk/kernel/dynlib.hpp Sat Jan  2 10:27:26 2010
@@ -38,9 +38,9 @@
  * OS specific dynamic library file extension.
  */
 #ifdef IS_DARWIN
-const std::string dynlibExt(".dylib");
+const string dynlibExt(".dylib");
 #else
-const std::string dynlibExt(".so");
+const string dynlibExt(".so");
 #endif
 
 /**
@@ -51,7 +51,7 @@
     lib() : dl(NULL) {
     }
 
-    lib(const std::string& name) : dl(new DynLib(name)) {
+    lib(const string& name) : dl(new (gc_new<DynLib>()) DynLib(name)) {
     }
 
     ~lib() {
@@ -60,41 +60,42 @@
 private:
     class DynLib {
     public:
-        DynLib(const std::string& name) : name(name), h(dlopen(name.c_str(), RTLD_NOW)) {
+        DynLib(const string& name) : name(name), h(dlopen(c_str(name), RTLD_NOW)) {
         }
+
         ~DynLib() {
             if (h == NULL)
                 return;
             dlclose(h);
         }
 
-        const std::string name;
+        const string name;
         void* h;
     };
 
     gc_ptr<DynLib> dl;
 
-    friend const failable<lib, std::string> dynlib(const std::string& name);
-    template<typename S> friend const failable<lambda<S>, std::string> dynlambda(const std::string& name, const lib& l);
+    friend const failable<lib> dynlib(const string& name);
+    template<typename S> friend const failable<lambda<S> > dynlambda(const string& name, const lib& l);
 };
 
 /**
  * Load a dynamic library.
  */
-const failable<lib, std::string> dynlib(const std::string& name) {
+const failable<lib> dynlib(const string& name) {
     const lib l(name);
     if (l.dl->h == NULL)
-        return mkfailure<lib, std::string>("Could not load library: " + name + ": " + dlerror());
+        return mkfailure<lib>(string("Could not load library: ") + name + ": " + dlerror());
     return l;
 }
 
 /**
  * Find a lambda function in a dynamic library.
  */
-template<typename S> const failable<lambda<S>, std::string> dynlambda(const std::string& name, const lib& l) {
-    const void* s = dlsym(l.dl->h, name.c_str());
+template<typename S> const failable<lambda<S> > dynlambda(const string& name, const lib& l) {
+    const void* s = dlsym(l.dl->h, c_str(name));
     if (s == NULL)
-        return mkfailure<lambda<S>, std::string>(std::string("Could not load symbol: " + name));
+        return mkfailure<lambda<S> >(string("Could not load symbol: ") + name);
     return lambda<S>((S*)s);
 }
 

Modified: tuscany/sca-cpp/trunk/kernel/element.hpp
URL: http://svn.apache.org/viewvc/tuscany/sca-cpp/trunk/kernel/element.hpp?rev=895165&r1=895164&r2=895165&view=diff
==============================================================================
--- tuscany/sca-cpp/trunk/kernel/element.hpp (original)
+++ tuscany/sca-cpp/trunk/kernel/element.hpp Sat Jan  2 10:27:26 2010
@@ -98,7 +98,7 @@
     const list<value> r = reverse(l);
     if (isSymbol(car(r)))
         return false;
-    if(isList(car(r)) && isSymbol(car<value>(car(r))))
+    if(isList(car(r)) && !isNil((list<value>)car(r)) && isSymbol(car<value>(car(r))))
             return false;
     return true;
 }
@@ -201,7 +201,7 @@
             return mklist(element, n, v);
 
         // Convert a list value
-        if (!isSymbol(car<value>(v)))
+        if (isNil((list<value>)v) || !isSymbol(car<value>(v)))
             return cons(element, cons(n, mklist<value>(valuesToElements(v))));
 
         // Convert a nested name value pair value

Added: tuscany/sca-cpp/trunk/kernel/fstream.hpp
URL: http://svn.apache.org/viewvc/tuscany/sca-cpp/trunk/kernel/fstream.hpp?rev=895165&view=auto
==============================================================================
--- tuscany/sca-cpp/trunk/kernel/fstream.hpp (added)
+++ tuscany/sca-cpp/trunk/kernel/fstream.hpp Sat Jan  2 10:27:26 2010
@@ -0,0 +1,152 @@
+/*
+ * 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.
+ */
+
+/* $Rev$ $Date$ */
+
+#ifndef tuscany_fstream_hpp
+#define tuscany_fstream_hpp
+
+/**
+ * File based streams.
+ */
+
+#include <stdio.h>
+#include <stdarg.h>
+#include "string.hpp"
+#include "stream.hpp"
+
+namespace tuscany {
+
+/*
+ * Output stream backed by a FILE.
+ */
+class ofstream : public ostream {
+public:
+    ofstream(const string& path) : file(fopen(c_str(path), "wb")), owned(true) {
+    }
+
+    ofstream(FILE* file) : file(file), owned(false) {
+    }
+
+    ofstream(const ofstream& os) : file(os.file), owned(false) {
+    }
+
+    ~ofstream() {
+        if (!owned)
+            return;
+        if (file == NULL)
+            return;
+        fclose(file);
+    }
+
+    ofstream& vprintf(const char* fmt, ...) {
+        va_list args;
+        va_start (args, fmt);
+        vfprintf (file, fmt, args);
+        va_end (args);
+        return *this;
+    }
+
+    ofstream& flush() {
+        fflush(file);
+        return *this;
+    }
+
+private:
+    FILE* file;
+    bool owned;
+};
+
+/*
+ * Input stream backed by a FILE.
+ */
+class ifstream : public istream {
+public:
+    ifstream(const string& path) : file(fopen(c_str(path), "rb")), owned(true) {
+    }
+
+    ifstream(FILE* file) : file(file), owned(false) {
+    }
+
+    ifstream(const ifstream& is) : file(is.file), owned(false) {
+    }
+
+    ~ifstream() {
+        if (!owned)
+            return;
+        if (file == NULL)
+            return;
+        fclose(file);
+    }
+
+    const int read(void* buf, int size) {
+        return fread(buf, 1, size, file);
+    }
+
+    const bool eof() {
+        return feof(file);
+    }
+
+    const bool fail() {
+        return file == NULL;
+    }
+
+    const int get() {
+        return fgetc(file);
+    }
+
+    const int peek() {
+        int c = fgetc(file);
+        if (c == -1)
+            return c;
+        ungetc(c, file);
+        return c;
+    }
+
+private:
+    FILE* file;
+    bool owned;
+};
+
+/**
+ * Standard streams.
+ */
+ofstream cout(stdout);
+ofstream cerr(stderr);
+ifstream cin(stdin);
+
+/**
+ * Debug log stream.
+ */
+#ifdef _DEBUG
+
+template<typename V> const bool debug(const V& v, const string& msg) {
+    cerr << msg << ": " << v << endl;
+    return true;
+}
+
+#else
+
+#define debug(v, msg)
+
+#endif
+
+}
+
+#endif /* tuscany_fstream_hpp */

Modified: tuscany/sca-cpp/trunk/kernel/function.hpp
URL: http://svn.apache.org/viewvc/tuscany/sca-cpp/trunk/kernel/function.hpp?rev=895165&r1=895164&r2=895165&view=diff
==============================================================================
--- tuscany/sca-cpp/trunk/kernel/function.hpp (original)
+++ tuscany/sca-cpp/trunk/kernel/function.hpp Sat Jan  2 10:27:26 2010
@@ -26,7 +26,8 @@
  * Lambda function type.
  */
 
-#include <iostream>
+#include <bits/move.h>
+#include "fstream.hpp"
 #include "gc.hpp"
 #include "debug.hpp"
 
@@ -55,13 +56,13 @@
 }
 
 bool printLambdaCounters() {
-    std::cout << "countLambdas " << countLambdas << std::endl;
-    std::cout << "countELambdas " << countELambdas << std::endl;
-    std::cout << "countFLambdas " << countFLambdas << std::endl;
-    std::cout << "countCLambdas " << countCLambdas << std::endl;
-    std::cout << "countProxies " << countProxies << std::endl;
-    std::cout << "countFProxies " << countFProxies << std::endl;
-    std::cout << "countCProxies " << countCProxies << std::endl;
+    cout << "countLambdas " << countLambdas << endl;
+    cout << "countELambdas " << countELambdas << endl;
+    cout << "countFLambdas " << countFLambdas << endl;
+    cout << "countCLambdas " << countCLambdas << endl;
+    cout << "countProxies " << countProxies << endl;
+    cout << "countFProxies " << countFProxies << endl;
+    cout << "countCProxies " << countCProxies << endl;
     return true;
 }
 
@@ -79,7 +80,7 @@
 
 template<typename R, typename... P> class Callable {
 public:
-    Callable() : refCount(0) {
+    Callable() {
     }
 
     virtual const int size() const = 0;
@@ -116,19 +117,6 @@
     private:
         const F function;
     };
-
-private:
-    friend class gc_counting_ptr<Callable>;
-
-    unsigned int refCount;
-
-    unsigned int acquire() {
-        return gc_add_and_fetch(refCount, (unsigned int)1);
-    }
-
-    unsigned int release() {
-        return gc_sub_and_fetch(refCount, (unsigned int)1);
-    }
 };
 
 template<typename S> class lambda;
@@ -145,7 +133,7 @@
         debug_inc(countFLambdas);
 
         typedef typename CallableType::template Proxy<F> ProxyType;
-        callable = gc_counting_ptr<CallableType>(new ProxyType(f));
+        callable = gc_ptr<CallableType>(new (gc_new<ProxyType>()) ProxyType(f));
     }
 
     lambda(const lambda& l) {
@@ -179,15 +167,15 @@
         return (*callable)(std::forward<P>(p)...);
     }
 
-    template<typename S> friend std::ostream& operator<<(std::ostream&, const lambda<S>&);
+    template<typename S> friend ostream& operator<<(ostream&, const lambda<S>&);
     template<typename S> friend const bool isNil(const lambda<S>& l);
 
 private:
     typedef Callable<R,P...> CallableType;
-    gc_counting_ptr<CallableType> callable;
+    gc_ptr<CallableType> callable;
 };
 
-template<typename S> std::ostream& operator<<(std::ostream& out, const lambda<S>& l) {
+template<typename S> ostream& operator<<(ostream& out, const lambda<S>& l) {
     return out << "lambda::" << l.callable;
 }
 

Modified: tuscany/sca-cpp/trunk/kernel/gc.hpp
URL: http://svn.apache.org/viewvc/tuscany/sca-cpp/trunk/kernel/gc.hpp?rev=895165&r1=895164&r2=895165&view=diff
==============================================================================
--- tuscany/sca-cpp/trunk/kernel/gc.hpp (original)
+++ tuscany/sca-cpp/trunk/kernel/gc.hpp Sat Jan  2 10:27:26 2010
@@ -23,399 +23,236 @@
 #define tuscany_gc_hpp
 
 /**
- * Garbage collected pointer.
+ * Garbage collected memory management, using APR memory pools.
  */
 
+#include <stdlib.h>
 #include <apr_general.h>
 #include <apr_pools.h>
-#include <iostream>
+#include <assert.h>
+#include <new>
+#include "debug.hpp"
 
 namespace tuscany
 {
 
 /**
- * Macros used to add or subtract values to reference counters.
- * In a multithreaded environment, use the GCC __sync_add_and_fetch
- * and __sync_sub_and_fetch built in functions.
+ * Pointer to a value.
  */
-#ifdef _REENTRANT
-
-#define gc_add_and_fetch(t, v) __sync_add_and_fetch(&(t), v)
-#define gc_sub_and_fetch(t, v) __sync_sub_and_fetch(&(t), v)
-
-#else
-
-#define gc_add_and_fetch(t, v) ((t) = (t) + (v))
-#define gc_sub_and_fetch(t, v) ((t) = (t) - (v))
-
-#endif
-
 template<typename T> class gc_ptr {
 public:
-    gc_ptr(T* p = 0) throw() : countingRef(p == 0? 0 : new CountingRef(p)) {
+    gc_ptr(T* ptr = NULL) throw() : ptr(ptr) {
     }
 
     ~gc_ptr() throw() {
-        release();
     }
 
-    gc_ptr(const gc_ptr& r) throw() : countingRef(r.countingRef) {
-        acquire(r.countingRef);
+    gc_ptr(const gc_ptr& r) throw() : ptr(r.ptr) {
     }
 
     gc_ptr& operator=(const gc_ptr& r) throw() {
         if(this == &r)
             return *this;
-        acquire(r.countingRef);
-        release();
-        countingRef = r.countingRef;
+        ptr = r.ptr;
         return *this;
     }
 
     const bool operator==(const gc_ptr& r) const throw() {
         if (this == &r)
             return true;
-        if (countingRef == NULL)
-            return r.countingRef == NULL;
-        if (r.countingRef == NULL)
-            return false;
-        return countingRef-> ptr == r.countingRef->ptr;
+        return ptr == r.ptr;
     }
 
     const bool operator!=(const gc_ptr& r) const throw() {
-        return !this->operator ==(r);
+        return !this->operator==(r);
     }
 
     T& operator*() const throw() {
-        return *countingRef->ptr;
+        return *ptr;
     }
 
     T* operator->() const throw() {
-        return countingRef->ptr;
+        return ptr;
     }
 
     operator T*() const throw() {
-        return countingRef->ptr;
+        return ptr;
     }
 
-    template<typename X> friend std::ostream& operator<<(std::ostream&, const gc_ptr<X>&);
-
-private:
-    struct CountingRef {
-        T* ptr;
-        unsigned count;
-
-        CountingRef(T* p) throw() :
-            ptr(p), count(1) {
-        }
-    }* countingRef;
-
-    void acquire(CountingRef* ref) throw() {
-        if(ref)
-            gc_add_and_fetch(ref->count, (unsigned int)1);
-    }
-
-    void release() throw() {
-        if(countingRef) {
-            unsigned rc = gc_sub_and_fetch(countingRef->count, (unsigned int)1);
-            if(rc == 0) {
-                delete countingRef->ptr;
-                delete countingRef;
-            }
-        }
-    }
+    T* ptr;
 };
 
-template<typename T> std::ostream& operator<<(std::ostream& out, const gc_ptr<T>& p) {
-    return out << p.countingRef->ptr;
-}
-
 /**
- * Garbage collected pointer to an array.
+ * Garbage collected APR memory pool.
  */
-template<typename T> class gc_aptr {
+class gc_pool {
 public:
-    gc_aptr(T* p = 0) throw() : countingRef(p == 0? 0 : new CountingRef(p)) {
+    gc_pool() : p(NULL) {
     }
 
-    ~gc_aptr() throw() {
-        release();
+    gc_pool(apr_pool_t* p) : p(p) {
     }
 
-    gc_aptr(const gc_aptr& r) throw() : countingRef(r.countingRef) {
-        acquire(r.countingRef);
+    gc_pool(const gc_pool& pool) : p(pool.p) {
     }
 
-    gc_aptr& operator=(const gc_aptr& r) throw() {
-        if(this == &r)
+    gc_pool& operator=(const gc_pool& pool) {
+        if (this == &pool)
             return *this;
-        acquire(r.countingRef);
-        release();
-        countingRef = r.countingRef;
+        p = pool.p;
         return *this;
     }
 
-    const bool operator==(const gc_aptr& r) const throw() {
-        if (this == &r)
-            return true;
-        if (countingRef == NULL)
-            return r.countingRef == NULL;
-        if (r.countingRef == NULL)
-            return false;
-        return countingRef-> ptr == r.countingRef->ptr;
-    }
-
-    const bool operator!=(const gc_aptr& r) const throw() {
-        return !this->operator ==(r);
-    }
-
-    T& operator*() const throw() {
-        return *countingRef->ptr;
-    }
-
-    T* operator->() const throw() {
-        return countingRef->ptr;
-    }
-
-    operator T*() const throw() {
-        return countingRef->ptr;
+    operator apr_pool_t*() const {
+        return p;
     }
 
-    template<typename X> friend std::ostream& operator<<(std::ostream&, const gc_aptr<X>&);
-
 private:
-    struct CountingRef {
-        T* ptr;
-        unsigned count;
-
-        CountingRef(T* p) throw() :
-            ptr(p), count(1) {
-        }
-    }* countingRef;
-
-    void acquire(CountingRef* ref) throw() {
-        if(ref)
-            gc_add_and_fetch(ref->count, (unsigned int)1);
-    }
-
-    void release() throw() {
-        if(countingRef) {
-            unsigned rc = gc_sub_and_fetch(countingRef->count, (unsigned int)1);
-            if(rc == 0) {
-                delete[] countingRef->ptr;
-                delete countingRef;
-            }
-        }
-    }
-};
+    friend const bool destroy(gc_pool& pool);
+    friend class gc_global_pool_t;
+    friend class gc_scoped_pool;
 
-template<typename T> std::ostream& operator<<(std::ostream& out, const gc_aptr<T>& p) {
-    return out << p.countingRef->ptr;
-}
+    apr_pool_t* p;
+};
 
 /**
- * Garbage collected pointer to a reference counting object.
+ * Destroy a memory pool.
  */
-template<typename T> class gc_counting_ptr {
-public:
-    gc_counting_ptr(T* p = 0) throw() : ptr(p) {
-        acquire(p);
-    }
-
-    ~gc_counting_ptr() throw() {
-        release();
-    }
-
-    gc_counting_ptr(const gc_counting_ptr& r) throw() : ptr(r.ptr) {
-        acquire(ptr);
-    }
-
-    gc_counting_ptr& operator=(const gc_counting_ptr& r) throw() {
-        if(this == &r)
-            return *this;
-        acquire(r.ptr);
-        release();
-        ptr = r.ptr;
-        return *this;
-    }
-
-    const bool operator==(const gc_counting_ptr& r) const throw() {
-        if (this == &r)
-            return true;
-        return ptr == r.ptr;
-    }
-
-    const bool operator!=(const gc_counting_ptr& r) const throw() {
-        return !this->operator ==(r);
-    }
-
-    T& operator*() const throw() {
-        return *ptr;
-    }
-
-    T* operator->() const throw() {
-        return ptr;
-    }
-
-    operator T*() const throw() {
-        return ptr;
-    }
-
-    template<typename X> friend std::ostream& operator<<(std::ostream&, const gc_counting_ptr<X>&);
-
-private:
-    T* ptr;
-
-    void acquire(T* p) throw() {
-        if(p)
-            p->acquire();
-    }
-
-    void release() throw() {
-        if(ptr) {
-            if(ptr->release() == 0) {
-                delete ptr;
-            }
-        }
-    }
-};
-
-template<typename T> std::ostream& operator<<(std::ostream& out, const gc_counting_ptr<T>& p) {
-    return out << p.ptr;
+const bool destroy(gc_pool& pool) {
+    apr_pool_destroy(pool.p);
+    return true;
 }
 
 /**
- * Apache Portable Runtime library context
+ * Default global memory pool.
  */
-class APRContext {
+class gc_apr_context_t {
 public:
-    APRContext() {
+    gc_apr_context_t() {
         apr_initialize();
     }
-    ~APRContext() {
-        apr_terminate();
+    ~gc_apr_context_t() {
+        //apr_terminate();
     }
 };
 
-APRContext aprContext;
+gc_apr_context_t gc_apr_context;
 
-/**
- * Garbage collected memory pool, using an APR pool.
- */
-class gc_pool {
+class gc_global_pool_t : public gc_pool {
 public:
-    gc_pool() : aprPool(new APRPool) {
+    gc_global_pool_t() {
+        apr_pool_create(&p, NULL);
     }
 
-    operator apr_pool_t*() const {
-        return aprPool->p;
+    ~gc_global_pool_t() {
+        //apr_pool_destroy(p);
     }
+};
 
-private:
-    class APRPool {
-        friend class gc_pool;
-        friend class gc_counting_ptr<APRPool>;
-
-        unsigned int refCount;
-        apr_pool_t* p;
-
-        APRPool() : refCount(0) {
-            apr_pool_create(&p, NULL);
-        }
-
-        ~APRPool() {
-            apr_pool_destroy(p);
-        }
+gc_global_pool_t gc_global_pool;
 
-        unsigned int acquire() {
-            return gc_add_and_fetch(refCount, (unsigned int)1);
-        }
-
-        unsigned int release() {
-            return gc_sub_and_fetch(refCount, (unsigned int)1);
-        }
-    };
+/**
+ * Maintain a stack of memory pools.
+ */
+#ifdef _REENTRANT
+__thread
+#endif
+apr_pool_t* gc_pool_stack = NULL;
 
-    const gc_counting_ptr<APRPool> aprPool;
-};
+/**
+ * Return the current memory pool.
+ */
+apr_pool_t* gc_current_pool() {
+    apr_pool_t* p = gc_pool_stack;
+    if (p != NULL)
+        return p;
+    apr_pool_t* g = gc_global_pool;
+    gc_pool_stack = g;
+    return g;
+}
 
 /**
- * Garbage collected pointer to pooled memory.
+ * A memory pool scope, used to setup a scope in which a particular pool
+ * will be used for all allocations.
  */
-template<typename T> class gc_pool_ptr {
+class gc_scoped_pool : public gc_pool {
 public:
-    gc_pool_ptr(T* ptr = 0) throw() : ptr(ptr) {
-    }
-
-    ~gc_pool_ptr() throw() {
-    }
-
-    gc_pool_ptr(const gc_pool_ptr& r) throw() : ptr(r.ptr) {
-    }
-
-    gc_pool_ptr& operator=(const gc_pool_ptr& r) throw() {
-        if(this == &r)
-            return *this;
-        ptr = r.ptr;
-        return *this;
-    }
 
-    const bool operator==(const gc_pool_ptr& r) const throw() {
-        if (this == &r)
-            return true;
-        return ptr == r.ptr;
+    gc_scoped_pool() : gc_pool(NULL), prev(gc_current_pool()), owned(true) {
+        apr_pool_create(&p, NULL);
+        gc_pool_stack = p;
     }
 
-    const bool operator!=(const gc_pool_ptr& r) const throw() {
-        return !this->operator ==(r);
+    gc_scoped_pool(apr_pool_t* pool) : gc_pool(pool), prev(gc_current_pool()), owned(false) {
+        gc_pool_stack = p;
     }
 
-    T& operator*() const throw() {
-        return *ptr;
-    }
-
-    T* operator->() const throw() {
-        return ptr;
+    ~gc_scoped_pool() {
+        if (owned)
+            apr_pool_destroy(p);
+        if (prev != NULL)
+            gc_pool_stack = prev;
     }
 
-    operator T*() const throw() {
-        return ptr;
+private:
+    gc_scoped_pool(const unused gc_scoped_pool& pool) : gc_pool(pool.p), prev(NULL), owned(false) {
     }
 
-    template<typename X> friend std::ostream& operator<<(std::ostream&, const gc_pool_ptr<X>&);
-
-private:
-    T* ptr;
+    apr_pool_t* prev;
+    bool owned;
 };
 
-template<typename T> std::ostream& operator<<(std::ostream& out, const gc_pool_ptr<T>& p) {
-    return out << p.ptr;
-}
-
 /**
- * Cleanup function, called by the APR pool to cleanup registered resources.
- * Calls the allocated object's destructor.
+ * Allocates a pointer to an object allocated from a memory pool and
+ * register a cleanup callback for it.
  */
-template<typename T> apr_status_t gc_pool_cleanupCallback(void* v) {
+template<typename T> apr_status_t gc_pool_cleanup(void* v) {
     T* t = static_cast<T*>(v);
     t->~T();
     return APR_SUCCESS;
 }
 
-/**
- * Returns a pointer to an object allocated from a memory pool.
- */
-template<typename T> gc_pool_ptr<T> gc_pool_new(const gc_pool& mp) {
+template<typename T> T* gc_new(apr_pool_t* p) {
+    void* m = apr_palloc(p, sizeof(T));
+    apr_pool_cleanup_register(p, m, gc_pool_cleanup<T>, apr_pool_cleanup_null) ;
+    return static_cast<T*>(m);
+}
+
+template<typename T> T* gc_new() {
+    return gc_new<T>(gc_current_pool());
+}
+
+template<typename T> apr_status_t gc_pool_acleanup(void* v) {
+    int* m = static_cast<int*>(v);
+    int n = *m;
+    T* t = static_cast<T*>(m + 1);
+    for (int i = 0; i < n; i++, t++)
+        t->~T();
+    return APR_SUCCESS;
+}
+
+template<typename T> T* gc_anew(apr_pool_t* p, int n) {
+    int* m = static_cast<int*>(apr_palloc(p, sizeof(int) + sizeof(T[n])));
+    *m = n;
+    apr_pool_cleanup_register(p, m, gc_pool_acleanup<T>, apr_pool_cleanup_null) ;
+    return static_cast<T*>(m + 1);
+}
 
-    // Allocate memory from the pool
-    void* m = apr_palloc(mp, sizeof(T));
+template<typename T> T* gc_anew(int n) {
+    return gc_anew<T>(gc_current_pool(), n);
+}
 
-    // Register a cleanup callback
-    apr_pool_cleanup_register(mp, m, gc_pool_cleanupCallback<T>, apr_pool_cleanup_null) ;
+/**
+ * Allocate an array of chars.
+ */
+char* gc_cnew(apr_pool_t* p, int n) {
+    return static_cast<char*>(apr_palloc(p, n));
+}
 
-    // Run the requested type's constructor over the allocated memory
-    return new (m) T();
+char* gc_cnew(int n) {
+    return gc_cnew(gc_current_pool(), n);
 }
 
 }
+
 #endif /* tuscany_gc_hpp */

Modified: tuscany/sca-cpp/trunk/kernel/kernel-test.cpp
URL: http://svn.apache.org/viewvc/tuscany/sca-cpp/trunk/kernel/kernel-test.cpp?rev=895165&r1=895164&r2=895165&view=diff
==============================================================================
--- tuscany/sca-cpp/trunk/kernel/kernel-test.cpp (original)
+++ tuscany/sca-cpp/trunk/kernel/kernel-test.cpp Sat Jan  2 10:27:26 2010
@@ -24,12 +24,10 @@
  */
 
 #include <assert.h>
-#include <iostream>
-#include <string>
-#include <sstream>
+#include "string.hpp"
+#include "sstream.hpp"
 #include "function.hpp"
 #include "list.hpp"
-#include "slist.hpp"
 #include "tree.hpp"
 #include "value.hpp"
 #include "monad.hpp"
@@ -77,7 +75,10 @@
 
 bool testLambdaGC() {
     resetLambdaCounters();
-    testLambda();
+    {
+        gc_scoped_pool gc;
+        testLambda();
+    }
     assert(checkLambdaCounters());
     return true;
 }
@@ -87,18 +88,15 @@
 struct Element {
     int i;
 
-    Element() :
-        i(0) {
+    Element() : i(0) {
         countElements++;
     }
 
-    Element(int i) :
-        i(i) {
+    Element(int i) : i(i) {
         countElements++;
     }
 
-    Element(const Element& o) :
-        i(o.i) {
+    Element(const Element& o) : i(o.i) {
         countElements++;
     }
 
@@ -110,7 +108,7 @@
         return o.i == i;
     }
 };
-std::ostream& operator<<(std::ostream& out, const Element& v) {
+ostream& operator<<(ostream& out, const Element& v) {
     out << v.i ;
     return out;
 }
@@ -124,23 +122,14 @@
     return true;
 }
 
-bool testSet() {
-    list<int> l = mklist(1, 2, 3);
-    setCar(l, 4);
-    setCdr(l, mklist(5, 6));
-    assert(car(l) == 4);
-    assert(cadr(l) == 5);
-    assert(caddr(l) == 6);
-    assert(isNil(cdddr(l)));
-    return true;
-}
-
 bool testListGC() {
     resetLambdaCounters();
     resetListCounters();
     countElements = 0;
-    testCons();
-    testSet();
+    {
+        gc_scoped_pool gc;
+        testCons();
+    }
     assert(checkLambdaCounters());
     assert(checkListCounters());
     assert(countElements == 0);
@@ -148,13 +137,13 @@
 }
 
 bool testOut() {
-    std::ostringstream os1;
+    ostringstream os1;
     os1 << list<int> ();
-    assert(os1.str() == "()");
+    assert(str(os1) == "()");
 
-    std::ostringstream os2;
+    ostringstream os2;
     os2 << mklist(1, 2, 3);
-    assert(os2.str() == "(1 2 3)");
+    assert(str(os2) == "(1 2 3)");
     return true;
 }
 
@@ -180,10 +169,7 @@
     assert(car(cdr(cdr(append(mklist(1), mklist(2, 3))))) == 3);
     assert(isNil(cdr(cdr(cdr(append(mklist(1), mklist(2, 3)))))));
 
-    list<int> l;
-    l << 1 << 2 << 3;
-    assert(l == mklist(1, 2, 3));
-    assert(list<int>() << 1 << 2 << 3 == mklist(1, 2, 3));
+    assert(list<int>() + 1 + 2 + 3 == mklist(1, 2, 3));
     return true;
 }
 
@@ -196,7 +182,7 @@
         x(x), y(y) {
     }
 };
-std::ostream& operator<<(std::ostream& out, const Complex& v) {
+ostream& operator<<(ostream& out, const Complex& v) {
     out << "[" << v.x << ":" << v.y << "]";
     return out;
 }
@@ -266,9 +252,9 @@
 }
 
 bool testAssoc() {
-    const list<list<std::string> > l = mklist(mklist<std::string>("x", "X"), mklist<std::string>("a", "A"), mklist<std::string>("y", "Y"), mklist<std::string>("a", "AA"));
-    assert(assoc<std::string>("a", l) == mklist<std::string>("a", "A"));
-    assert(isNil(assoc<std::string>("z", l)));
+    const list<list<string> > l = mklist(mklist<string>("x", "X"), mklist<string>("a", "A"), mklist<string>("y", "Y"), mklist<string>("a", "AA"));
+    assert(assoc<string>("a", l) == mklist<string>("a", "A"));
+    assert(isNil(assoc<string>("z", l)));
 
     const list<list<value> > u = mklist(mklist<value>("x", "X"), mklist<value>("a", "A"), mklist<value>("y", "Y"), mklist<value>("a", "AA"));
     assert(assoc<value>("a", u) == mklist<value>("a", "A"));
@@ -279,21 +265,21 @@
 }
 
 bool testZip() {
-    const list<std::string> k = mklist<std::string>("x", "a", "y", "a");
-    const list<std::string> v = mklist<std::string>("X", "A", "Y", "AA");
-    const list<list<std::string> > z = mklist(k, v);
-    const list<list<std::string> > u = mklist(mklist<std::string>("x", "X"), mklist<std::string>("a", "A"), mklist<std::string>("y", "Y"), mklist<std::string>("a", "AA"));
+    const list<string> k = mklist<string>("x", "a", "y", "a");
+    const list<string> v = mklist<string>("X", "A", "Y", "AA");
+    const list<list<string> > z = mklist(k, v);
+    const list<list<string> > u = mklist(mklist<string>("x", "X"), mklist<string>("a", "A"), mklist<string>("y", "Y"), mklist<string>("a", "AA"));
     assert(zip(k, v) == u);
     assert(unzip(u) == z);
     return true;
 }
 
 bool testTokenize() {
-    assert(tokenize("/", "aaa/bbb/ccc/ddd") == mklist<std::string>("aaa", "bbb", "ccc", "ddd"));
-    assert(tokenize("/", "/bbb/ccc/ddd") == mklist<std::string>("", "bbb", "ccc", "ddd"));
-    assert(tokenize("/", "/bbb/ccc/") == mklist<std::string>("", "bbb", "ccc"));
-    assert(tokenize("/", "/bbb//ccc/") == mklist<std::string>("", "bbb", "", "ccc"));
-    assert(tokenize("/", "abc/def/") == mklist<std::string>("abc", "def"));
+    assert(tokenize("/", "aaa/bbb/ccc/ddd") == mklist<string>("aaa", "bbb", "ccc", "ddd"));
+    assert(tokenize("/", "/bbb/ccc/ddd") == mklist<string>("", "bbb", "ccc", "ddd"));
+    assert(tokenize("/", "/bbb/ccc/") == mklist<string>("", "bbb", "ccc"));
+    assert(tokenize("/", "/bbb//ccc/") == mklist<string>("", "bbb", "", "ccc"));
+    assert(tokenize("/", "abc/def/") == mklist<string>("abc", "def"));
     return true;
 }
 
@@ -336,13 +322,11 @@
     const list<value> v = mklist<value>(mklist<value>("x", "X"), mklist<value>("a", "A"), mklist<value>("y", "Y"));
     assert(cadr((list<list<value> >)value(v)) == mklist<value>("a", "A"));
 
-    const value pv(gc_ptr<value>(new value(1)));
+    const value pv(gc_ptr<value>(new (gc_new<value>()) value(1)));
     assert(*(gc_ptr<value>)pv == value(1));
 
-    const list<value> lpv = mklist<value>(gc_ptr<value>(new value(1)), gc_ptr<value>(new value(2)));
+    const list<value> lpv = mklist<value>(gc_ptr<value>(new (gc_new<value>()) value(1)), gc_ptr<value>(new (gc_new<value>()) value(2)));
     assert(*(gc_ptr<value>)car(lpv) == value(1));
-    *(gc_ptr<value>)cadr(lpv) = value(3);
-    assert(*(gc_ptr<value>)cadr(lpv) == value(3));
     return true;
 }
 
@@ -350,7 +334,10 @@
     resetLambdaCounters();
     resetListCounters();
     resetValueCounters();
-    testValue();
+    {
+        gc_scoped_pool gc;
+        testValue();
+    }
     assert(checkValueCounters());
     assert(checkLambdaCounters());
     assert(checkListCounters());
@@ -371,8 +358,8 @@
     return true;
 }
 
-const list<value> lta(const std::string& x) {
-    return mklist<value>(x.c_str(), (x + x).c_str());
+const list<value> lta(const string& x) {
+    return mklist<value>(c_str(x), c_str(x + x));
 }
 
 bool testTreeAssoc() {
@@ -425,7 +412,7 @@
 bool testCppPerf() {
     {
         const lambda<bool()> fml = fibMapPerf();
-        std::cout << "Fibonacci map test " << (time(fml, 1, 1) / 1000) << " ms" << std::endl;
+        cout << "Fibonacci map test " << (time(fml, 1, 1) / 1000) << " ms" << endl;
     }
 
     {
@@ -443,7 +430,7 @@
         };
 
         const lambda<bool()> nfml = nestedFibMapPerf(lambda<double(const double)>(nested::fib));
-        std::cout << "Nested Fibonacci map test " << (time(nfml, 1, 1) / 1000) << " ms" << std::endl;
+        cout << "Nested Fibonacci map test " << (time(nfml, 1, 1) / 1000) << " ms" << endl;
     }
     return true;
 }
@@ -490,26 +477,26 @@
     return true;
 }
 
-const failable<int, std::string> failableF(const int v) {
+const failable<int> failableF(const int v) {
     return v * 2;
 }
 
-const failable<int, std::string> failableG(const int v) {
+const failable<int> failableG(const int v) {
     return v * 3;
 }
 
-const failable<int, std::string> failableH(const int v) {
+const failable<int> failableH(const int v) {
     return failableF(v) >> failableG;
 }
 
 bool testFailableMonad() {
-    const failable<int, std::string> m(2);
+    const failable<int> m(2);
     assert(m >> failableF == failableF(2));
-    assert((m >> success<int, std::string>()) == m);
+    assert((m >> success<int, string>()) == m);
     assert(m >> failableF >> failableG == m >> failableH);
 
-    std::cout << "Failable monad test... ";
-    failable<int, std::string> ooops = mkfailure<int, std::string>("test");
+    cout << "Failable monad test... " << endl;
+    failable<int> ooops = mkfailure<int>("test");
     assert(reason(ooops) == "test");
     assert(ooops >> failableF >> failableG == ooops);
     return true;
@@ -553,14 +540,14 @@
 }
 
 bool testDynLib() {
-    const failable<lib, std::string> dl(dynlib(".libs/libdynlib-test" + dynlibExt));
+    const failable<lib> dl(dynlib(string(".libs/libdynlib-test") + dynlibExt));
     assert(hasContent(dl));
-    const failable<lambda<int(const int)>, std::string> sq(dynlambda<int(const int)>("csquare", content(dl)));
+    const failable<lambda<int(const int)>> sq(dynlambda<int(const int)>("csquare", content(dl)));
     assert(hasContent(sq));
     lambda<int(const int)> l(content(sq));
     assert(l(2) == 4);
 
-    const failable<lambda<lambda<int(const int)>()>, std::string> sql(dynlambda<lambda<int(const int)>()>("csquarel", content(dl)));
+    const failable<lambda<lambda<int(const int)>()>> sql(dynlambda<lambda<int(const int)>()>("csquarel", content(dl)));
     assert(hasContent(sql));
     lambda<lambda<int(const int)>()> ll(content(sql));
     assert(ll()(3) == 9);
@@ -570,12 +557,11 @@
 }
 
 int main() {
-    std::cout << "Testing..." << std::endl;
+    tuscany::cout << "Testing..." << tuscany::endl;
 
     tuscany::testLambda();
     tuscany::testLambdaGC();
     tuscany::testCons();
-    tuscany::testSet();
     tuscany::testListGC();
     tuscany::testOut();
     tuscany::testEquals();
@@ -603,7 +589,7 @@
     tuscany::testStateMonad();
     tuscany::testDynLib();
 
-    std::cout << "OK" << std::endl;
+    tuscany::cout << "OK" << tuscany::endl;
 
     return 0;
 }

Modified: tuscany/sca-cpp/trunk/kernel/list.hpp
URL: http://svn.apache.org/viewvc/tuscany/sca-cpp/trunk/kernel/list.hpp?rev=895165&r1=895164&r2=895165&view=diff
==============================================================================
--- tuscany/sca-cpp/trunk/kernel/list.hpp (original)
+++ tuscany/sca-cpp/trunk/kernel/list.hpp Sat Jan  2 10:27:26 2010
@@ -26,9 +26,9 @@
  * Simple list functions.
  */
 
-#include <string>
-#include <sstream>
-#include <iostream>
+#include <assert.h>
+#include "string.hpp"
+#include "fstream.hpp"
 #include "function.hpp"
 #include "debug.hpp"
 
@@ -56,28 +56,33 @@
 }
 
 bool printListCounters() {
-    std::cout << "countLists " << countLists << std::endl;
-    std::cout << "countELists " << countELists << std::endl;
-    std::cout << "countILists " << countILists << std::endl;
-    std::cout << "countCLists " << countCLists << std::endl;
+    cout << "countLists " << countLists << endl;
+    cout << "countELists " << countELists << endl;
+    cout << "countILists " << countILists << endl;
+    cout << "countCLists " << countCLists << endl;
     return true;
 }
 
-#define debug_watchList() do { \
-        this->watch = watchList(*this); \
-    } while (0)
-
 #else
 
 #define resetListCounters()
 #define checkListCounters() true
 #define printListCounters()
 
+#endif
+
+#ifdef _DEBUG_WATCH
+
+#define debug_watchList() do { \
+        this->watch = watchList(*this); \
+    } while (0)
+
+#else
+
 #define debug_watchList();
 
 #endif
 
-
 /**
  * A car/cdr lisp-like pair, base structure to construct lists.
  */
@@ -91,28 +96,26 @@
         debug_watchList();
     }
 
-    list(const T car, const lambda<list<T>()>& cdr) :
-        car(car), cdr(cdr) {
+    list(const T car, const lambda<list<T>()>& cdr) : car(car), cdr(cdr) {
         debug_inc(countLists);
         debug_inc(countILists);
         debug_watchList();
     }
 
-    list(const list& p) :
-        car(p.car), cdr(p.cdr) {
+    list(const list& p) : car(p.car), cdr(p.cdr) {
         debug_inc(countLists);
         debug_inc(countCLists);
-#ifdef _DEBUG
+#ifdef _DEBUG_WATCH
         watch = p.watch;
 #endif
     }
 
-    const list& operator=(const list<T>& p) {
+    const list<T>& operator=(const list<T>& p) {
         if(this == &p)
             return *this;
         car = p.car;
         cdr = p.cdr;
-#ifdef _DEBUG
+#ifdef _DEBUG_WATCH
         watch = p.watch;
 #endif
         return *this;
@@ -172,41 +175,34 @@
         return (list<list<T> >)T(*this);
     }
 
-    list<T>& operator<<(const T& v) {
-        *this = append(*this, mklist(v));
-        return *this;
-    }
+private:
+#ifdef _DEBUG_WATCH
+    template<typename X> friend const string watchList(const list<X>& p);
+    string watch;
+#endif
 
     template<typename X> friend const bool isNil(const list<X>& p);
     template<typename X> friend const X car(const list<X>& p);
     template<typename X> friend const list<X> cdr(const list<X>& p);
-    template<typename X> friend const bool setCar(list<X>& p, const X& car);
-    template<typename X> friend const bool setCdr(list<X>& p, const list<X>& cdr);
-    template<typename X> friend const bool setCdr(list<X>& p, const lambda<list<X>()>& cdr);
-
-private:
-#ifdef _DEBUG
-    template<typename X> friend const std::string watchList(const list<X>& p);
-    std::string watch;
-#endif
 
     T car;
     lambda<list<T>()> cdr;
 };
 
-#ifdef _DEBUG
+#ifdef _DEBUG_WATCH
 
 /**
  * Debug utility used to write the contents of a list to a string, easier
  * to watch than the list itself in a debugger.
  */
-template<typename T> const std::string watchList(const list<T>& p) {
+template<typename T> const string watchList(const list<T>& p) {
     if(isNil(p))
         return "()";
-    std::ostringstream os;
+    ostringstream<string::npos> os;
     os << "(" << car(p) << " ...)";
-    return os.str();
+    return str(os);
 }
+
 #endif
 
 /**
@@ -219,14 +215,14 @@
 /**
  * Write a list to an output stream.
  */
-template<typename T> std::ostream& writeHelper(std::ostream& out, const list<T>& l) {
+template<typename T> ostream& writeHelper(ostream& out, const list<T>& l) {
     if (isNil(l))
         return out;
     out << " " << car(l);
     return writeHelper(out, cdr(l));
 }
 
-template<typename T> std::ostream& operator<<(std::ostream& out, const list<T>& l) {
+template<typename T> ostream& operator<<(ostream& out, const list<T>& l) {
     if(isNil(l))
         return out << "()";
     out << "(" << car(l);
@@ -305,6 +301,8 @@
  * Returns the car of a list.
  */
 template<typename T> const T car(const list<T>& p) {
+    // Abort if trying to access the car of a nil list
+    assert(!isNil(p.cdr));
     return p.car;
 }
 
@@ -316,31 +314,6 @@
 }
 
 /**
- * Sets the car of a list.
- */
-template<typename T> const bool setCar(list<T>& p, const T& car) {
-    p.car = car;
-    return true;
-}
-
-/**
- * Sets the cdr of a list.
- */
-template<typename T> const bool setCdr(list<T>& p, const list<T>& c) {
-    p.cdr = result(c);
-    return true;
-}
-
-/**
- * Sets the cdr of a list to a lambda function.
- */
-template<typename T> const bool setCdr(list<T>& p, const lambda<list<T>()>& cdr) {
-    p.cdr = cdr;
-    return true;
-}
-
-
-/**
  * Returns the car of the cdr of a list.
  */
 template<typename T> const T cadr(const list<T>& p) {
@@ -419,6 +392,17 @@
 }
 
 /**
+ * Append a value to a list.
+ */
+template<typename T> const list<T> operator+(const list<T>& l, const T& v) {
+    return append(l, mklist(v));
+}
+
+template<typename T, typename V> const list<T> operator+(const list<T>& l, const V& v) {
+    return append(l, mklist<T>(v));
+}
+
+/**
  * Map a lambda function on a list.
  */
 template<typename T, typename R> const list<R> map(const lambda<R(const T)>& f, const list<T>& p) {

Added: tuscany/sca-cpp/trunk/kernel/mem-test.cpp
URL: http://svn.apache.org/viewvc/tuscany/sca-cpp/trunk/kernel/mem-test.cpp?rev=895165&view=auto
==============================================================================
--- tuscany/sca-cpp/trunk/kernel/mem-test.cpp (added)
+++ tuscany/sca-cpp/trunk/kernel/mem-test.cpp Sat Jan  2 10:27:26 2010
@@ -0,0 +1,162 @@
+/*
+ * 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.
+ */
+
+/* $Rev$ $Date$ */
+
+/**
+ * Test memory allocation functions.
+ */
+
+#include <assert.h>
+#include "stream.hpp"
+#include "string.hpp"
+#include "gc.hpp"
+#include "function.hpp"
+#include "perf.hpp"
+
+namespace tuscany {
+
+int countElements = 0;
+int maxElements = 0;
+
+class Element {
+public:
+    Element() : i(0) {
+        countElements++;
+        if (countElements > maxElements)
+            maxElements = countElements;
+    }
+
+    Element(int i) : i(i) {
+        countElements++;
+        if (countElements > maxElements)
+            maxElements = countElements;
+    }
+
+    Element(const Element& o) : i(o.i) {
+        countElements++;
+        if (countElements > maxElements)
+            maxElements = countElements;
+    }
+
+    ~Element() {
+        countElements--;
+    }
+
+    const bool operator==(const Element& o) const {
+        return o.i == i;
+    }
+
+private:
+    friend ostream& operator<<(ostream& out, const Element& v);
+
+    int i;
+    char c[20];
+};
+
+ostream& operator<<(ostream& out, const Element& v) {
+    out << v.i ;
+    return out;
+}
+
+bool poolAlloc(Element** p, const int count) {
+    if (count == 0)
+        return true;
+    p[count - 1] = new (gc_new<Element>()) Element();
+    return poolAlloc(p, count - 1);
+};
+
+bool poolFree(Element** p, const int count) {
+    if (count == 0)
+        return true;
+    // Do nothing to free the element, but cycle through them just
+    // to get a fair comparison with the other memory alloc tests
+    return poolFree(p, count - 1);
+};
+
+struct poolAllocPerf {
+    const int n;
+    Element** p;
+    poolAllocPerf(const int n) : n(n), p(new Element*[n]) {
+    }
+    const bool operator()() const {
+        gc_scoped_pool gc;
+        poolAlloc(p, n);
+        return true;
+    }
+};
+
+bool testPoolAllocPerf() {
+    const int count = 100000;
+    const lambda<bool()> pl = poolAllocPerf(count);
+    maxElements = 0;
+    cout << "Memory pool alloc test " << (time(pl, 1, 1) / count) << " ms" << endl;
+    assert(countElements == 0);
+    assert(maxElements == count);
+    return true;
+}
+
+bool stdAlloc(Element** p, const int count) {
+    if (count == 0)
+        return true;
+    p[count - 1] = new Element();
+    return stdAlloc(p, count - 1);
+};
+
+bool stdFree(Element** p, const int count) {
+    if (count == 0)
+        return true;
+    delete p[count -1];
+    return stdFree(p, count - 1);
+};
+
+struct stdAllocPerf {
+    const int n;
+    Element** p;
+    stdAllocPerf(const int n) : n(n), p(new Element*[n]) {
+    }
+    const bool operator()() const {
+        stdAlloc(p, n);
+        stdFree(p, n);
+        return true;
+    }
+};
+
+bool testStdAllocPerf() {
+    const int count = 100000;
+    const lambda<bool()> sl = stdAllocPerf(count);
+    maxElements = 0;
+    cout << "Memory standard alloc test " << (time(sl, 1, 1) / count) << " ms" << endl;
+    assert(countElements == 0);
+    assert(maxElements == count);
+    return true;
+}
+
+}
+
+int main() {
+    tuscany::cout << "Testing..." << tuscany::endl;
+
+    tuscany::testPoolAllocPerf();
+    tuscany::testStdAllocPerf();
+
+    tuscany::cout << "OK" << tuscany::endl;
+
+    return 0;
+}

Modified: tuscany/sca-cpp/trunk/kernel/monad.hpp
URL: http://svn.apache.org/viewvc/tuscany/sca-cpp/trunk/kernel/monad.hpp?rev=895165&r1=895164&r2=895165&view=diff
==============================================================================
--- tuscany/sca-cpp/trunk/kernel/monad.hpp (original)
+++ tuscany/sca-cpp/trunk/kernel/monad.hpp Sat Jan  2 10:27:26 2010
@@ -26,11 +26,10 @@
  * Simple monad implementations.
  */
 
-#include <string>
-#include <iostream>
-
 #include "function.hpp"
 #include "debug.hpp"
+#include "string.hpp"
+#include "stream.hpp"
 
 namespace tuscany
 {
@@ -70,7 +69,7 @@
 /**
  * Write an identity monad to a stream.
  */
-template<typename V> std::ostream& operator<<(std::ostream& out, const id<V>& m) {
+template<typename V> ostream& operator<<(ostream& out, const id<V>& m) {
     out << content(m);
     return out;
 }
@@ -148,7 +147,7 @@
 /**
  * Write a maybe monad to a stream.
  */
-template<typename V> std::ostream& operator<<(std::ostream& out, const maybe<V>& m) {
+template<typename V> ostream& operator<<(ostream& out, const maybe<V>& m) {
     if (!hasContent(m)) {
         out << "nothing";
         return out;
@@ -203,7 +202,7 @@
  * To get the value in the monad, just cast it to the value type.
  * To get the failure in the monad, cast it to the failure type.
  */
-template<typename V, typename F> class failable {
+template<typename V, typename F = string> class failable {
 public:
     failable() : hasv(false) {
     }
@@ -211,22 +210,7 @@
     failable(const V& v) : hasv(true), v(v) {
     }
 
-    failable(const failable<V, F>& m) : hasv(m.hasv) {
-        if (hasv)
-            v = m.v;
-        else
-            f = m.f;
-    }
-
-    const failable<V, F>& operator=(const failable<V, F>& m) {
-        if(this == &m)
-            return *this;
-        hasv = m.hasv;
-        if (hasv)
-            v = m.v;
-        else
-            f = m.f;
-        return *this;
+    failable(const failable<V, F>& m) : hasv(m.hasv), v(m.v), f(m.f) {
     }
 
     const bool operator!=(const failable<V, F>& m) const {
@@ -242,23 +226,28 @@
     }
 
 private:
-    bool hasv;
-    V v;
-    F f;
-
     failable(const bool hasv, const F& f) : hasv(hasv), f(f) {
     }
 
+    // Prevent mutation
+    const failable<V, F>& operator=(const failable<V, F>& m) {
+        return *this;
+    }
+
     template<typename A, typename B> friend const bool hasContent(const failable<A, B>& m);
     template<typename A, typename B> friend const A content(const failable<A, B>& m);
     template<typename A, typename B> friend const B reason(const failable<A, B>& m);
     template<typename A, typename B> friend const failable<A, B> mkfailure(const B& f);
+
+    bool hasv;
+    V v;
+    F f;
 };
 
 /**
  * Write a failable monad to a stream.
  */
-template<typename V, typename F> std::ostream& operator<<(std::ostream& out, const failable<V, F>& m) {
+template<typename V, typename F> ostream& operator<<(ostream& out, const failable<V, F>& m) {
     if (!hasContent(m)) {
         out << reason(m);
         return out;
@@ -286,6 +275,10 @@
     return failable<V, F>(false, f);
 }
 
+template<typename V> const failable<V> mkfailure(const char* f) {
+    return mkfailure<V, string>(string(f));
+}
+
 template<typename V, typename F> const lambda<failable<V, F>(const V)> failure() {
     return mkfailure<V, F>;
 }
@@ -421,7 +414,7 @@
 /**
  * Write a state monad to a stream.
  */
-template<typename S, typename V> std::ostream& operator<<(std::ostream& out, const state<S, V>& m) {
+template<typename S, typename V> ostream& operator<<(ostream& out, const state<S, V>& m) {
     const S s = m;
     const V v = m;
     out << '(' << s << ' ' << v << ')';

Modified: tuscany/sca-cpp/trunk/kernel/parallel-test.cpp
URL: http://svn.apache.org/viewvc/tuscany/sca-cpp/trunk/kernel/parallel-test.cpp?rev=895165&r1=895164&r2=895165&view=diff
==============================================================================
--- tuscany/sca-cpp/trunk/kernel/parallel-test.cpp (original)
+++ tuscany/sca-cpp/trunk/kernel/parallel-test.cpp Sat Jan  2 10:27:26 2010
@@ -24,8 +24,8 @@
  */
 
 #include <assert.h>
-#include <iostream>
-#include <string>
+#include "stream.hpp"
+#include "string.hpp"
 #include "function.hpp"
 #include "list.hpp"
 #include "perf.hpp"
@@ -33,6 +33,8 @@
 
 namespace tuscany {
 
+#ifdef _REENTRANT
+
 int inci = 0;
 
 struct incPerf {
@@ -84,25 +86,25 @@
     const int count = 100000;
     {
         const lambda<bool()> l = incPerf();
-        std::cout << "Non-atomic inc test " << time(l, 1000, count) << " ms" << std::endl;
+        cout << "Non-atomic inc test " << time(l, 1000, count) << " ms" << endl;
         assert(inci == count + 1000);
     }
     {
         const lambda<bool()> l = addAndFetchPerf();
-        std::cout << "Atomic inc test " << time(l, 1000, count) << " ms" << std::endl;
+        cout << "Atomic inc test " << time(l, 1000, count) << " ms" << endl;
         assert(addi == count + 1000);
     }
     {
         pthread_mutex_t mutex;
         pthread_mutex_init(&mutex, NULL);
         const lambda<bool()> l = mutexPerf(&mutex);
-        std::cout << "Locked inc test " << time(l, 1000, count) << " ms" << std::endl;
+        cout << "Locked inc test " << time(l, 1000, count) << " ms" << endl;
         assert(muxi == count + 1000);
         pthread_mutex_destroy(&mutex);
     }
     {
         const lambda<bool()> l = tlsPerf();
-        std::cout << "Thread local inc test " << time(l, 1000, count) << " ms" << std::endl;
+        cout << "Thread local inc test " << time(l, 1000, count) << " ms" << endl;
         assert(tlsi == count + 1000);
     }
     return true;
@@ -114,38 +116,51 @@
     return x * x;
 }
 
+bool checkResults(const list<future<int> > r, int i) {
+    if (isNil(r))
+        return true;
+    assert(car(r) == i * i);
+    checkResults(cdr(r), i + 1);
+    return true;
+}
+
+const list<future<int> > submitSquares(worker& w, const int max, const int i) {
+    if (i == max)
+        return list<future<int> >();
+    const lambda<int()> func = curry(lambda<int(const int)> (mtsquare), i);
+    return cons(submit(w, func), submitSquares(w, max, i + 1));
+}
+
 bool testWorker() {
-    worker w(10);
+    worker w(20);
     {
         const lambda<int()> func = curry(lambda<int(const int)> (mtsquare), 2);
         assert(submit(w, func) == 4);
     }
     {
-        const int max = 10;
-
-        list<future<int> > r;
-        for(int i = 0; i < max; i++) {
-            const lambda<int()> func = curry(lambda<int(const int)> (mtsquare), i);
-            r = cons(submit(w, func), r);
-        }
-        for(int i = max - 1; i >= 0; i--) {
-            assert(car(r) == i * i);
-            r = cdr(r);
-        }
+        const int max = 20;
+        const list<future<int> > r(submitSquares(w, max, 0));
+        checkResults(r, 0);
     }
     shutdown(w);
     return true;
 }
 
+#endif
+
 }
 
 int main() {
-    std::cout << "Testing..." << std::endl;
+    tuscany::cout << "Testing..." << tuscany::endl;
 
+#ifdef _REENTRANT
     tuscany::testAtomicPerf();
     tuscany::testWorker();
+#else
+    tuscany::cout << "Skipped multi-thread tests" << tuscany::endl;
+#endif
 
-    std::cout << "OK" << std::endl;
+    tuscany::cout << "OK" << tuscany::endl;
 
     return 0;
 }

Modified: tuscany/sca-cpp/trunk/kernel/parallel.hpp
URL: http://svn.apache.org/viewvc/tuscany/sca-cpp/trunk/kernel/parallel.hpp?rev=895165&r1=895164&r2=895165&view=diff
==============================================================================
--- tuscany/sca-cpp/trunk/kernel/parallel.hpp (original)
+++ tuscany/sca-cpp/trunk/kernel/parallel.hpp Sat Jan  2 10:27:26 2010
@@ -26,13 +26,18 @@
  * Simple parallel work execution functions.
  */
 
+#ifdef _REENTRANT
 #include <pthread.h>
 #include <sys/syscall.h>
+#include <unistd.h>
+#endif
 
 #include "function.hpp"
 
 namespace tuscany {
 
+#ifdef _REENTRANT
+
 /**
  * Returns the current thread id.
  */
@@ -48,8 +53,7 @@
 private:
     template<typename X> class futureValue {
     public:
-        futureValue() :
-            refCount(0), hasValue(false) {
+        futureValue() : hasValue(false) {
             pthread_mutex_init(&valueMutex, NULL);
             pthread_cond_init(&valueCond, NULL);
         }
@@ -59,14 +63,6 @@
             pthread_cond_destroy(&valueCond);
         }
 
-        unsigned int acquire() {
-            return __sync_add_and_fetch(&refCount, (unsigned int)1);
-        }
-
-        unsigned int release() {
-            return __sync_sub_and_fetch(&refCount, (unsigned int)1);
-        }
-
         bool set(const T& v) {
             pthread_mutex_lock(&valueMutex);
             if(hasValue) {
@@ -91,33 +87,28 @@
         }
 
     private:
-        unsigned refCount;
         pthread_mutex_t valueMutex;
         pthread_cond_t valueCond;
         bool hasValue;
         X value;
     };
 
-    gc_counting_ptr<futureValue<T> > fvalue;
+    gc_ptr<futureValue<T> > fvalue;
 
     template<typename X> friend const X get(const future<X>& f);
     template<typename X> friend bool set(const future<X>& f, const X& v);
 
 public:
-    future() : fvalue(new futureValue<T>()) {
-        //std::cout << "future() threadId " << threadId() << "\n";
+    future() : fvalue(new (gc_new<futureValue<T> >()) futureValue<T>()) {
     }
 
     ~future() {
-        //std::cout << "~future() threadId " << threadId() << "\n";
     }
 
     future(const future& f) : fvalue(f.fvalue) {
-        //std::cout << "future(const future& f) threadId " << threadId() << "\n";
     }
 
     const future& operator=(const future& f) {
-        //std::cout << "future::operator=(const future& f) threadId " << threadId() << "\n";
         if (&f == this)
             return *this;
         fvalue = f.fvalue;
@@ -132,7 +123,6 @@
     operator const T() const {
         return fvalue->get();
     }
-
 };
 
 /**
@@ -140,7 +130,7 @@
  */
 template<typename T> class queue {
 public:
-    queue(int max) : max(max), size(0), tail(0), head(0), values(new T[max]) {
+    queue(int max) : max(max), size(0), tail(0), head(0), values(new (gc_anew<T>(max)) T[max]) {
         pthread_mutex_init(&mutex, NULL);
         pthread_cond_init(&full, NULL);
         pthread_cond_init(&empty, NULL);
@@ -160,7 +150,7 @@
     pthread_mutex_t mutex;
     pthread_cond_t full;
     pthread_cond_t empty;
-    gc_aptr<T> values;
+    gc_ptr<T> values;
 
     template<typename X> friend const int enqueue(queue<X>& q, const X& v);
     template<typename X> friend const X dequeue(queue<X>& q);
@@ -280,5 +270,7 @@
     return true;
 }
 
+#endif
+
 }
 #endif /* tuscany_parallel_hpp */



Mime
View raw message