diff options
author | jsdelfino <jsdelfino@13f79535-47bb-0310-9956-ffa450edef68> | 2011-08-28 02:50:02 +0000 |
---|---|---|
committer | jsdelfino <jsdelfino@13f79535-47bb-0310-9956-ffa450edef68> | 2011-08-28 02:50:02 +0000 |
commit | 29edc4e6fb2c8fb3a93aac36d9666efd21b92bd0 (patch) | |
tree | 2b1998d904a16cdce69f69041c89cc56d474e69e /sca-cpp/trunk/modules | |
parent | d93ec216d63aed8ff2f08b4cba7de965dc14639c (diff) |
Implement a portable alternative to __thread and get the HTTP and SQLDB components and the Auth modules working with the HTTPD multithreaded event MPM.
git-svn-id: http://svn.us.apache.org/repos/asf/tuscany@1162472 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'sca-cpp/trunk/modules')
-rw-r--r-- | sca-cpp/trunk/modules/js/eval.hpp | 6 | ||||
-rw-r--r-- | sca-cpp/trunk/modules/oauth/mod-oauth1.cpp | 23 | ||||
-rw-r--r-- | sca-cpp/trunk/modules/oauth/mod-oauth2.cpp | 27 | ||||
-rw-r--r-- | sca-cpp/trunk/modules/scheme/primitive.hpp | 11 | ||||
-rw-r--r-- | sca-cpp/trunk/modules/server/mod-eval.hpp | 5 |
5 files changed, 58 insertions, 14 deletions
diff --git a/sca-cpp/trunk/modules/js/eval.hpp b/sca-cpp/trunk/modules/js/eval.hpp index f18c3e41c9..69863c9831 100644 --- a/sca-cpp/trunk/modules/js/eval.hpp +++ b/sca-cpp/trunk/modules/js/eval.hpp @@ -43,6 +43,7 @@ #include "value.hpp" #include "element.hpp" #include "monad.hpp" +#include "parallel.hpp" namespace tuscany { namespace js { @@ -106,9 +107,10 @@ JSClass jsGlobalClass = { "global", JSCLASS_GLOBAL_FLAGS, * Represents a JavaScript context. Maintains one context per thread. */ #ifdef WANT_THREADS -__thread -#endif +perthread_ptr<JSContext> jsContext; +#else ::JSContext* jsContext = NULL; +#endif class JSContext { public: diff --git a/sca-cpp/trunk/modules/oauth/mod-oauth1.cpp b/sca-cpp/trunk/modules/oauth/mod-oauth1.cpp index 252d5c5ee0..ca7f562b60 100644 --- a/sca-cpp/trunk/modules/oauth/mod-oauth1.cpp +++ b/sca-cpp/trunk/modules/oauth/mod-oauth1.cpp @@ -36,6 +36,7 @@ extern "C" { #include "tree.hpp" #include "value.hpp" #include "monad.hpp" +#include "parallel.hpp" #include "../json/json.hpp" #include "../http/httpd.hpp" #include "../http/http.hpp" @@ -65,7 +66,7 @@ public: list<list<value> > appkeys; list<string> mcaddrs; memcache::MemCached mc; - http::CURLSession cs; + perthread_ptr<http::CURLSession> cs; }; /** @@ -476,6 +477,24 @@ int postConfig(apr_pool_t* p, unused apr_pool_t* plog, unused apr_pool_t* ptemp, } /** + * Lambda function that creates a new CURL session. + */ +class newsession { +public: + newsession(const string& ca, const string& cert, const string& key) : ca(ca), cert(cert), key(key) { + } + + const gc_ptr<http::CURLSession> operator()() const { + return new (gc_new<http::CURLSession>()) http::CURLSession(ca, cert, key, ""); + } + +private: + const string ca; + const string cert; + const string key; +}; + +/** * Child process initialization. */ void childInit(apr_pool_t* p, server_rec* s) { @@ -494,7 +513,7 @@ void childInit(apr_pool_t* p, server_rec* s) { sc.mc = *(new (gc_new<memcache::MemCached>()) memcache::MemCached(sc.mcaddrs)); // Setup a CURL session - sc.cs = *(new (gc_new<http::CURLSession>()) http::CURLSession(sc.ca, sc.cert, sc.key, "")); + sc.cs = perthread_ptr<http::CURLSession>(lambda<gc_ptr<http::CURLSession>()>(newsession(sc.ca, sc.cert, sc.key))); // Merge the updated configuration into the virtual hosts postConfigMerge(sc, s->next); diff --git a/sca-cpp/trunk/modules/oauth/mod-oauth2.cpp b/sca-cpp/trunk/modules/oauth/mod-oauth2.cpp index 2e4b2e5b80..41d722f1e2 100644 --- a/sca-cpp/trunk/modules/oauth/mod-oauth2.cpp +++ b/sca-cpp/trunk/modules/oauth/mod-oauth2.cpp @@ -31,6 +31,7 @@ #include "tree.hpp" #include "value.hpp" #include "monad.hpp" +#include "parallel.hpp" #include "../http/httpd.hpp" #include "../http/http.hpp" #include "../http/openauth.hpp" @@ -59,7 +60,7 @@ public: list<list<value> > appkeys; list<string> mcaddrs; memcache::MemCached mc; - http::CURLSession cs; + perthread_ptr<http::CURLSession> cs; }; /** @@ -199,7 +200,7 @@ const failable<int> access_token(const list<list<value> >& args, request_rec* r, const list<list<value> > targs = mklist<list<value> >(mklist<value>("client_id", car(appkey)), mklist<value>("redirect_uri", httpd::escape(redir)), mklist<value>("client_secret", cadr(appkey)), code); const string turi = httpd::unescape(cadr(tok)) + string("?") + http::queryString(targs); debug(turi, "modoauth2::access_token::tokenuri"); - const failable<value> tr = http::get(turi, sc.cs); + const failable<value> tr = http::get(turi, *(sc.cs)); if (!hasContent(tr)) return mkfailure<int>(reason(tr)); debug(tr, "modoauth2::access_token::response"); @@ -213,7 +214,7 @@ const failable<int> access_token(const list<list<value> >& args, request_rec* r, const list<list<value> > iargs = mklist<list<value> >(tv); const string iuri = httpd::unescape(cadr(info)) + string("?") + http::queryString(iargs); debug(iuri, "modoauth2::access_token::infouri"); - const failable<value> profres = http::get(iuri, sc.cs); + const failable<value> profres = http::get(iuri, *(sc.cs)); if (!hasContent(profres)) return mkfailure<int>("Couldn't retrieve user info"); debug(content(profres), "modoauth2::access_token::info"); @@ -328,6 +329,24 @@ int postConfig(apr_pool_t* p, unused apr_pool_t* plog, unused apr_pool_t* ptemp, } /** + * Lambda function that creates a new CURL session. + */ +class newsession { +public: + newsession(const string& ca, const string& cert, const string& key) : ca(ca), cert(cert), key(key) { + } + + const gc_ptr<http::CURLSession> operator()() const { + return new (gc_new<http::CURLSession>()) http::CURLSession(ca, cert, key, ""); + } + +private: + const string ca; + const string cert; + const string key; +}; + +/** * Child process initialization. */ void childInit(apr_pool_t* p, server_rec* s) { @@ -346,7 +365,7 @@ void childInit(apr_pool_t* p, server_rec* s) { sc.mc = *(new (gc_new<memcache::MemCached>()) memcache::MemCached(sc.mcaddrs)); // Setup a CURL session - sc.cs = *(new (gc_new<http::CURLSession>()) http::CURLSession(sc.ca, sc.cert, sc.key, "")); + sc.cs = perthread_ptr<http::CURLSession>(lambda<gc_ptr<http::CURLSession>()>(newsession(sc.ca, sc.cert, sc.key))); // Merge the updated configuration into the virtual hosts postConfigMerge(sc, s->next); diff --git a/sca-cpp/trunk/modules/scheme/primitive.hpp b/sca-cpp/trunk/modules/scheme/primitive.hpp index 899d6f83da..59aee12073 100644 --- a/sca-cpp/trunk/modules/scheme/primitive.hpp +++ b/sca-cpp/trunk/modules/scheme/primitive.hpp @@ -30,6 +30,7 @@ #include "function.hpp" #include "list.hpp" #include "value.hpp" +#include "parallel.hpp" namespace tuscany { namespace scheme { @@ -39,14 +40,16 @@ const value quoteSymbol("'"); const value lambdaSymbol("lambda"); #ifdef WANT_THREADS -__thread -#endif +perthread_ptr<ostream> displayOutStream; +#else ostream* displayOutStream = NULL; +#endif #ifdef WANT_THREADS -__thread -#endif +perthread_ptr<ostream> logOutStream; +#else ostream* logOutStream = NULL; +#endif const bool setupDisplay(ostream& out) { displayOutStream = &out; diff --git a/sca-cpp/trunk/modules/server/mod-eval.hpp b/sca-cpp/trunk/modules/server/mod-eval.hpp index b9b11e06dc..34cdfdbb29 100644 --- a/sca-cpp/trunk/modules/server/mod-eval.hpp +++ b/sca-cpp/trunk/modules/server/mod-eval.hpp @@ -100,9 +100,10 @@ const failable<value> failableResult(const list<value>& v) { * Store current HTTP request for access from property and proxy lambda functions. */ #ifdef WANT_THREADS -__thread -#endif +perthread_ptr<request_rec> currentRequest; +#else request_rec* currentRequest = NULL; +#endif class ScopedRequest { public: |