Ensure that low-level system resource wrappers throw exceptions on failure

(Sourceforge Request ID 1152841).
This commit is contained in:
chris_kohlhoff 2005-03-03 12:49:32 +00:00
parent 2ad0e49cc8
commit d9e5875753
6 changed files with 18 additions and 7 deletions

View File

@ -16,6 +16,7 @@
#if !defined(_WIN32)
#include "asio/detail/push_options.hpp"
#include <new>
#include <boost/noncopyable.hpp>
#include <pthread.h>
#include "asio/detail/pop_options.hpp"
@ -37,7 +38,8 @@ public:
: joined_(false)
{
func_base* arg = new func<Function>(f);
::pthread_create(&thread_, 0, asio_detail_posix_thread_function, arg);
if (::pthread_create(&thread_, 0, asio_detail_posix_thread_function, arg))
throw std::bad_alloc();
}
// Destructor.

View File

@ -16,7 +16,7 @@
#if !defined(_WIN32)
#include "asio/detail/push_options.hpp"
#include <stdexcept>
#include <new>
#include <pthread.h>
#include "asio/detail/pop_options.hpp"
@ -30,7 +30,7 @@ public:
posix_tss_bool()
{
if (::pthread_key_create(&tss_key_, 0) != 0)
throw std::runtime_error("Cannot create thread-local storage");
throw std::bad_alloc();
}
// Destructor.

View File

@ -15,6 +15,10 @@
#if defined(_WIN32)
#include "asio/detail/push_options.hpp"
#include <new>
#include "asio/detail/pop_options.hpp"
#include "asio/detail/socket_types.hpp"
namespace asio {
@ -28,6 +32,8 @@ public:
win_event()
: event_(::CreateEvent(0, true, false, 0))
{
if (!event_)
throw std::bad_alloc();
}
// Destructor.

View File

@ -16,7 +16,7 @@
#if defined(_WIN32)
#include "asio/detail/push_options.hpp"
#include <stdexcept>
#include <new>
#include <boost/noncopyable.hpp>
#include "asio/detail/pop_options.hpp"
@ -36,7 +36,7 @@ public:
win_mutex()
{
if (!do_init())
throw std::runtime_error("Unable to create mutex");
throw std::bad_alloc();
}
// Destructor.

View File

@ -18,6 +18,7 @@
#include "asio/detail/socket_types.hpp"
#include "asio/detail/push_options.hpp"
#include <new>
#include <process.h>
#include "asio/detail/pop_options.hpp"
@ -38,6 +39,8 @@ public:
unsigned int thread_id = 0;
thread_ = reinterpret_cast<HANDLE>(::_beginthreadex(0, 0,
asio_detail_win_thread_function, arg, 0, &thread_id));
if (!thread_)
throw std::bad_alloc();
}
// Destructor.

View File

@ -16,7 +16,7 @@
#if defined(_WIN32)
#include "asio/detail/push_options.hpp"
#include <stdexcept>
#include <new>
#include "asio/detail/pop_options.hpp"
#include "asio/detail/socket_types.hpp"
@ -32,7 +32,7 @@ public:
{
tss_key_ = ::TlsAlloc();
if (tss_key_ == TLS_OUT_OF_INDEXES)
throw std::runtime_error("Cannot create thread-local storage");
throw std::bad_alloc();
}
// Destructor.