Skip to content

Commit

Permalink
Port previous Boost patches.
Browse files Browse the repository at this point in the history
  • Loading branch information
FooBarWidget committed May 16, 2008
1 parent 1a3f207 commit f18c360
Show file tree
Hide file tree
Showing 7 changed files with 60 additions and 22 deletions.
2 changes: 1 addition & 1 deletion Rakefile
Expand Up @@ -81,7 +81,7 @@ end
##### boost::thread static library

subdir 'ext/boost/src' do
file 'libboost_thread.a' => Dir['*.cpp'] do
file 'libboost_thread.a' => Dir['*.cpp', 'pthread/*.cpp'] do
# Note: NDEBUG *must* be defined! boost::thread use assert() to check whether
# the pthread functions return an error. Because of the way Passenger uses
# processes, sometimes pthread errors will occur. These errors are harmless
Expand Down
32 changes: 27 additions & 5 deletions ext/boost/src/pthread/exceptions.cpp
Expand Up @@ -9,6 +9,7 @@
#include <boost/thread/exceptions.hpp>
#include <cstring>
#include <string>
#include <sstream>

namespace boost {

Expand All @@ -17,9 +18,21 @@ thread_exception::thread_exception()
{
}

thread_exception::thread_exception(const std::string &description, int sys_err_code)
: m_sys_err(sys_err_code)
{
std::ostringstream s;
s << description << ": ";
s << strerror(sys_err_code) << " (" << sys_err_code << ")";
message.assign(s.str());
}

thread_exception::thread_exception(int sys_err_code)
: m_sys_err(sys_err_code)
{
std::ostringstream s;
s << strerror(sys_err_code) << " (" << sys_err_code << ")";
message.assign(s.str());
}

thread_exception::~thread_exception() throw()
Expand All @@ -31,6 +44,15 @@ int thread_exception::native_error() const
return m_sys_err;
}

const char *thread_exception::what() const throw()
{
if (message.empty()) {
return std::exception::what();
} else {
return message.c_str();
}
}

lock_error::lock_error()
{
}
Expand All @@ -53,18 +75,18 @@ thread_resource_error::thread_resource_error()
{
}

thread_resource_error::thread_resource_error(int sys_err_code)
: thread_exception(sys_err_code)
thread_resource_error::thread_resource_error(const std::string &description, int sys_err_code)
: thread_exception(description, sys_err_code)
{
}

thread_resource_error::~thread_resource_error() throw()
thread_resource_error::thread_resource_error(int sys_err_code)
: thread_exception(sys_err_code)
{
}

const char* thread_resource_error::what() const throw()
thread_resource_error::~thread_resource_error() throw()
{
return "boost::thread_resource_error";
}

unsupported_thread_option::unsupported_thread_option()
Expand Down
20 changes: 17 additions & 3 deletions ext/boost/src/pthread/thread.cpp
Expand Up @@ -180,14 +180,28 @@ namespace boost
thread::thread()
{}

void thread::start_thread()
void thread::start_thread(unsigned int stack_size)
{
thread_info->self=thread_info;
int const res = pthread_create(&thread_info->thread_handle, 0, &thread_proxy, thread_info.get());
pthread_attr_t attr;
int res = pthread_attr_init(&attr);
if (res != 0) {
throw thread_resource_error("Cannot initialize thread attributes", res);
}
if (stack_size > 0) {
res = pthread_attr_setstacksize(&attr, stack_size);
if (res != 0) {
pthread_attr_destroy(&attr);
throw thread_resource_error("Cannot set thread stack size attribute", res);
}
}

res = pthread_create(&thread_info->thread_handle, &attr, &thread_proxy, thread_info.get());
pthread_attr_destroy(&attr);
if (res != 0)
{
thread_info->self.reset();
throw thread_resource_error();
throw thread_resource_error("Cannot create a thread", res);
}
}

Expand Down
6 changes: 4 additions & 2 deletions ext/boost/thread/exceptions.hpp
Expand Up @@ -24,13 +24,16 @@ namespace boost {
class BOOST_THREAD_DECL thread_exception : public std::exception
{
protected:
std::string message;
thread_exception();
thread_exception(const std::string &description, int sys_err_code);
thread_exception(int sys_err_code);

public:
~thread_exception() throw();

int native_error() const;
virtual const char *what() const throw();

private:
int m_sys_err;
Expand Down Expand Up @@ -61,10 +64,9 @@ class BOOST_THREAD_DECL thread_resource_error : public thread_exception
{
public:
thread_resource_error();
thread_resource_error(const std::string &description, int sys_err_code);
thread_resource_error(int sys_err_code);
~thread_resource_error() throw();

virtual const char* what() const throw();
};

class BOOST_THREAD_DECL unsupported_thread_option : public thread_exception
Expand Down
6 changes: 3 additions & 3 deletions ext/boost/thread/pthread/condition_variable.hpp
Expand Up @@ -21,7 +21,7 @@ namespace boost
int const res=pthread_cond_init(&cond,NULL);
if(res)
{
throw thread_resource_error();
throw thread_resource_error("Cannot initialize a condition variable", res);
}
}
inline condition_variable::~condition_variable()
Expand Down Expand Up @@ -72,13 +72,13 @@ namespace boost
int const res=pthread_mutex_init(&internal_mutex,NULL);
if(res)
{
throw thread_resource_error();
throw thread_resource_error("Cannot initialize a mutex", res);
}
int const res2=pthread_cond_init(&cond,NULL);
if(res2)
{
BOOST_VERIFY(!pthread_mutex_destroy(&internal_mutex));
throw thread_resource_error();
throw thread_resource_error("Cannot initialize a condition variable", res2);
}
}
~condition_variable_any()
Expand Down
6 changes: 3 additions & 3 deletions ext/boost/thread/pthread/mutex.hpp
Expand Up @@ -37,7 +37,7 @@ namespace boost
int const res=pthread_mutex_init(&m,NULL);
if(res)
{
throw thread_resource_error();
throw thread_resource_error("Cannot initialize a mutex", res);
}
}
~mutex()
Expand Down Expand Up @@ -89,14 +89,14 @@ namespace boost
int const res=pthread_mutex_init(&m,NULL);
if(res)
{
throw thread_resource_error();
throw thread_resource_error("Cannot initialize a mutex", res);
}
#ifndef BOOST_PTHREAD_HAS_TIMEDLOCK
int const res2=pthread_cond_init(&cond,NULL);
if(res2)
{
BOOST_VERIFY(!pthread_mutex_destroy(&m));
throw thread_resource_error();
throw thread_resource_error("Cannot initialize a condition variable", res2);
}
is_locked=false;
#endif
Expand Down
10 changes: 5 additions & 5 deletions ext/boost/thread/pthread/thread.hpp
Expand Up @@ -134,7 +134,7 @@ namespace boost
mutable boost::mutex thread_info_mutex;
detail::thread_data_ptr thread_info;

void start_thread();
void start_thread(unsigned int stack_size = 0);

explicit thread(detail::thread_data_ptr data);

Expand All @@ -145,16 +145,16 @@ namespace boost
~thread();

template <class F>
explicit thread(F f):
explicit thread(F f, unsigned int stack_size = 0):
thread_info(new thread_data<F>(f))
{
start_thread();
start_thread(stack_size);
}
template <class F>
thread(detail::thread_move_t<F> f):
thread(detail::thread_move_t<F> f, unsigned int stack_size = 0):
thread_info(new thread_data<F>(f))
{
start_thread();
start_thread(stack_size);
}

thread(detail::thread_move_t<thread> x);
Expand Down

0 comments on commit f18c360

Please sign in to comment.