@@ -205,42 +205,6 @@ set(CPPCMS_LIBRARY_PREFIX ${CMAKE_SHARED_LIBRARY_PREFIX}) | |||
# Atomic API tests | |||
# | |||
check_cxx_source_compiles( | |||
"#include <windows.h> | |||
int main() { volatile long v=0; return InterlockedCompareExchange(&v,1,0); }" | |||
HAVE_WIN32_INTERLOCKED) | |||
check_cxx_source_compiles( | |||
"int main() { volatile long v=0; return __sync_add_and_fetch(&v,1); }" | |||
HAVE_SYNC_FETCH_AND_ADD) | |||
check_cxx_source_compiles( | |||
"#include <bits/atomicity.h> | |||
using __gnu_cxx::__exchange_and_add; | |||
int main(){ volatile int x=0; return __exchange_and_add(&x,1);}" | |||
HAVE_GCC_BITS_EXCHANGE_AND_ADD) | |||
check_cxx_source_compiles( | |||
"#include <ext/atomicity.h> | |||
using __gnu_cxx::__exchange_and_add; | |||
int main(){ volatile int x=0; return __exchange_and_add(&x,1);}" | |||
HAVE_GCC_EXT_EXCHANGE_AND_ADD) | |||
check_cxx_source_compiles( | |||
"#include <sys/types.h> | |||
#include <machine/atomic.h> | |||
int main() { volatile unsigned v=0; return atomic_fetchadd_int(&v,1); }" | |||
HAVE_FREEBSD_ATOMIC) | |||
check_cxx_source_compiles( | |||
"#include <atomic.h> | |||
int main() { volatile unsigned v=0; return atomic_add_int_nv(&v,1); }" | |||
HAVE_SOLARIS_ATOMIC) | |||
check_cxx_source_compiles( | |||
"#include <libkern/OSAtomic.h> | |||
int main() { volatile int v=0; return OSAtomicAdd32(1,&v); }" | |||
HAVE_MAC_OS_X_ATOMIC) | |||
check_cxx_source_compiles( | |||
"#include <string> | |||
@@ -339,7 +303,6 @@ endif(USE_EXTERNAL_BOOST) | |||
set(CPPCMS_PUBLIC_HEADERS | |||
application.h | |||
applications_pool.h | |||
atomic_counter.h | |||
base64.h | |||
base_content.h | |||
base_view.h | |||
@@ -400,7 +363,6 @@ set(CPPCMS_SOURCES | |||
base_view.cpp | |||
views_pool.cpp | |||
internal_file_server.cpp | |||
atomic_counter.cpp | |||
json.cpp | |||
encoding.cpp | |||
form.cpp | |||
@@ -631,7 +593,6 @@ add_executable(cppcms_config_find_param cppcms_config_find_param.cpp json.cpp) | |||
set(ALL_TESTS | |||
form_test | |||
proto_test | |||
atomic_test | |||
encryptor_test | |||
storage_test | |||
cache_backend_test | |||
@@ -706,7 +667,6 @@ install(PROGRAMS cppcms_tmpl_cc cppcms_run | |||
set(CNF "${CMAKE_CURRENT_SOURCE_DIR}/tests") | |||
add_test(atomic_test atomic_test) | |||
add_test(base64_test base64_test) | |||
add_test(encryptor_test encryptor_test) | |||
add_test(storage_test storage_test) | |||
@@ -23,7 +23,6 @@ | |||
#include "service.h" | |||
#include "cppcms_error.h" | |||
#include "url_dispatcher.h" | |||
#include "intrusive_ptr.h" | |||
#include "applications_pool.h" | |||
#include "http_response.h" | |||
#include "views_pool.h" | |||
@@ -49,7 +48,7 @@ struct application::data { | |||
{ | |||
} | |||
cppcms::service *service; | |||
intrusive_ptr<http::context> conn; | |||
booster::intrusive_ptr<http::context> conn; | |||
int pool_id; | |||
url_dispatcher url; | |||
std::vector<application *> managed_children; | |||
@@ -94,7 +93,7 @@ url_dispatcher &application::dispatcher() | |||
return d->url; | |||
} | |||
intrusive_ptr<http::context> application::get_context() | |||
booster::intrusive_ptr<http::context> application::get_context() | |||
{ | |||
return root()->d->conn; | |||
} | |||
@@ -106,9 +105,9 @@ http::context &application::context() | |||
return *root()->d->conn; | |||
} | |||
intrusive_ptr<http::context> application::release_context() | |||
booster::intrusive_ptr<http::context> application::release_context() | |||
{ | |||
intrusive_ptr<http::context> ptr=root()->d->conn; | |||
booster::intrusive_ptr<http::context> ptr=root()->d->conn; | |||
assign_context(0); | |||
return ptr; | |||
} | |||
@@ -119,7 +118,7 @@ bool application::is_asynchronous() | |||
return pool_id() < 0; | |||
} | |||
void application::assign_context(intrusive_ptr<http::context> conn) | |||
void application::assign_context(booster::intrusive_ptr<http::context> conn) | |||
{ | |||
root()->d->conn=conn; | |||
} | |||
@@ -220,43 +219,46 @@ void application::recycle() | |||
assign_context(0); | |||
} | |||
void intrusive_ptr_add_ref(application *app) | |||
{ | |||
++(app->root()->refs_); | |||
} | |||
// REMEMBER THIS IS CALLED FROM DESTRUCTOR!!! | |||
void intrusive_ptr_release(application *app) | |||
{ | |||
// it is called in destructors... So be very careful | |||
try { | |||
app = app->root(); | |||
long refs=--(app->refs_); | |||
if(refs > 0) | |||
return; | |||
cppcms::service &service=app->service(); | |||
try { | |||
app->recycle(); | |||
} | |||
catch(...) { | |||
if(app->pool_id() < 0) { | |||
service.applications_pool().put(app); | |||
} | |||
else | |||
delete app; | |||
throw; | |||
} | |||
} // cppcms | |||
service.applications_pool().put(app); | |||
// return the application to pool... or delete it if "pooled" | |||
} | |||
catch(...) | |||
namespace booster { | |||
void intrusive_ptr_add_ref(cppcms::application *app) | |||
{ | |||
// FIXME LOG IT? | |||
++(app->root()->refs_); | |||
} | |||
} | |||
// REMEMBER THIS IS CALLED FROM DESTRUCTOR!!! | |||
void intrusive_ptr_release(cppcms::application *app) | |||
{ | |||
// it is called in destructors... So be very careful | |||
try { | |||
app = app->root(); | |||
long refs=--(app->refs_); | |||
if(refs > 0) | |||
return; | |||
cppcms::service &service=app->service(); | |||
try { | |||
app->recycle(); | |||
} | |||
catch(...) { | |||
if(app->pool_id() < 0) { | |||
service.applications_pool().put(app); | |||
} | |||
else | |||
delete app; | |||
throw; | |||
} | |||
} // cppcms | |||
service.applications_pool().put(app); | |||
// return the application to pool... or delete it if "pooled" | |||
} | |||
catch(...) | |||
{ | |||
// FIXME LOG IT? | |||
} | |||
} | |||
} // booster |
@@ -21,12 +21,22 @@ | |||
#include "defs.h" | |||
#include <booster/noncopyable.h> | |||
#include "atomic_counter.h" | |||
#include <booster/hold_ptr.h> | |||
#include "intrusive_ptr.h" | |||
#include <booster/atomic_counter.h> | |||
#include <booster/intrusive_ptr.h> | |||
#include <string> | |||
namespace cppcms { | |||
class application; | |||
} | |||
namespace booster { | |||
void CPPCMS_API intrusive_ptr_add_ref(cppcms::application *p); | |||
void CPPCMS_API intrusive_ptr_release(cppcms::application *p); | |||
} | |||
namespace cppcms { | |||
class service; | |||
class url_dispatcher; | |||
@@ -45,15 +55,6 @@ namespace cppcms { | |||
class value; | |||
} | |||
/// | |||
/// Increase reference count of the p->root(). | |||
/// | |||
void CPPCMS_API intrusive_ptr_add_ref(application *p); | |||
/// | |||
/// Decrease reference count of the p->root(). If reference count is 0, and application is asynchronous: | |||
/// destroy it, otherwise recycle it to the application pool for future use. | |||
/// | |||
void CPPCMS_API intrusive_ptr_release(application *p); | |||
/// | |||
/// \brief application class is the base class for all user created applications. | |||
@@ -230,19 +231,19 @@ namespace cppcms { | |||
/// | |||
/// Note: because application hierarchy shared same context, it affects all classes in it. | |||
/// | |||
intrusive_ptr<http::context> release_context(); | |||
booster::intrusive_ptr<http::context> release_context(); | |||
/// | |||
/// Get reference counted pointer to the http::context | |||
/// | |||
intrusive_ptr<http::context> get_context(); | |||
booster::intrusive_ptr<http::context> get_context(); | |||
/// | |||
/// Set context to the application. The application gets shared ownership on the context. | |||
/// | |||
/// Note: because application hierarchy shared same context, it affects all classes in it. | |||
/// | |||
void assign_context(intrusive_ptr<http::context> conn); | |||
void assign_context(booster::intrusive_ptr<http::context> conn); | |||
/// | |||
/// Returns true if current application was created as asynchronous application. | |||
@@ -276,10 +277,10 @@ namespace cppcms { | |||
application *parent_; | |||
application *root_; | |||
atomic_counter refs_; | |||
booster::atomic_counter refs_; | |||
friend class applications_pool; | |||
friend void intrusive_ptr_add_ref(application *p); | |||
friend void intrusive_ptr_release(application *p); | |||
friend void booster::intrusive_ptr_add_ref(application *p); | |||
friend void booster::intrusive_ptr_release(application *p); | |||
}; | |||
} // cppcms | |||
@@ -26,13 +26,7 @@ | |||
#include <vector> | |||
#include "config.h" | |||
#include <booster/regex.h> | |||
#ifdef CPPCMS_USE_EXTERNAL_BOOST | |||
# include <boost/shared_ptr.hpp> | |||
#else // Internal Boost | |||
# include <cppcms_boost/shared_ptr.hpp> | |||
namespace boost = cppcms_boost; | |||
#endif | |||
#include <booster/shared_ptr.h> | |||
#include <booster/thread.h> | |||
namespace cppcms { | |||
@@ -109,8 +103,8 @@ namespace cppcms { | |||
}; | |||
struct applications_pool::data { | |||
std::vector<boost::shared_ptr<app_data> > apps; | |||
typedef std::map<application *,boost::shared_ptr<long_running_app_data> > long_running_aps_type; | |||
std::vector<booster::shared_ptr<app_data> > apps; | |||
typedef std::map<application *,booster::shared_ptr<long_running_app_data> > long_running_aps_type; | |||
long_running_aps_type long_running_aps; | |||
int limit; | |||
booster::recursive_mutex mutex; | |||
@@ -136,47 +130,47 @@ std::string applications_pool::script_name() | |||
void applications_pool::mount(std::auto_ptr<factory> aps) | |||
{ | |||
lock_it lock(d->mutex); | |||
d->apps.push_back(boost::shared_ptr<app_data>(new app_data(script_name(),aps))); | |||
d->apps.push_back(booster::shared_ptr<app_data>(new app_data(script_name(),aps))); | |||
} | |||
void applications_pool::mount(std::auto_ptr<factory> aps,std::string path_info,int select) | |||
{ | |||
lock_it lock(d->mutex); | |||
d->apps.push_back(boost::shared_ptr<app_data>(new app_data(script_name(),path_info,select,aps))); | |||
d->apps.push_back(booster::shared_ptr<app_data>(new app_data(script_name(),path_info,select,aps))); | |||
} | |||
void applications_pool::mount(std::auto_ptr<factory> aps,std::string script_name) | |||
{ | |||
lock_it lock(d->mutex); | |||
d->apps.push_back(boost::shared_ptr<app_data>(new app_data(script_name,aps))); | |||
d->apps.push_back(booster::shared_ptr<app_data>(new app_data(script_name,aps))); | |||
} | |||
void applications_pool::mount(std::auto_ptr<factory> aps,std::string script_name,std::string path_info,int select) | |||
{ | |||
lock_it lock(d->mutex); | |||
d->apps.push_back(boost::shared_ptr<app_data>(new app_data(script_name,path_info,select,aps))); | |||
d->apps.push_back(booster::shared_ptr<app_data>(new app_data(script_name,path_info,select,aps))); | |||
} | |||
void applications_pool::mount(intrusive_ptr<application> app) | |||
void applications_pool::mount(booster::intrusive_ptr<application> app) | |||
{ | |||
lock_it lock(d->mutex); | |||
d->long_running_aps[app.get()]= | |||
boost::shared_ptr<long_running_app_data>(new long_running_app_data(script_name())); | |||
booster::shared_ptr<long_running_app_data>(new long_running_app_data(script_name())); | |||
} | |||
void applications_pool::mount(intrusive_ptr<application> app,std::string path_info,int select) | |||
void applications_pool::mount(booster::intrusive_ptr<application> app,std::string path_info,int select) | |||
{ | |||
lock_it lock(d->mutex); | |||
d->long_running_aps[app.get()]= | |||
boost::shared_ptr<long_running_app_data>(new long_running_app_data(script_name(),path_info,select)); | |||
booster::shared_ptr<long_running_app_data>(new long_running_app_data(script_name(),path_info,select)); | |||
} | |||
void applications_pool::mount(intrusive_ptr<application> app,std::string script_name) | |||
void applications_pool::mount(booster::intrusive_ptr<application> app,std::string script_name) | |||
{ | |||
lock_it lock(d->mutex); | |||
d->long_running_aps[app.get()]= | |||
boost::shared_ptr<long_running_app_data>(new long_running_app_data(script_name)); | |||
booster::shared_ptr<long_running_app_data>(new long_running_app_data(script_name)); | |||
} | |||
void applications_pool::mount(intrusive_ptr<application> app,std::string script_name,std::string path_info,int select) | |||
void applications_pool::mount(booster::intrusive_ptr<application> app,std::string script_name,std::string path_info,int select) | |||
{ | |||
lock_it lock(d->mutex); | |||
d->long_running_aps[app.get()]= | |||
boost::shared_ptr<long_running_app_data>(new long_running_app_data(script_name,path_info,select)); | |||
booster::shared_ptr<long_running_app_data>(new long_running_app_data(script_name,path_info,select)); | |||
} | |||
bool applications_pool::matched(basic_app_data &data,std::string script_name,std::string path_info,std::string &matched) | |||
@@ -215,7 +209,7 @@ bool applications_pool::matched(basic_app_data &data,std::string script_name,std | |||
} | |||
intrusive_ptr<application> applications_pool::get(std::string script_name,std::string path_info,std::string &m) | |||
booster::intrusive_ptr<application> applications_pool::get(std::string script_name,std::string path_info,std::string &m) | |||
{ | |||
lock_it lock(d->mutex); | |||
for(unsigned i=0;i<d->apps.size();i++) { | |||
@@ -223,19 +217,19 @@ intrusive_ptr<application> applications_pool::get(std::string script_name,std::s | |||
continue; | |||
if(d->apps[i]->pool.empty()) { | |||
intrusive_ptr<application> app=(*d->apps[i]->factory)(*srv_).release(); | |||
booster::intrusive_ptr<application> app=(*d->apps[i]->factory)(*srv_).release(); | |||
app->pool_id(i); | |||
return app; | |||
} | |||
d->apps[i]->size--; | |||
intrusive_ptr<application> app(*(d->apps[i]->pool.begin())); | |||
booster::intrusive_ptr<application> app(*(d->apps[i]->pool.begin())); | |||
d->apps[i]->pool.erase(app.get()); | |||
return app; | |||
} | |||
for(data::long_running_aps_type::iterator p=d->long_running_aps.begin();p!=d->long_running_aps.end();++p){ | |||
if(!matched(*p->second,script_name,path_info,m)) | |||
continue; | |||
intrusive_ptr<application> app=p->first; | |||
booster::intrusive_ptr<application> app=p->first; | |||
return app; | |||
} | |||
return 0; | |||
@@ -22,7 +22,7 @@ | |||
#include "defs.h" | |||
#include <booster/noncopyable.h> | |||
#include <booster/hold_ptr.h> | |||
#include "intrusive_ptr.h" | |||
#include <booster/intrusive_ptr.h> | |||
#include <memory> | |||
#include <string> | |||
@@ -101,7 +101,7 @@ namespace cppcms { | |||
/// | |||
/// This member function is thread safe. | |||
/// | |||
void mount(intrusive_ptr<application> app); | |||
void mount(booster::intrusive_ptr<application> app); | |||
/// | |||
/// Mount an asynchronous application \a app for processing of requests for which CGI PATH_INFO | |||
/// matches the regular expression \a path_info. The marched part of an regular expression \a select would | |||
@@ -109,7 +109,7 @@ namespace cppcms { | |||
/// | |||
/// This member function is thread safe. | |||
/// | |||
void mount(intrusive_ptr<application> app,std::string path_info,int select); | |||
void mount(booster::intrusive_ptr<application> app,std::string path_info,int select); | |||
/// | |||
/// Mount an asynchronous application \a app for processing of requests for which CGI SCRIPT_NAME exactly | |||
/// matches \a script_name parameter. And PATH_INFO patches regular expression \a path_info. | |||
@@ -117,7 +117,7 @@ namespace cppcms { | |||
/// | |||
/// This member function is thread safe. | |||
/// | |||
void mount(intrusive_ptr<application> app,std::string script_name); | |||
void mount(booster::intrusive_ptr<application> app,std::string script_name); | |||
/// | |||
/// Mount an asynchronous application \a app for processing of requests for which CGI SCRIPT_NAME exactly | |||
/// matches \a script_name parameter. And PATH_INFO patches regular expression \a path_info. | |||
@@ -125,12 +125,12 @@ namespace cppcms { | |||
/// | |||
/// This member function is thread safe. | |||
/// | |||
void mount(intrusive_ptr<application> app,std::string script_name,std::string path_info, int select); | |||
void mount(booster::intrusive_ptr<application> app,std::string script_name,std::string path_info, int select); | |||
/// | |||
/// Internal API - do not use it directly | |||
/// | |||
intrusive_ptr<application> get(std::string script_name,std::string path_info,std::string &match); | |||
booster::intrusive_ptr<application> get(std::string script_name,std::string path_info,std::string &match); | |||
/// | |||
/// Internal API - do not use it directly | |||
/// | |||
@@ -1,167 +0,0 @@ | |||
/////////////////////////////////////////////////////////////////////////////// | |||
// | |||
// Copyright (C) 2008-2010 Artyom Beilis (Tonkikh) <artyomtnk@yahoo.com> | |||
// | |||
// This program is free software: you can redistribute it and/or modify | |||
// it under the terms of the GNU Lesser General Public License as published by | |||
// the Free Software Foundation, either version 3 of the License, or | |||
// (at your option) any later version. | |||
// | |||
// This program is distributed in the hope that it will be useful, | |||
// but WITHOUT ANY WARRANTY; without even the implied warranty of | |||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |||
// GNU Lesser General Public License for more details. | |||
// | |||
// You should have received a copy of the GNU Lesser General Public License | |||
// along with this program. If not, see <http://www.gnu.org/licenses/>. | |||
// | |||
/////////////////////////////////////////////////////////////////////////////// | |||
#define CPPCMS_SOURCE | |||
#include "atomic_counter.h" | |||
#include "config.h" | |||
#include <string.h> | |||
#if defined(HAVE_WIN32_INTERLOCKED) | |||
# include <windows.h> | |||
# define cppcms_atomic_set(p,v) ((p)->l=v) | |||
long static cppcms_atomic_add_and_fetch_impl(volatile long *v,long d) | |||
{ | |||
long old,prev; | |||
do{ | |||
old = *v; | |||
prev = InterlockedCompareExchange(v,old+d,old); | |||
} | |||
while(prev != old); | |||
return old+d; | |||
} | |||
# define cppcms_atomic_add_and_fetch(p,d) cppcms_atomic_add_and_fetch_impl(&(p)->l,d) | |||
#elif defined(HAVE_FREEBSD_ATOMIC) | |||
# include <sys/types.h> | |||
# include <machine/atomic.h> | |||
# define cppcms_atomic_set(p,v) ((p)->ui=v) | |||
# define cppcms_atomic_add_and_fetch(p,d) (atomic_fetchadd_int(&(p)->ui,d) + d) | |||
#elif defined(HAVE_SOLARIS_ATOMIC) | |||
# include <atomic.h> | |||
# define cppcms_atomic_set(p,v) ((p)->ui=v) | |||
# define cppcms_atomic_add_and_fetch(p,d) (atomic_add_int_nv(&(p)->ui,d)) | |||
#elif defined(HAVE_MAC_OS_X_ATOMIC) | |||
# include <libkern/OSAtomic.h> | |||
# define cppcms_atomic_set(p,v) ((p)->i=v) | |||
# define cppcms_atomic_add_and_fetch(p,d) (OSAtomicAdd32(d,&(p)->i)) | |||
#elif defined HAVE_SYNC_FETCH_AND_ADD | |||
# define cppcms_atomic_set(p,v) ((p)->l=v) | |||
# define cppcms_atomic_add_and_fetch(p,d) ( __sync_add_and_fetch(&(p)->i,d) ) | |||
# elif defined(HAVE_GCC_BITS_EXCHANGE_AND_ADD) | |||
# include <bits/atomicity.h> | |||
using __gnu_cxx::__exchange_and_add; | |||
# define cppcms_atomic_set(p,v) ((p)->i=v) | |||
# define cppcms_atomic_add_and_fetch(p,d) ( __exchange_and_add(&(p)->i,d)+d ) | |||
#elif defined(HAVE_GCC_EXT_EXCHANGE_AND_ADD) | |||
# include <ext/atomicity.h> | |||
using __gnu_cxx::__exchange_and_add; | |||
# define cppcms_atomic_set(p,v) ((p)->i=v) | |||
# define cppcms_atomic_add_and_fetch(p,d) ( __exchange_and_add(&(p)->i,d)+d ) | |||
#else // Failing back to pthreads | |||
# include <pthread.h> | |||
# define CPPCMS_PTHREAD_ATOMIC | |||
#endif | |||
namespace cppcms { | |||
#if !defined(CPPCMS_PTHREAD_ATOMIC) | |||
atomic_counter::atomic_counter(long value) | |||
{ | |||
memset(&value_,0,sizeof(value_)); | |||
mutex_ = 0; | |||
cppcms_atomic_set(&value_,value); | |||
} | |||
atomic_counter::~atomic_counter() | |||
{ | |||
} | |||
long atomic_counter::inc() | |||
{ | |||
return cppcms_atomic_add_and_fetch( &value_, 1 ); | |||
} | |||
long atomic_counter::dec() | |||
{ | |||
return cppcms_atomic_add_and_fetch( &value_, -1 ); | |||
} | |||
long atomic_counter::get() const | |||
{ | |||
return cppcms_atomic_add_and_fetch( &value_, 0 ); | |||
} | |||
#else | |||
#define MUTEX (reinterpret_cast<pthread_mutex_t *>(mutex_)) | |||
atomic_counter::atomic_counter(long value) | |||
{ | |||
mutex_ = new pthread_mutex_t; | |||
pthread_mutex_init(MUTEX,0); | |||
value_.l=value; | |||
} | |||
atomic_counter::~atomic_counter() | |||
{ | |||
pthread_mutex_destroy(MUTEX); | |||
delete MUTEX; | |||
mutex_ = 0; | |||
} | |||
long atomic_counter::inc() | |||
{ | |||
pthread_mutex_lock(MUTEX); | |||
long result= ++value_.l; | |||
pthread_mutex_unlock(MUTEX); | |||
return result; | |||
} | |||
long atomic_counter::dec() | |||
{ | |||
pthread_mutex_lock(MUTEX); | |||
long result= --value_.l; | |||
pthread_mutex_unlock(MUTEX); | |||
return result; | |||
} | |||
long atomic_counter::get() const | |||
{ | |||
pthread_mutex_lock(MUTEX); | |||
long result= value_.l; | |||
pthread_mutex_unlock(MUTEX); | |||
return result; | |||
} | |||
#endif | |||
} // cppcms | |||
@@ -1,94 +0,0 @@ | |||
/////////////////////////////////////////////////////////////////////////////// | |||
// | |||
// Copyright (C) 2008-2010 Artyom Beilis (Tonkikh) <artyomtnk@yahoo.com> | |||
// | |||
// This program is free software: you can redistribute it and/or modify | |||
// it under the terms of the GNU Lesser General Public License as published by | |||
// the Free Software Foundation, either version 3 of the License, or | |||
// (at your option) any later version. | |||
// | |||
// This program is distributed in the hope that it will be useful, | |||
// but WITHOUT ANY WARRANTY; without even the implied warranty of | |||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |||
// GNU Lesser General Public License for more details. | |||
// | |||
// You should have received a copy of the GNU Lesser General Public License | |||
// along with this program. If not, see <http://www.gnu.org/licenses/>. | |||
// | |||
/////////////////////////////////////////////////////////////////////////////// | |||
#ifndef CPPCMS_ATOMIC_COUNT_H | |||
#define CPPCMS_ATOMIC_COUNT_H | |||
#include "defs.h" | |||
namespace cppcms { | |||
/// | |||
/// \brief Atomic counter is a class that allows perform counting in thread safe way. | |||
/// | |||
/// It is mainly used for reference counting. Under Windows it uses Interlocked API, under | |||
/// other platforms it used built-in atomic operations or fails back to pthreads locking implementation. | |||
/// | |||
/// Notes: | |||
/// | |||
/// - This counter is not safe for use in process shared memory, when pthreads fall-back is used | |||
/// - Under POSIX platform pthread_mutex_t is always present in order to make sure that we can implement | |||
/// or remove pthread fall-back at any point not affecting ABI | |||
/// | |||
class CPPCMS_API atomic_counter { | |||
public: | |||
/// | |||
/// Create a counter with initial value v | |||
/// | |||
explicit atomic_counter( long v ); | |||
~atomic_counter(); | |||
/// | |||
/// Increment and return the result after increment atomically | |||
/// | |||
long operator++() | |||
{ | |||
return inc(); | |||
} | |||
/// | |||
/// Decrement and return the result after decrement atomically | |||
/// | |||
long operator--() | |||
{ | |||
return dec(); | |||
} | |||
/// | |||
/// Return current value - atomically | |||
/// | |||
operator long() const | |||
{ | |||
return get(); | |||
} | |||
private: | |||
long inc(); | |||
long dec(); | |||
long get() const; | |||
atomic_counter(atomic_counter const &); | |||
atomic_counter & operator=(atomic_counter const &); | |||
mutable union { | |||
int i; | |||
unsigned ui; | |||
long l; | |||
unsigned long ul; | |||
long long ll; | |||
unsigned long long ull; | |||
} value_; | |||
// Is actually used for platforms without lock | |||
// it would not be used when atomic operations | |||
// available | |||
void *mutex_; | |||
}; | |||
} // cppcms | |||
#endif | |||
@@ -22,7 +22,7 @@ | |||
#include <string> | |||
#include <set> | |||
#include "defs.h" | |||
#include "intrusive_ptr.h" | |||
#include <booster/intrusive_ptr.h> | |||
#include "cstdint.h" | |||
namespace cppcms { | |||
@@ -46,15 +46,18 @@ namespace cppcms { | |||
} | |||
}; | |||
} // impl | |||
} //cppcms | |||
namespace booster { | |||
inline void intrusive_ptr_add_ref(impl::base_cache *ptr) | |||
inline void intrusive_ptr_add_ref(cppcms::impl::base_cache *ptr) | |||
{ | |||
ptr->add_ref(); | |||
} | |||
inline void intrusive_ptr_release(impl::base_cache *ptr) | |||
inline void intrusive_ptr_release(cppcms::impl::base_cache *ptr) | |||
{ | |||
if(ptr && ptr->del_ref()) | |||
delete ptr; | |||
} | |||
} // cppcms | |||
} // booster | |||
#endif |
@@ -24,7 +24,7 @@ | |||
#include "defs.h" | |||
#include <booster/noncopyable.h> | |||
#include "intrusive_ptr.h" | |||
#include <booster/intrusive_ptr.h> | |||
#include <booster/hold_ptr.h> | |||
#include "cstdint.h" | |||
@@ -269,7 +269,7 @@ namespace cppcms { | |||
booster::hold_ptr<data> d; | |||
http::context *context_; | |||
std::set<std::string> triggers_; | |||
intrusive_ptr<impl::base_cache> cache_module_; | |||
booster::intrusive_ptr<impl::base_cache> cache_module_; | |||
uint32_t page_compression_used_ : 1; | |||
uint32_t reserved : 31; | |||
@@ -18,7 +18,7 @@ | |||
/////////////////////////////////////////////////////////////////////////////// | |||
#define CPPCMS_SOURCE | |||
#include "tcp_cache_client.h" | |||
#include "atomic_counter.h" | |||
#include <booster/atomic_counter.h> | |||
#include <booster/thread.h> | |||
@@ -26,7 +26,7 @@ namespace cppcms { | |||
namespace impl { | |||
class cache_over_ip : public base_cache { | |||
public: | |||
cache_over_ip(std::vector<std::string> ips,std::vector<int> ports,intrusive_ptr<base_cache> l1) : | |||
cache_over_ip(std::vector<std::string> ips,std::vector<int> ports,booster::intrusive_ptr<base_cache> l1) : | |||
ips_(ips), | |||
ports_(ports), | |||
l1_(l1), | |||
@@ -126,15 +126,15 @@ namespace impl { | |||
booster::thread_specific_ptr<tcp_cache> tcp_; | |||
std::vector<std::string> ips_; | |||
std::vector<int> ports_; | |||
intrusive_ptr<base_cache> l1_; | |||
atomic_counter refs_; | |||
booster::intrusive_ptr<base_cache> l1_; | |||
booster::atomic_counter refs_; | |||
}; | |||
intrusive_ptr<base_cache> CPPCMS_API | |||
booster::intrusive_ptr<base_cache> CPPCMS_API | |||
tcp_cache_factory( std::vector<std::string> const &ips, | |||
std::vector<int> const &ports, | |||
intrusive_ptr<base_cache> l1) | |||
booster::intrusive_ptr<base_cache> l1) | |||
{ | |||
return new cache_over_ip(ips,ports,l1); | |||
} | |||
@@ -19,17 +19,17 @@ | |||
#ifndef CPPCMS_CACHE_OVER_IP_H | |||
#define CPPCMS_CACHE_OVER_IP_H | |||
#include "defs.h" | |||
#include "intrusive_ptr.h" | |||
#include <booster/intrusive_ptr.h> | |||
#include "base_cache.h" | |||
#include <string> | |||
#include <vector> | |||
namespace cppcms { | |||
namespace impl { | |||
intrusive_ptr<base_cache> CPPCMS_API | |||
booster::intrusive_ptr<base_cache> CPPCMS_API | |||
tcp_cache_factory( std::vector<std::string> const &ips, | |||
std::vector<int> const &ports, | |||
intrusive_ptr<base_cache> l1); | |||
booster::intrusive_ptr<base_cache> l1); | |||
} | |||
} | |||
@@ -27,7 +27,7 @@ | |||
namespace cppcms { | |||
struct cache_pool::data { | |||
intrusive_ptr<impl::base_cache> module; | |||
booster::intrusive_ptr<impl::base_cache> module; | |||
}; | |||
cache_pool::cache_pool(json::value const &settings) : | |||
@@ -65,7 +65,7 @@ cache_pool::cache_pool(json::value const &settings) : | |||
throw cppcms_error("Invalid settings in cache.tcp.ports or cache.tcp.ips"); | |||
} | |||
intrusive_ptr<impl::base_cache> l1=d->module; | |||
booster::intrusive_ptr<impl::base_cache> l1=d->module; | |||
d->module=impl::tcp_cache_factory(ips,ports,l1); | |||
} | |||
} | |||
@@ -74,7 +74,7 @@ cache_pool::~cache_pool() | |||
{ | |||
} | |||
intrusive_ptr<impl::base_cache> cache_pool::get() | |||
booster::intrusive_ptr<impl::base_cache> cache_pool::get() | |||
{ | |||
return d->module; | |||
} | |||
@@ -21,7 +21,7 @@ | |||
#include "defs.h" | |||
#include <booster/noncopyable.h> | |||
#include "intrusive_ptr.h" | |||
#include <booster/intrusive_ptr.h> | |||
#include <booster/hold_ptr.h> | |||
namespace cppcms { | |||
@@ -32,7 +32,7 @@ namespace cppcms { | |||
public: | |||
cache_pool(json::value const &settings); | |||
~cache_pool(); | |||
intrusive_ptr<impl::base_cache> get(); | |||
booster::intrusive_ptr<impl::base_cache> get(); | |||
private: | |||
struct data; | |||
booster::hold_ptr<data> d; | |||
@@ -149,7 +149,7 @@ int main(int argc,char **argv) | |||
{ | |||
params par(argc,argv); | |||
cppcms::intrusive_ptr<cppcms::impl::base_cache> cache; | |||
booster::intrusive_ptr<cppcms::impl::base_cache> cache; | |||
//auto_ptr<session_server_storage> storage; | |||
if(par.en_cache) | |||
@@ -398,13 +398,13 @@ public: | |||
}; // mem cache | |||
intrusive_ptr<base_cache> thread_cache_factory(unsigned items) | |||
booster::intrusive_ptr<base_cache> thread_cache_factory(unsigned items) | |||
{ | |||
return new mem_cache<thread_settings>(items); | |||
} | |||
#ifndef CPPCMS_WIN32 | |||
intrusive_ptr<base_cache> process_cache_factory(size_t memory) | |||
booster::intrusive_ptr<base_cache> process_cache_factory(size_t memory) | |||
{ | |||
process_settings::init(memory); | |||
return new mem_cache<process_settings>(0); | |||
@@ -19,14 +19,14 @@ | |||
#ifndef THREAD_CHACHE_H | |||
#define THREAD_CHACHE_H | |||
#include "base_cache.h" | |||
#include "intrusive_ptr.h" | |||
#include <booster/intrusive_ptr.h> | |||
#include "defs.h" | |||
namespace cppcms { | |||
namespace impl { | |||
intrusive_ptr<base_cache> CPPCMS_API thread_cache_factory(unsigned items); | |||
booster::intrusive_ptr<base_cache> CPPCMS_API thread_cache_factory(unsigned items); | |||
#ifndef CPPCMS_WIN32 | |||
intrusive_ptr<base_cache> CPPCMS_API process_cache_factory(size_t memory); | |||
booster::intrusive_ptr<base_cache> CPPCMS_API process_cache_factory(size_t memory); | |||
#endif | |||
} // impl | |||
} // cppcms | |||
@@ -107,7 +107,7 @@ namespace impl { | |||
if(!e) { | |||
if(tcp_) | |||
asio_socket_->set_option(io::socket::tcp_no_delay,true); | |||
intrusive_ptr< ::cppcms::http::context> cnt(new ::cppcms::http::context(api_)); | |||
booster::intrusive_ptr< ::cppcms::http::context> cnt(new ::cppcms::http::context(api_)); | |||
api_=0; | |||
cnt->run(); | |||
} | |||
@@ -115,7 +115,7 @@ namespace impl { | |||
} | |||
cppcms::service &srv_; | |||
intrusive_ptr<connection> api_; | |||
booster::intrusive_ptr<connection> api_; | |||
booster::aio::socket *asio_socket_,acceptor_; | |||
bool stopped_; | |||
bool tcp_; | |||
@@ -138,7 +138,7 @@ public: | |||
struct none{}; | |||
struct eof{}; | |||
typedef std::pair<std::string,std::string> pair_type; | |||
typedef boost::shared_ptr<http::file> file_type; | |||
typedef booster::shared_ptr<http::file> file_type; | |||
typedef enum { none, eof, error } result_type; | |||
typedef boost::variant<result_type,pair_type,file_type,eof> variant_type; | |||
@@ -250,7 +250,7 @@ cppcms::service &connection::service() | |||
{ | |||
return *service_; | |||
} | |||
intrusive_ptr<connection> connection::self() | |||
booster::intrusive_ptr<connection> connection::self() | |||
{ | |||
return this; | |||
} | |||
@@ -20,8 +20,8 @@ | |||
#define CPPCMS_IMPL_CGI_API_H | |||
#include <booster/noncopyable.h> | |||
#include "refcounted.h" | |||
#include "intrusive_ptr.h" | |||
#include <booster/refcounted.h> | |||
#include <booster/intrusive_ptr.h> | |||
#include <vector> | |||
#include <map> | |||
#include <booster/function.h> | |||
@@ -55,7 +55,7 @@ namespace cgi { | |||
virtual ~acceptor(){} | |||
}; | |||
class connection : public refcounted | |||
class connection : public booster::refcounted | |||
{ | |||
public: | |||
connection(cppcms::service &srv); | |||
@@ -103,7 +103,7 @@ namespace cgi { | |||
/****************************************************************************/ | |||
protected: | |||
intrusive_ptr<connection> self(); | |||
booster::intrusive_ptr<connection> self(); | |||
void async_read(void *,size_t,io_handler const &h); | |||
void async_write(void const *,size_t,io_handler const &h); | |||
private: | |||
@@ -30,16 +30,17 @@ | |||
#include <booster/aio/buffer.h> | |||
#include <booster/aio/endpoint.h> | |||
#include <booster/shared_ptr.h> | |||
#include <booster/enable_shared_from_this.h> | |||
#ifdef CPPCMS_USE_EXTERNAL_BOOST | |||
# include <boost/bind.hpp> | |||
# include <boost/enable_shared_from_this.hpp> | |||
# include <boost/format.hpp> | |||
# if defined(CPPCMS_WIN32) && _WIN32_WINNT <= 0x0501 && !defined(BOOST_ASIO_DISABLE_IOCP) | |||
# define NO_CANCELIO | |||
# endif | |||
#else // Internal Boost | |||
# include <cppcms_boost/bind.hpp> | |||
# include <cppcms_boost/enable_shared_from_this.hpp> | |||
# include <cppcms_boost/format.hpp> | |||
namespace boost = cppcms_boost; | |||
# if defined(CPPCMS_WIN32) && _WIN32_WINNT <= 0x0501 && !defined(CPPCMS_BOOST_ASIO_DISABLE_IOCP) | |||
@@ -51,9 +52,9 @@ namespace io = booster::aio; | |||
namespace cppcms { | |||
namespace impl { | |||
class tcp_pipe : public boost::enable_shared_from_this<tcp_pipe> { | |||
class tcp_pipe : public booster::enable_shared_from_this<tcp_pipe> { | |||
public: | |||
tcp_pipe(intrusive_ptr<http::context> connection,std::string const &ip,int port) : | |||
tcp_pipe(booster::intrusive_ptr<http::context> connection,std::string const &ip,int port) : | |||
connection_(connection), | |||
ip_(ip), | |||
port_(port), | |||
@@ -128,7 +129,7 @@ namespace cppcms { | |||
} | |||
} | |||
intrusive_ptr<http::context> connection_; | |||
booster::intrusive_ptr<http::context> connection_; | |||
std::string ip_; | |||
int port_; | |||
std::string data_; | |||
@@ -150,7 +151,7 @@ namespace cppcms { | |||
} | |||
void connection_forwarder::main(std::string unused) | |||
{ | |||
intrusive_ptr<http::context> con = release_context(); | |||
booster::intrusive_ptr<http::context> con = release_context(); | |||
std::string env_str; | |||
env_str.reserve(1000); | |||
@@ -180,7 +181,7 @@ namespace cppcms { | |||
header+=','; | |||
header.append(reinterpret_cast<char *>(post.first),post.second); | |||
boost::shared_ptr<impl::tcp_pipe> pipe(new impl::tcp_pipe(con,ip_,port_)); | |||
booster::shared_ptr<impl::tcp_pipe> pipe(new impl::tcp_pipe(con,ip_,port_)); | |||
pipe->async_send_receive(header); | |||
} | |||
}; |
@@ -639,7 +639,7 @@ namespace cgi { | |||
} | |||
intrusive_ptr<fastcgi> self() | |||
booster::intrusive_ptr<fastcgi> self() | |||
{ | |||
return this; | |||
} | |||
@@ -26,7 +26,7 @@ | |||
#include "localization.h" | |||
#include "http_context.h" | |||
#include "filters.h" | |||
#include "intrusive_ptr.h" | |||
#include <booster/intrusive_ptr.h> | |||
#include "form.h" | |||
#include "cache_interface.h" | |||
#include "session_interface.h" | |||
@@ -79,12 +79,12 @@ public: | |||
release_context()->async_complete_response(); | |||
} | |||
else if(pos == messages_.size()) { | |||
cppcms::intrusive_ptr<cppcms::http::context> context=release_context(); | |||
booster::intrusive_ptr<cppcms::http::context> context=release_context(); | |||
waiters_.insert(context); | |||
context->async_on_peer_reset( | |||
boost::bind( | |||
&chat::remove_context, | |||
cppcms::intrusive_ptr<chat>(this), | |||
booster::intrusive_ptr<chat>(this), | |||
context)); | |||
} | |||
else { | |||
@@ -92,7 +92,7 @@ public: | |||
release_context()->async_complete_response(); | |||
} | |||
} | |||
void remove_context(cppcms::intrusive_ptr<cppcms::http::context> context) | |||
void remove_context(booster::intrusive_ptr<cppcms::http::context> context) | |||
{ | |||
std::cerr<<"Connection closed"<<std::endl; | |||
waiters_.erase(context); | |||
@@ -108,7 +108,7 @@ public: | |||
} | |||
private: | |||
std::vector<std::string> messages_; | |||
typedef std::set<cppcms::intrusive_ptr<cppcms::http::context> > waiters_type; | |||
typedef std::set<booster::intrusive_ptr<cppcms::http::context> > waiters_type; | |||
waiters_type waiters_; | |||
}; | |||
@@ -136,7 +136,7 @@ private: | |||
{ | |||
broadcast(); | |||
timer_.expires_from_now(booster::ptime(100)); | |||
timer_.async_wait(cppcms::util::mem_bind(&stock::on_timeout,cppcms::intrusive_ptr<stock>(this))); | |||
timer_.async_wait(cppcms::util::mem_bind(&stock::on_timeout,booster::intrusive_ptr<stock>(this))); | |||
} | |||
void get() | |||
{ | |||
@@ -186,7 +186,7 @@ private: | |||
int counter_; | |||
double price_; | |||
std::vector<cppcms::intrusive_ptr<cppcms::http::context> > all_; | |||
std::vector<booster::intrusive_ptr<cppcms::http::context> > all_; | |||
booster::aio::deadline_timer timer_; | |||
}; | |||
@@ -454,7 +454,7 @@ int main(int argc,char **argv) | |||
{ | |||
try { | |||
cppcms::service service(argc,argv); | |||
cppcms::intrusive_ptr<chat> c=new chat(service); | |||
booster::intrusive_ptr<chat> c=new chat(service); | |||
service.applications_pool().mount(c,"/chat"); | |||
service.applications_pool().mount(cppcms::applications_factory<hello>(),"/hello"); | |||
service.applications_pool().mount(new stock(service),"/stock"); | |||
@@ -80,13 +80,13 @@ namespace cgi { | |||
{ | |||
self_->some_headers_data_read(e,n,h_); | |||
} | |||
binder(intrusive_ptr<http> self,handler const &h) : | |||
binder(booster::intrusive_ptr<http> self,handler const &h) : | |||
self_(self), | |||
h_(h) | |||
{ | |||
} | |||
private: | |||
intrusive_ptr<http> self_; | |||
booster::intrusive_ptr<http> self_; | |||
handler h_; | |||
}; | |||
virtual void async_read_headers(handler const &h) | |||
@@ -414,7 +414,7 @@ namespace cgi { | |||
} | |||
intrusive_ptr<http> self() | |||
booster::intrusive_ptr<http> self() | |||
{ | |||
return this; | |||
} | |||
@@ -56,7 +56,7 @@ namespace http { | |||
} | |||
}; | |||
context::context(intrusive_ptr<impl::cgi::connection> conn) : | |||
context::context(booster::intrusive_ptr<impl::cgi::connection> conn) : | |||
conn_(conn) | |||
{ | |||
d.reset(new data(*this)); | |||
@@ -95,7 +95,7 @@ void context::on_request_ready(bool error) | |||
std::string script_name = conn_->getenv("SCRIPT_NAME"); | |||
std::string matched; | |||
intrusive_ptr<application> app = service().applications_pool().get(script_name,path_info,matched); | |||
booster::intrusive_ptr<application> app = service().applications_pool().get(script_name,path_info,matched); | |||
if(!app) { | |||
response().io_mode(http::response::asynchronous); | |||
@@ -115,7 +115,7 @@ void context::on_request_ready(bool error) | |||
} | |||
} | |||
// static | |||
void context::dispatch(intrusive_ptr<application> app,std::string url,bool syncronous) | |||
void context::dispatch(booster::intrusive_ptr<application> app,std::string url,bool syncronous) | |||
{ | |||
try { | |||
if(syncronous) | |||
@@ -169,15 +169,15 @@ void context::try_restart(bool e) | |||
if(e) return; | |||
if(conn_->is_reuseable()) { | |||
intrusive_ptr<context> cont=new context(conn_); | |||
booster::intrusive_ptr<context> cont=new context(conn_); | |||
cont->run(); | |||
} | |||
conn_=0; | |||
} | |||
intrusive_ptr<context> context::self() | |||
booster::intrusive_ptr<context> context::self() | |||
{ | |||
intrusive_ptr<context> ptr(this); | |||
booster::intrusive_ptr<context> ptr(this); | |||
return ptr; | |||
} | |||
@@ -21,8 +21,8 @@ | |||
#include "defs.h" | |||
#include <booster/hold_ptr.h> | |||
#include "intrusive_ptr.h" | |||
#include "refcounted.h" | |||
#include <booster/intrusive_ptr.h> | |||
#include <booster/refcounted.h> | |||
#include <booster/function.h> | |||
#include <locale> | |||
@@ -48,13 +48,13 @@ namespace cppcms { | |||
/// and destroyed when HTTP request/response is completed | |||
/// | |||
class CPPCMS_API context : public refcounted | |||
class CPPCMS_API context : public booster::refcounted | |||
{ | |||
public: | |||
/// | |||
/// Internal API, don't use it | |||
/// | |||
context(intrusive_ptr<impl::cgi::connection> conn); | |||
context(booster::intrusive_ptr<impl::cgi::connection> conn); | |||
/// | |||
/// Destructor. | |||
~context(); | |||
@@ -168,13 +168,13 @@ namespace cppcms { | |||
void async_on_peer_reset(booster::function<void()> const &h); | |||
private: | |||
void on_request_ready(bool error); | |||
static void dispatch(intrusive_ptr<application> app,std::string url,bool syncronous); | |||
static void dispatch(booster::intrusive_ptr<application> app,std::string url,bool syncronous); | |||
void try_restart(bool e); | |||
intrusive_ptr<context> self(); | |||
booster::intrusive_ptr<context> self(); | |||
struct data; | |||
booster::hold_ptr<data> d; | |||
intrusive_ptr<impl::cgi::connection> conn_; | |||
booster::intrusive_ptr<impl::cgi::connection> conn_; | |||
}; | |||
} | |||
@@ -26,13 +26,8 @@ | |||
#include <stdio.h> | |||
#include <stdlib.h> | |||
#include "config.h" | |||
#ifdef CPPCMS_USE_EXTERNAL_BOOST | |||
# include <boost/shared_ptr.hpp> | |||
#else // Internal Boost | |||
# include <cppcms_boost/shared_ptr.hpp> | |||
namespace boost = cppcms_boost; | |||
#endif | |||
#include <booster/shared_ptr.h> | |||
namespace cppcms { namespace http { | |||
@@ -105,7 +100,7 @@ bool request::parse_cookies() | |||
struct request::data { | |||
std::vector<boost::shared_ptr<file> > files; | |||
std::vector<booster::shared_ptr<file> > files; | |||
std::vector<char> post_data; | |||
}; | |||
@@ -1,218 +0,0 @@ | |||
/////////////////////////////////////////////////////////////////////////////// | |||
// | |||
// Copyright (C) 2008-2010 Artyom Beilis (Tonkikh) <artyomtnk@yahoo.com> | |||
// | |||
// This program is free software: you can redistribute it and/or modify | |||
// it under the terms of the GNU Lesser General Public License as published by | |||
// the Free Software Foundation, either version 3 of the License, or | |||
// (at your option) any later version. | |||
// | |||
// This program is distributed in the hope that it will be useful, | |||
// but WITHOUT ANY WARRANTY; without even the implied warranty of | |||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |||
// GNU Lesser General Public License for more details. | |||
// | |||
// You should have received a copy of the GNU Lesser General Public License | |||
// along with this program. If not, see <http://www.gnu.org/licenses/>. | |||
// | |||
/////////////////////////////////////////////////////////////////////////////// | |||
#ifndef CPPCMS_INTRUSIVE_PTR_H_INCLUDED | |||
#define CPPCMS_INTRUSIVE_PTR_H_INCLUDED | |||
// | |||
// intrusive_ptr.hpp | |||
// | |||
// Copyright (c) 2001, 2002 Peter Dimov | |||
// | |||
// Distributed under the Boost Software License, Version 1.0. (See | |||
// accompanying file LICENSE_1_0.txt or copy at | |||
// http://www.boost.org/LICENSE_1_0.txt) | |||
// | |||
// See http://www.boost.org/libs/smart_ptr/intrusive_ptr.html for documentation. | |||
// | |||
#include <functional> // for std::less | |||
#include <iosfwd> // for std::basic_ostream | |||
namespace cppcms | |||
{ | |||
// | |||
// intrusive_ptr | |||
// | |||
// A smart pointer that uses intrusive reference counting. | |||
// | |||
// Relies on unqualified calls to | |||
// | |||
// void intrusive_ptr_add_ref(T * p); | |||
// void intrusive_ptr_release(T * p); | |||
// | |||
// (p != 0) | |||
// | |||
// The object is responsible for destroying itself. | |||
// | |||
template<class T> class intrusive_ptr | |||
{ | |||
private: | |||
typedef intrusive_ptr this_type; | |||
public: | |||
typedef T element_type; | |||
intrusive_ptr(): p_(0) | |||
{ | |||
} | |||
intrusive_ptr(T * p, bool add_ref = true): p_(p) | |||
{ | |||
if(p_ != 0 && add_ref) intrusive_ptr_add_ref(p_); | |||
} | |||
intrusive_ptr(intrusive_ptr const & rhs): p_(rhs.p_) | |||
{ | |||
if(p_ != 0) intrusive_ptr_add_ref(p_); | |||
} | |||
~intrusive_ptr() | |||
{ | |||
if(p_ != 0) intrusive_ptr_release(p_); | |||
} | |||
template<class U> intrusive_ptr(intrusive_ptr<U> const & rhs): p_(rhs.get()) | |||
{ | |||
if(p_ != 0) intrusive_ptr_add_ref(p_); | |||
} | |||
intrusive_ptr & operator=(intrusive_ptr const & rhs) | |||
{ | |||
this_type(rhs).swap(*this); | |||
return *this; | |||
} | |||
intrusive_ptr & operator=(T * rhs) | |||
{ | |||
this_type(rhs).swap(*this); | |||
return *this; | |||
} | |||
T * get() const | |||
{ | |||
return p_; | |||
} | |||
T & operator*() const | |||
{ | |||
return *p_; | |||
} | |||
T * operator->() const | |||
{ | |||
return p_; | |||
} | |||
typedef T * this_type::*unspecified_bool_type; | |||
operator unspecified_bool_type () const | |||
{ | |||
return p_ == 0? 0: &this_type::p_; | |||
} | |||
// operator! is a Borland-specific workaround | |||
bool operator! () const | |||
{ | |||
return p_ == 0; | |||
} | |||
void swap(intrusive_ptr & rhs) | |||
{ | |||
T * tmp = p_; | |||
p_ = rhs.p_; | |||
rhs.p_ = tmp; | |||
} | |||
private: | |||
T * p_; | |||
}; | |||
template<class T, class U> inline bool operator==(intrusive_ptr<T> const & a, intrusive_ptr<U> const & b) | |||
{ | |||
return a.get() == b.get(); | |||
} | |||
template<class T, class U> inline bool operator!=(intrusive_ptr<T> const & a, intrusive_ptr<U> const & b) | |||
{ | |||
return a.get() != b.get(); | |||
} | |||
template<class T> inline bool operator==(intrusive_ptr<T> const & a, T * b) | |||
{ | |||
return a.get() == b; | |||
} | |||
template<class T> inline bool operator!=(intrusive_ptr<T> const & a, T * b) | |||
{ | |||
return a.get() != b; | |||
} | |||
template<class T> inline bool operator==(T * a, intrusive_ptr<T> const & b) | |||
{ | |||
return a == b.get(); | |||
} | |||
template<class T> inline bool operator!=(T * a, intrusive_ptr<T> const & b) | |||
{ | |||
return a != b.get(); | |||
} | |||
template<class T> inline bool operator<(intrusive_ptr<T> const & a, intrusive_ptr<T> const & b) | |||
{ | |||
return std::less<T *>()(a.get(), b.get()); | |||
} | |||
template<class T> void swap(intrusive_ptr<T> & lhs, intrusive_ptr<T> & rhs) | |||
{ | |||
lhs.swap(rhs); | |||
} | |||
// mem_fn support | |||
template<class T> T * get_pointer(intrusive_ptr<T> const & p) | |||
{ | |||
return p.get(); | |||
} | |||
template<class T, class U> intrusive_ptr<T> static_pointer_cast(intrusive_ptr<U> const & p) | |||
{ | |||
return static_cast<T *>(p.get()); | |||
} | |||
template<class T, class U> intrusive_ptr<T> const_pointer_cast(intrusive_ptr<U> const & p) | |||
{ | |||
return const_cast<T *>(p.get()); | |||
} | |||
template<class T, class U> intrusive_ptr<T> dynamic_pointer_cast(intrusive_ptr<U> const & p) | |||
{ | |||
return dynamic_cast<T *>(p.get()); | |||
} | |||
// operator<< | |||
template<class E, class T, class Y> std::basic_ostream<E, T> & operator<< (std::basic_ostream<E, T> & os, intrusive_ptr<Y> const & p) | |||
{ | |||
os << p.get(); | |||
return os; | |||
} | |||
} // namespace cppcms | |||
#endif // #ifndef CPPCMS_INTRUSIVE_PTR_H_INCLUDED |
@@ -22,13 +22,12 @@ | |||
#include "config.h" | |||
#ifdef CPPCMS_USE_EXTERNAL_BOOST | |||
# include <boost/format.hpp> | |||
# include <boost/shared_ptr.hpp> | |||
#else // Internal Boost | |||
# include <cppcms_boost/format.hpp> | |||
# include <cppcms_boost/shared_ptr.hpp> | |||
namespace boost = cppcms_boost; | |||
#endif | |||
#include <booster/shared_ptr.h> | |||
#include <booster/thread.h> | |||
#include <sstream> | |||
@@ -87,7 +86,7 @@ namespace cppcms { | |||
typedef std::map<std::string,logger::level_type> module_level_type; | |||
module_level_type module_level; | |||
std::auto_ptr<std::fstream> output; | |||
std::vector<boost::shared_ptr<impl::log_device> > devices; | |||
std::vector<booster::shared_ptr<impl::log_device> > devices; | |||
}; | |||
logger::level_type logger::module_level(char const *module) | |||
@@ -1,63 +0,0 @@ | |||
/////////////////////////////////////////////////////////////////////////////// | |||
// | |||
// Copyright (C) 2008-2010 Artyom Beilis (Tonkikh) <artyomtnk@yahoo.com> | |||
// | |||
// This program is free software: you can redistribute it and/or modify | |||
// it under the terms of the GNU Lesser General Public License as published by | |||
// the Free Software Foundation, either version 3 of the License, or | |||
// (at your option) any later version. | |||
// | |||
// This program is distributed in the hope that it will be useful, | |||
// but WITHOUT ANY WARRANTY; without even the implied warranty of | |||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |||
// GNU Lesser General Public License for more details. | |||
// | |||
// You should have received a copy of the GNU Lesser General Public License | |||
// along with this program. If not, see <http://www.gnu.org/licenses/>. | |||
// | |||
/////////////////////////////////////////////////////////////////////////////// | |||
#ifndef CPPCMS_REFCOUNTED_H | |||
#define CPPCMS_REFCOUNTED_H | |||
#include "atomic_counter.h" | |||
namespace cppcms { | |||
class refcounted; | |||
void intrusive_ptr_add_ref(refcounted *ptr); | |||
void intrusive_ptr_release(refcounted *ptr); | |||
class refcounted { | |||
public: | |||
refcounted() : | |||
refs_(0) | |||
{ | |||
} | |||
virtual ~refcounted() | |||
{ | |||
} | |||
private: | |||
friend void intrusive_ptr_add_ref(refcounted *); | |||
friend void intrusive_ptr_release(refcounted *); | |||
refcounted(refcounted const &other); | |||
refcounted const &operator=(refcounted const &other); | |||
atomic_counter refs_; | |||
}; | |||
inline void intrusive_ptr_add_ref(refcounted *p) | |||
{ | |||
++p->refs_; | |||
} | |||
inline void intrusive_ptr_release(refcounted *p) | |||
{ | |||
if(p && --p->refs_ == 0) | |||
delete p; | |||
} | |||
} | |||
#endif |
@@ -117,7 +117,7 @@ namespace rpc { | |||
return params_; | |||
} | |||
void json_call::attach_context(intrusive_ptr<http::context> c) | |||
void json_call::attach_context(booster::intrusive_ptr<http::context> c) | |||
{ | |||
context_ = c; | |||
} | |||
@@ -232,11 +232,11 @@ namespace rpc { | |||
check_call(); | |||
current_call_->return_error(context(),e); | |||
} | |||
intrusive_ptr<json_call> json_rpc_server::release_call() | |||
booster::intrusive_ptr<json_call> json_rpc_server::release_call() | |||
{ | |||
check_call(); | |||
current_call_->attach_context(release_context()); | |||
intrusive_ptr<json_call> call = current_call_; | |||
booster::intrusive_ptr<json_call> call = current_call_; | |||
current_call_ = 0; | |||
return call; | |||
} | |||
@@ -20,8 +20,8 @@ | |||
#define CPPCMS_RPC_JSON_OBJECT_H | |||
#include "application.h" | |||
#include "refcounted.h" | |||
#include "intrusive_ptr.h" | |||
#include <booster/refcounted.h> | |||
#include <booster/intrusive_ptr.h> | |||
#include <booster/function.h> | |||
#include "json.h" | |||
#include "cppcms_error.h" | |||
@@ -51,7 +51,7 @@ namespace rpc { | |||
/// for handling asynchronous responses only. Similar API is provided | |||
/// in json_rpc_server class for synchronous methods. | |||
/// | |||
class CPPCMS_API json_call : public refcounted { | |||
class CPPCMS_API json_call : public booster::refcounted { | |||
public: | |||
/// | |||
@@ -100,10 +100,10 @@ namespace rpc { | |||
friend class json_rpc_server; | |||
void return_result(http::context &,json::value const &); | |||
void return_error(http::context &,json::value const &); | |||
void attach_context(intrusive_ptr<http::context> context); | |||
void attach_context(booster::intrusive_ptr<http::context> context); | |||
void check_not_notification(); | |||
intrusive_ptr<http::context> context_; | |||
booster::intrusive_ptr<http::context> context_; | |||
json::value id_; | |||
json::array params_; | |||
std::string method_; | |||
@@ -160,7 +160,7 @@ namespace rpc { | |||
/// Release json_call for asynchronous responses. Calls release_context() and | |||
/// assignes it to json_call object. | |||
/// | |||
intrusive_ptr<json_call> release_call(); | |||
booster::intrusive_ptr<json_call> release_call(); | |||
json_rpc_server(cppcms::service &srv); | |||
~json_rpc_server(); | |||
@@ -198,7 +198,7 @@ namespace rpc { | |||
}; | |||
typedef std::map<std::string,method_data> methods_map_type; | |||
methods_map_type methods_; | |||
intrusive_ptr<json_call> current_call_; | |||
booster::intrusive_ptr<json_call> current_call_; | |||
std::string smd_; | |||
@@ -178,7 +178,7 @@ namespace cgi { | |||
private: | |||
size_t start_,end_,sep_; | |||
intrusive_ptr<scgi> self() | |||
booster::intrusive_ptr<scgi> self() | |||
{ | |||
return this; | |||
} | |||
@@ -546,7 +546,7 @@ void service::setup_acceptor(json::value const &v,int backlog) | |||
if(!a.get()) | |||
throw cppcms_error("Unknown api: " + api); | |||
impl_->acceptors_.push_back(boost::shared_ptr<acceptor>(a)); | |||
impl_->acceptors_.push_back(booster::shared_ptr<acceptor>(a)); | |||
} | |||
void service::start_acceptor() | |||
@@ -22,16 +22,9 @@ | |||
#include "json.h" | |||
#include "localization.h" | |||
#include <booster/aio/io_service.h> | |||
#include <booster/shared_ptr.h> | |||
#include <memory> | |||
#include "config.h" | |||
#ifdef CPPCMS_USE_EXTERNAL_BOOST | |||
# include <boost/shared_ptr.hpp> | |||
#else // Internal Boost | |||
# include <cppcms_boost/shared_ptr.hpp> | |||
namespace boost = cppcms_boost; | |||
#endif | |||
namespace cppcms { | |||
class service; | |||
@@ -58,7 +51,7 @@ namespace impl { | |||
friend class cppcms::service; | |||
std::auto_ptr<booster::aio::io_service> io_service_; | |||
std::vector<boost::shared_ptr<cgi::acceptor> > acceptors_; | |||
std::vector<booster::shared_ptr<cgi::acceptor> > acceptors_; | |||
std::auto_ptr<json::value> settings_; | |||
std::auto_ptr<applications_pool> applications_pool_; | |||
std::auto_ptr<thread_pool> thread_pool_; | |||
@@ -21,8 +21,8 @@ | |||
#include "defs.h" | |||
#include <booster/noncopyable.h> | |||
#include "refcounted.h" | |||
#include "intrusive_ptr.h" | |||
#include <booster/refcounted.h> | |||
#include <booster/intrusive_ptr.h> | |||
#include <string> | |||
namespace cppcms { | |||
@@ -31,7 +31,7 @@ class session_interface; | |||
class session_api : | |||
public booster::noncopyable, | |||
public refcounted | |||
public booster::refcounted | |||
{ | |||
public: | |||
virtual void save(session_interface &,std::string const &data,time_t timeout, bool new_data, bool on_server) = 0; | |||
@@ -44,7 +44,7 @@ class session_api_factory { | |||
public: | |||
virtual bool requires_gc() = 0; | |||
virtual void gc() = 0; | |||
virtual intrusive_ptr<session_api> get() = 0; | |||
virtual booster::intrusive_ptr<session_api> get() = 0; | |||
virtual ~session_api_factory() {} | |||
}; | |||
@@ -29,7 +29,7 @@ namespace sessions { | |||
struct session_dual::data {}; | |||
session_dual::session_dual(std::auto_ptr<encryptor> enc,intrusive_ptr<session_storage> storage,size_t limit) : | |||
session_dual::session_dual(std::auto_ptr<encryptor> enc,booster::intrusive_ptr<session_storage> storage,size_t limit) : | |||
client_(new session_cookies(enc)), | |||
server_(new session_sid(storage)), | |||
data_size_limit_(limit) | |||
@@ -22,7 +22,7 @@ | |||
#include "session_api.h" | |||
#include "defs.h" | |||
#include <booster/hold_ptr.h> | |||
#include "intrusive_ptr.h" | |||
#include <booster/intrusive_ptr.h> | |||
#include <memory> | |||
namespace cppcms { | |||
@@ -36,7 +36,7 @@ class encryptor; | |||
class CPPCMS_API session_dual : public session_api { | |||
public: | |||
session_dual( std::auto_ptr<encryptor> enc, | |||
intrusive_ptr<session_storage> storage, | |||
booster::intrusive_ptr<session_storage> storage, | |||
size_t data_size_limit); | |||
virtual ~session_dual(); | |||
virtual void save(session_interface &,std::string const &data,time_t timeout,bool new_session,bool on_server); | |||
@@ -45,8 +45,8 @@ public: | |||
private: | |||
struct data; | |||
booster::hold_ptr<data> d; | |||
intrusive_ptr<session_cookies> client_; | |||
intrusive_ptr<session_sid> server_; | |||
booster::intrusive_ptr<session_cookies> client_; | |||
booster::intrusive_ptr<session_sid> server_; | |||
size_t data_size_limit_; | |||
}; | |||
@@ -22,7 +22,7 @@ | |||
#include "defs.h" | |||
#include <booster/noncopyable.h> | |||
#include <booster/hold_ptr.h> | |||
#include "intrusive_ptr.h" | |||
#include <booster/intrusive_ptr.h> | |||
#include "cstdint.h" | |||
#include <string> | |||
#include <map> | |||
@@ -137,7 +137,7 @@ private: | |||
// storage itself | |||
intrusive_ptr<session_api> storage_; | |||
booster::intrusive_ptr<session_api> storage_; | |||
struct data; | |||
booster::hold_ptr<data> d; // for future use | |||
@@ -113,7 +113,7 @@ session_memory_storage_factory::~session_memory_storage_factory() | |||
{ | |||
} | |||
intrusive_ptr<session_storage> session_memory_storage_factory::get() | |||
booster::intrusive_ptr<session_storage> session_memory_storage_factory::get() | |||
{ | |||
return storage_; | |||
} | |||
@@ -27,12 +27,12 @@ namespace sessions { | |||
class CPPCMS_API session_memory_storage_factory : public session_storage_factory { | |||
public: | |||
session_memory_storage_factory(); | |||
virtual intrusive_ptr<session_storage> get(); | |||
virtual booster::intrusive_ptr<session_storage> get(); | |||
virtual bool requires_gc(); | |||
virtual void gc_job(); | |||
virtual ~session_memory_storage_factory(); | |||
private: | |||
intrusive_ptr<session_storage> storage_; | |||
booster::intrusive_ptr<session_storage> storage_; | |||
}; | |||
} // sessions | |||
@@ -26,16 +26,13 @@ | |||
#include "hmac_encryptor.h" | |||
#include "json.h" | |||
#include "cppcms_error.h" | |||
#include <booster/shared_ptr.h> | |||
#include <booster/enable_shared_from_this.h> | |||
#include "config.h" | |||
#ifdef CPPCMS_USE_EXTERNAL_BOOST | |||
# include <boost/bind.hpp> | |||
# include <boost/shared_ptr.hpp> | |||
# include <boost/enable_shared_from_this.hpp> | |||
#else // Internal Boost | |||
# include <cppcms_boost/bind.hpp> | |||
# include <cppcms_boost/shared_ptr.hpp> | |||
# include <cppcms_boost/enable_shared_from_this.hpp> | |||
namespace boost = cppcms_boost; | |||
#endif | |||
@@ -87,7 +84,7 @@ struct session_pool::sid_factory : public session_api_factory | |||
if(pool_->storage_.get()) | |||
pool_->storage_->gc_job(); | |||
} | |||
intrusive_ptr<session_api> get() { | |||
booster::intrusive_ptr<session_api> get() { | |||
if(pool_->storage_.get()) | |||
return new session_sid(pool_->storage_->get()); | |||
else | |||
@@ -104,7 +101,7 @@ struct session_pool::cookies_factory : public session_api_factory | |||
return false; | |||
} | |||
void gc() {} | |||
intrusive_ptr<session_api> get() { | |||
booster::intrusive_ptr<session_api> get() { | |||
if(pool_->encryptor_.get()) | |||
return new session_cookies(pool_->encryptor_->get()); | |||
else | |||
@@ -128,7 +125,7 @@ struct session_pool::dual_factory : public session_api_factory | |||
if(pool_->storage_.get()) | |||
pool_->storage_->gc_job(); | |||
} | |||
intrusive_ptr<session_api> get() { | |||
booster::intrusive_ptr<session_api> get() { | |||
if(pool_->storage_.get() && pool_->encryptor_.get()) | |||
return new session_dual(pool_->encryptor_->get(),pool_->storage_->get(),limit_); | |||
else | |||
@@ -140,7 +137,7 @@ private: | |||
}; | |||
class session_pool::gc_job : public boost::enable_shared_from_this<gc_job> { | |||
class session_pool::gc_job : public booster::enable_shared_from_this<gc_job> { | |||
public: | |||
gc_job(service *ser,int freq,session_pool *pool) : | |||
timer_(new booster::aio::deadline_timer(ser->get_io_service())), | |||
@@ -160,7 +157,7 @@ private: | |||
timer_->expires_from_now(booster::ptime(freq_)); | |||
timer_->async_wait(boost::bind(&gc_job::async_run,shared_from_this())); | |||
} | |||
boost::shared_ptr<booster::aio::deadline_timer> timer_; | |||
booster::shared_ptr<booster::aio::deadline_timer> timer_; | |||
service *service_; | |||
int freq_; | |||
session_pool *pool_; | |||
@@ -249,7 +246,7 @@ void session_pool::after_fork() | |||
return; | |||
int frequency = service_->settings().get("session.gc",0); | |||
if(frequency > 0) { | |||
boost::shared_ptr<gc_job> job(new gc_job(service_,frequency,this)); | |||
booster::shared_ptr<gc_job> job(new gc_job(service_,frequency,this)); | |||
job->async_run(); | |||
} | |||
} | |||
@@ -259,7 +256,7 @@ session_pool::~session_pool() | |||
{ | |||
} | |||
intrusive_ptr<session_api> session_pool::get() | |||
booster::intrusive_ptr<session_api> session_pool::get() | |||
{ | |||
if(backend_.get()) | |||
return backend_->get(); | |||
@@ -20,7 +20,7 @@ | |||
#define CPPCMS_SESSION_POOL_H | |||
#include "defs.h" | |||
#include "intrusive_ptr.h" | |||
#include <booster/intrusive_ptr.h> | |||
#include <booster/hold_ptr.h> | |||
#include "session_api.h" | |||
@@ -41,7 +41,7 @@ namespace cppcms { | |||
void init(); | |||
intrusive_ptr<session_api> get(); | |||
booster::intrusive_ptr<session_api> get(); | |||
void backend(std::auto_ptr<session_api_factory> b); | |||
void encryptor(std::auto_ptr<sessions::encryptor_factory> e); | |||
@@ -377,7 +377,7 @@ session_file_storage_factory::~session_file_storage_factory() | |||
{ | |||
} | |||
intrusive_ptr<session_storage> session_file_storage_factory::get() | |||
booster::intrusive_ptr<session_storage> session_file_storage_factory::get() | |||
{ | |||
return storage_; | |||
} | |||
@@ -71,13 +71,13 @@ namespace sessions { | |||
class CPPCMS_API session_file_storage_factory : public session_storage_factory { | |||
public: | |||
session_file_storage_factory(std::string path,int conc,int proc_no,bool force_lock); | |||
virtual intrusive_ptr<session_storage> get(); | |||
virtual booster::intrusive_ptr<session_storage> get(); | |||
virtual bool requires_gc(); | |||
virtual void gc_job(); | |||
virtual ~session_file_storage_factory(); | |||
private: | |||
struct data; | |||
intrusive_ptr<session_file_storage> storage_; | |||
booster::intrusive_ptr<session_file_storage> storage_; | |||
}; | |||
} // sessions | |||
} // cppcms | |||
@@ -111,7 +111,7 @@ namespace impl { | |||
struct session_sid::data {}; | |||
session_sid::session_sid(intrusive_ptr<session_storage> st) : | |||
session_sid::session_sid(booster::intrusive_ptr<session_storage> st) : | |||
storage_(st) | |||
{ | |||
} | |||
@@ -22,7 +22,7 @@ | |||
#include "session_api.h" | |||
#include "defs.h" | |||
#include <booster/hold_ptr.h> | |||
#include "intrusive_ptr.h" | |||
#include <booster/intrusive_ptr.h> | |||
#include "session_storage.h" | |||
namespace cppcms { | |||
@@ -32,7 +32,7 @@ namespace sessions { | |||
class CPPCMS_API session_sid : public session_api { | |||
public: | |||
session_sid(intrusive_ptr<session_storage> s); | |||
session_sid(booster::intrusive_ptr<session_storage> s); | |||
~session_sid(); | |||
virtual void save(session_interface &,std::string const &data,time_t timeout,bool,bool); | |||
virtual bool load(session_interface &,std::string &data,time_t &timeout); | |||
@@ -44,7 +44,7 @@ namespace sessions { | |||
struct data; | |||
booster::hold_ptr<data> d; | |||
intrusive_ptr<session_storage> storage_; | |||
booster::intrusive_ptr<session_storage> storage_; | |||
}; | |||
} // sessions | |||
@@ -20,9 +20,9 @@ | |||
#define CPPCMS_SESSION_STORAGE_H | |||
#include "defs.h" | |||
#include "refcounted.h" | |||
#include <booster/refcounted.h> | |||
#include <booster/noncopyable.h> | |||
#include "intrusive_ptr.h" | |||
#include <booster/intrusive_ptr.h> | |||
#include <string> | |||
namespace cppcms { | |||
@@ -39,7 +39,7 @@ namespace sessions { | |||
class session_storage : | |||
public booster::noncopyable, | |||
public refcounted | |||
public booster::refcounted | |||
{ | |||
public: | |||
/// | |||
@@ -67,7 +67,7 @@ namespace sessions { | |||
class session_storage_factory { | |||
public: | |||
virtual intrusive_ptr<session_storage> get() = 0; | |||
virtual booster::intrusive_ptr<session_storage> get() = 0; | |||
virtual bool requires_gc() = 0; | |||
virtual void gc_job() {} | |||
virtual ~session_storage_factory() {} | |||
@@ -83,10 +83,10 @@ struct builder { | |||
ips(ips_), ports(ports_) | |||
{ | |||
} | |||
boost::shared_ptr<session_api> operator()(worker_thread &w) | |||
booster::shared_ptr<session_api> operator()(worker_thread &w) | |||
{ | |||
boost::shared_ptr<session_server_storage> storage(new session_tcp_storage(ips,ports)); | |||
return boost::shared_ptr<session_api>(new session_sid(storage)); | |||
booster::shared_ptr<session_server_storage> storage(new session_tcp_storage(ips,ports)); | |||
return booster::shared_ptr<session_api>(new session_sid(storage)); | |||
} | |||
} ; | |||
@@ -257,7 +257,7 @@ session_file_storage_factory::~session_file_storage_factory() | |||
{ | |||
} | |||
intrusive_ptr<session_storage> session_file_storage_factory::get() | |||
booster::intrusive_ptr<session_storage> session_file_storage_factory::get() | |||
{ | |||
return storage_; | |||
} | |||
@@ -61,13 +61,13 @@ namespace sessions { | |||
class CPPCMS_API session_file_storage_factory : public session_storage_factory { | |||
public: | |||
session_file_storage_factory(std::string path); | |||
virtual intrusive_ptr<session_storage> get(); | |||
virtual booster::intrusive_ptr<session_storage> get(); | |||
virtual bool requires_gc(); | |||
virtual void gc_job(); | |||
virtual ~session_file_storage_factory(); | |||
private: | |||
struct data; | |||
intrusive_ptr<session_file_storage> storage_; | |||
booster::intrusive_ptr<session_file_storage> storage_; | |||
}; | |||
} // sessions | |||
} // cppcms | |||
@@ -32,14 +32,12 @@ | |||
#include "config.h" | |||
#ifdef CPPCMS_USE_EXTERNAL_BOOST | |||
# include <boost/bind.hpp> | |||
# include <boost/shared_ptr.hpp> | |||
# include <boost/enable_shared_from_this.hpp> | |||
#else // Internal Boost | |||
# include <cppcms_boost/bind.hpp> | |||
# include <cppcms_boost/shared_ptr.hpp> | |||
# include <cppcms_boost/enable_shared_from_this.hpp> | |||
namespace boost = cppcms_boost; | |||
#endif | |||
#include <booster/shared_ptr.h> | |||
#include <booster/enable_shared_from_this.h> | |||
#include <booster/thread.h> | |||
#include <booster/aio/socket.h> | |||
#include <booster/aio/io_service.h> | |||
@@ -57,7 +55,7 @@ namespace impl { | |||
namespace io = booster::aio; | |||
class tcp_cache_service::session : public boost::enable_shared_from_this<tcp_cache_service::session> { | |||
class tcp_cache_service::session : public booster::enable_shared_from_this<tcp_cache_service::session> { | |||
std::vector<char> data_in; | |||
std::string data_out; | |||
cppcms::impl::tcp_operation_header hout; | |||
@@ -279,7 +277,7 @@ class tcp_cache_service::server { | |||
io::socket acceptor_; | |||
cppcms::impl::base_cache &cache; | |||
//session_server_storage &sessions; | |||
void on_accept(booster::system::error_code const &e,boost::shared_ptr<tcp_cache_service::session> s) | |||
void on_accept(booster::system::error_code const &e,booster::shared_ptr<tcp_cache_service::session> s) | |||
{ | |||
if(!e) { | |||
s->socket_.set_option(io::socket::tcp_no_delay,true); | |||
@@ -289,8 +287,8 @@ class tcp_cache_service::server { | |||
} | |||
void start_accept() | |||
{ | |||
//boost::shared_ptr<session> s(new session(acceptor_.io_service(),cache,sessions)); | |||
boost::shared_ptr<session> s(new session(acceptor_.get_io_service(),cache)); | |||
//booster::shared_ptr<session> s(new session(acceptor_.io_service(),cache,sessions)); | |||
booster::shared_ptr<session> s(new session(acceptor_.get_io_service(),cache)); | |||
acceptor_.async_accept(s->socket_,boost::bind(&server::on_accept,this,_1,s)); | |||
} | |||
public: | |||
@@ -317,7 +315,7 @@ public: | |||
class garbage_collector | |||
{ | |||
aio::deadline_timer timer; | |||
boost::shared_ptr<storage::io> io; | |||
booster::shared_ptr<storage::io> io; | |||
int seconds; | |||
void submit() | |||
{ | |||
@@ -330,7 +328,7 @@ class garbage_collector | |||
submit(); | |||
} | |||
public: | |||
garbage_collector(io::io_service &srv,int sec,boost::shared_ptr<storage::io> io_) : | |||
garbage_collector(io::io_service &srv,int sec,booster::shared_ptr<storage::io> io_) : | |||
timer(srv), | |||
seconds(sec), | |||
io(io_) | |||
@@ -370,11 +368,11 @@ static void thread_function(io::io_service *io) | |||
struct tcp_cache_service::data { | |||
io::io_service io; | |||
std::auto_ptr<server> srv_cache; | |||
intrusive_ptr<base_cache> cache; | |||
std::vector<boost::shared_ptr<booster::thread> > threads; | |||
booster::intrusive_ptr<base_cache> cache; | |||
std::vector<booster::shared_ptr<booster::thread> > threads; | |||
}; | |||
tcp_cache_service::tcp_cache_service(intrusive_ptr<base_cache> cache,int threads,std::string ip,int port) : | |||
tcp_cache_service::tcp_cache_service(booster::intrusive_ptr<base_cache> cache,int threads,std::string ip,int port) : | |||
d(new data) | |||
{ | |||
d->cache=cache; | |||
@@ -388,7 +386,7 @@ tcp_cache_service::tcp_cache_service(intrusive_ptr<base_cache> cache,int threads | |||
int i; | |||
for(i=0;i<threads;i++){ | |||
boost::shared_ptr<booster::thread> thread; | |||
booster::shared_ptr<booster::thread> thread; | |||
thread.reset(new booster::thread(boost::bind(thread_function,&d->io))); | |||
d->threads.push_back(thread); | |||
} | |||
@@ -22,7 +22,7 @@ | |||
#include "defs.h" | |||
#include "base_cache.h" | |||
#include <booster/noncopyable.h> | |||
#include "intrusive_ptr.h" | |||
#include <booster/intrusive_ptr.h> | |||
#include <booster/hold_ptr.h> | |||
namespace cppcms { | |||
@@ -30,7 +30,7 @@ namespace impl { | |||
class CPPCMS_API tcp_cache_service : public booster::noncopyable { | |||
public: | |||
tcp_cache_service(intrusive_ptr<base_cache> cache,int threads,std::string ip,int port); | |||
tcp_cache_service(booster::intrusive_ptr<base_cache> cache,int threads,std::string ip,int port); | |||
~tcp_cache_service(); | |||
void stop(); | |||
private: | |||
@@ -21,7 +21,7 @@ | |||
#include "tcp_cache_server.h" | |||
#include "cache_over_ip.h" | |||
#include "base_cache.h" | |||
#include "intrusive_ptr.h" | |||
#include <booster/intrusive_ptr.h> | |||
#include "test.h" | |||
#include <iostream> | |||
#include <memory> | |||
@@ -36,7 +36,7 @@ void ssleep(int x) { sleep(x); } | |||
void test_cache(cppcms::intrusive_ptr<cppcms::impl::base_cache> cache,bool test_generators=true) | |||
void test_cache(booster::intrusive_ptr<cppcms::impl::base_cache> cache,bool test_generators=true) | |||
{ | |||
std::string tmp; | |||
std::set<std::string> tags; | |||
@@ -100,7 +100,7 @@ void test_cache(cppcms::intrusive_ptr<cppcms::impl::base_cache> cache,bool test_ | |||
} | |||
} | |||
void test_two_clients(cppcms::intrusive_ptr<cppcms::impl::base_cache> c1,cppcms::intrusive_ptr<cppcms::impl::base_cache> c2) | |||
void test_two_clients(booster::intrusive_ptr<cppcms::impl::base_cache> c1,booster::intrusive_ptr<cppcms::impl::base_cache> c2) | |||
{ | |||
std::string tmp; | |||
std::set<std::string> tags; | |||
@@ -27,14 +27,7 @@ | |||
#include <iostream> | |||
#include "client.h" | |||
#include "config.h" | |||
#ifdef CPPCMS_USE_EXTERNAL_BOOST | |||
# include <boost/shared_ptr.hpp> | |||
#else // Internal Boost | |||
# include <cppcms_boost/shared_ptr.hpp> | |||
namespace boost = cppcms_boost; | |||
#endif | |||
#include <booster/shared_ptr.h> | |||
#include <booster/thread.h> | |||
class unit_test : public cppcms::application | |||
@@ -86,7 +79,7 @@ public: | |||
} | |||
boost::shared_ptr<cppcms::service> service() | |||
booster::shared_ptr<cppcms::service> service() | |||
{ | |||
return srv; | |||
} | |||
@@ -104,8 +97,8 @@ public: | |||
fw_ok=true; | |||
} | |||
private: | |||
boost::shared_ptr<cppcms::service> srv; | |||
cppcms::intrusive_ptr<cppcms::application> app_; | |||
booster::shared_ptr<cppcms::service> srv; | |||
booster::intrusive_ptr<cppcms::application> app_; | |||
}; | |||
@@ -60,7 +60,7 @@ int main(int argc,char **argv) | |||
{ | |||
try { | |||
cppcms::service srv(argc,argv); | |||
cppcms::intrusive_ptr<cppcms::application> app; | |||
booster::intrusive_ptr<cppcms::application> app; | |||
if(!srv.settings().get("test.async",false)) { | |||
srv.applications_pool().mount( cppcms::applications_factory<unit_test>()); | |||
} | |||
@@ -40,7 +40,7 @@ | |||
std::string dir = "./sessions"; | |||
std::string bs="0123456789abcdef0123456789abcde"; | |||
void test(cppcms::intrusive_ptr<cppcms::sessions::session_storage> storage) | |||
void test(booster::intrusive_ptr<cppcms::sessions::session_storage> storage) | |||
{ | |||
time_t now=time(0)+3; | |||
storage->save(bs+"1",now,""); | |||
@@ -77,7 +77,7 @@ std::vector<std::string> list_files() | |||
return files; | |||
} | |||
void test_files(cppcms::intrusive_ptr<cppcms::sessions::session_storage> storage, | |||
void test_files(booster::intrusive_ptr<cppcms::sessions::session_storage> storage, | |||
cppcms::sessions::session_storage_factory &f) | |||
{ | |||
test(storage); | |||
@@ -107,7 +107,7 @@ void test_files(cppcms::intrusive_ptr<cppcms::sessions::session_storage> storage | |||
int main() | |||
{ | |||
try { | |||
cppcms::intrusive_ptr<cppcms::sessions::session_storage> storage; | |||
booster::intrusive_ptr<cppcms::sessions::session_storage> storage; | |||
using namespace cppcms::sessions; | |||
std::cout << "Testing memory storage" << std::endl; | |||
@@ -22,14 +22,13 @@ | |||
#include <vector> | |||
#include "config.h" | |||
#ifdef CPPCMS_USE_EXTERNAL_BOOST | |||
# include <boost/shared_ptr.hpp> | |||
# include <boost/bind.hpp> | |||
#else // Internal Boost | |||
# include <cppcms_boost/shared_ptr.hpp> | |||
# include <cppcms_boost/bind.hpp> | |||
namespace boost = cppcms_boost; | |||
#endif | |||
#include <booster/shared_ptr.h> | |||
#include <booster/thread.h> | |||
#if defined(CPPCMS_POSIX) | |||
@@ -88,7 +87,7 @@ namespace impl { | |||
} | |||
for(unsigned i=0;i<workers_.size();i++) { | |||
boost::shared_ptr<booster::thread> thread=workers_[i]; | |||
booster::shared_ptr<booster::thread> thread=workers_[i]; | |||
workers_[i].reset(); | |||
if(thread) | |||
thread->join(); | |||
@@ -137,7 +136,7 @@ namespace impl { | |||
int job_id_; | |||
typedef std::list<std::pair<int,booster::function<void()> > > queue_type; | |||
queue_type queue_; | |||
std::vector<boost::shared_ptr<booster::thread> > workers_; | |||
std::vector<booster::shared_ptr<booster::thread> > workers_; | |||
}; | |||
@@ -21,14 +21,7 @@ | |||
#include "application.h" | |||
#include <booster/regex.h> | |||
#include "config.h" | |||
#ifdef CPPCMS_USE_EXTERNAL_BOOST | |||
# include <boost/shared_ptr.hpp> | |||
#else // Internal Boost | |||
# include <cppcms_boost/shared_ptr.hpp> | |||
namespace boost = cppcms_boost; | |||
#endif | |||
#include <booster/shared_ptr.h> | |||
namespace cppcms { | |||
@@ -120,17 +113,17 @@ namespace cppcms { | |||
template<typename H> | |||
boost::shared_ptr<option> make_handler(std::string expr,H const &handler,int a=0,int b=0,int c=0,int d=0) | |||
booster::shared_ptr<option> make_handler(std::string expr,H const &handler,int a=0,int b=0,int c=0,int d=0) | |||
{ | |||
return boost::shared_ptr<option>(new base_handler<H>(expr,handler,a,b,c,d)); | |||
return booster::shared_ptr<option>(new base_handler<H>(expr,handler,a,b,c,d)); | |||
} | |||
} // anonynoys | |||
struct url_dispatcher::data { | |||
std::vector<boost::shared_ptr<option> > options; | |||
boost::shared_ptr<option> last_option; | |||
std::vector<booster::shared_ptr<option> > options; | |||
booster::shared_ptr<option> last_option; | |||
}; | |||
// Meanwhile nothing | |||
@@ -154,7 +147,7 @@ namespace cppcms { | |||
void url_dispatcher::mount(std::string match,application &app,int select) | |||
{ | |||
d->options.push_back(boost::shared_ptr<option>(new mounted(match,select,&app))); | |||
d->options.push_back(booster::shared_ptr<option>(new mounted(match,select,&app))); | |||
} | |||
@@ -28,6 +28,7 @@ | |||
namespace boost = cppcms_boost; | |||
#endif | |||
#include <booster/shared_ptr.h> | |||
#include <booster/thread.h> | |||
#ifdef CPPCMS_WIN32 | |||
@@ -197,7 +198,7 @@ private: | |||
std::string file_name_; | |||
time_t time_stamp_; | |||
mapping_type mapping_; | |||
boost::shared_ptr<impl::shared_object> shared_object_; | |||
booster::shared_ptr<impl::shared_object> shared_object_; | |||
}; | |||