| 1 | // Copyright (C) 2001-2003 |
|---|
| 2 | // William E. Kempf |
|---|
| 3 | // |
|---|
| 4 | // Permission to use, copy, modify, distribute and sell this software |
|---|
| 5 | // and its documentation for any purpose is hereby granted without fee, |
|---|
| 6 | // provided that the above copyright notice appear in all copies and |
|---|
| 7 | // that both that copyright notice and this permission notice appear |
|---|
| 8 | // in supporting documentation. William E. Kempf makes no representations |
|---|
| 9 | // about the suitability of this software for any purpose. |
|---|
| 10 | // It is provided "as is" without express or implied warranty. |
|---|
| 11 | |
|---|
| 12 | #include <boost/thread/detail/config.hpp> |
|---|
| 13 | |
|---|
| 14 | #include <boost/thread/exceptions.hpp> |
|---|
| 15 | #include <cstring> |
|---|
| 16 | #include <string> |
|---|
| 17 | |
|---|
| 18 | # ifdef BOOST_NO_STDC_NAMESPACE |
|---|
| 19 | namespace std { using ::strerror; } |
|---|
| 20 | # endif |
|---|
| 21 | |
|---|
| 22 | // BOOST_POSIX or BOOST_WINDOWS specify which API to use. |
|---|
| 23 | # if !defined( BOOST_WINDOWS ) && !defined( BOOST_POSIX ) |
|---|
| 24 | # if defined(_WIN32) || defined(__WIN32__) || defined(WIN32) || defined(__CYGWIN__) |
|---|
| 25 | # define BOOST_WINDOWS |
|---|
| 26 | # else |
|---|
| 27 | # define BOOST_POSIX |
|---|
| 28 | # endif |
|---|
| 29 | # endif |
|---|
| 30 | |
|---|
| 31 | # if defined( BOOST_WINDOWS ) |
|---|
| 32 | # include "windows.h" |
|---|
| 33 | # else |
|---|
| 34 | # include <errno.h> // for POSIX error codes |
|---|
| 35 | # endif |
|---|
| 36 | |
|---|
| 37 | namespace |
|---|
| 38 | { |
|---|
| 39 | |
|---|
| 40 | std::string system_message(int sys_err_code) |
|---|
| 41 | { |
|---|
| 42 | std::string str; |
|---|
| 43 | # ifdef BOOST_WINDOWS |
|---|
| 44 | LPVOID lpMsgBuf; |
|---|
| 45 | ::FormatMessageA(FORMAT_MESSAGE_ALLOCATE_BUFFER | |
|---|
| 46 | FORMAT_MESSAGE_FROM_SYSTEM | |
|---|
| 47 | FORMAT_MESSAGE_IGNORE_INSERTS, |
|---|
| 48 | NULL, |
|---|
| 49 | sys_err_code, |
|---|
| 50 | MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), // Default language |
|---|
| 51 | (LPSTR)&lpMsgBuf, |
|---|
| 52 | 0, |
|---|
| 53 | NULL); |
|---|
| 54 | str += static_cast<LPCSTR>(lpMsgBuf); |
|---|
| 55 | ::LocalFree(lpMsgBuf); // free the buffer |
|---|
| 56 | while (str.size() && (str[str.size()-1] == '\n' || |
|---|
| 57 | str[str.size()-1] == '\r')) |
|---|
| 58 | { |
|---|
| 59 | str.erase(str.size()-1); |
|---|
| 60 | } |
|---|
| 61 | # else |
|---|
| 62 | str += std::strerror(errno); |
|---|
| 63 | # endif |
|---|
| 64 | return str; |
|---|
| 65 | } |
|---|
| 66 | |
|---|
| 67 | } // unnamed namespace |
|---|
| 68 | |
|---|
| 69 | namespace boost { |
|---|
| 70 | |
|---|
| 71 | thread_exception::thread_exception() |
|---|
| 72 | : m_sys_err(0) |
|---|
| 73 | { |
|---|
| 74 | } |
|---|
| 75 | |
|---|
| 76 | thread_exception::thread_exception(int sys_err_code) |
|---|
| 77 | : m_sys_err(sys_err_code) |
|---|
| 78 | { |
|---|
| 79 | } |
|---|
| 80 | |
|---|
| 81 | thread_exception::~thread_exception() throw() |
|---|
| 82 | { |
|---|
| 83 | } |
|---|
| 84 | |
|---|
| 85 | int thread_exception::native_error() const |
|---|
| 86 | { |
|---|
| 87 | return m_sys_err; |
|---|
| 88 | } |
|---|
| 89 | |
|---|
| 90 | const char* thread_exception::message() const |
|---|
| 91 | { |
|---|
| 92 | if (m_sys_err != 0) |
|---|
| 93 | return system_message(m_sys_err).c_str(); |
|---|
| 94 | return what(); |
|---|
| 95 | } |
|---|
| 96 | |
|---|
| 97 | lock_error::lock_error() |
|---|
| 98 | { |
|---|
| 99 | } |
|---|
| 100 | |
|---|
| 101 | lock_error::lock_error(int sys_err_code) |
|---|
| 102 | : thread_exception(sys_err_code) |
|---|
| 103 | { |
|---|
| 104 | } |
|---|
| 105 | |
|---|
| 106 | lock_error::~lock_error() throw() |
|---|
| 107 | { |
|---|
| 108 | } |
|---|
| 109 | |
|---|
| 110 | const char* lock_error::what() const throw() |
|---|
| 111 | { |
|---|
| 112 | return "boost::lock_error"; |
|---|
| 113 | } |
|---|
| 114 | |
|---|
| 115 | thread_resource_error::thread_resource_error() |
|---|
| 116 | { |
|---|
| 117 | } |
|---|
| 118 | |
|---|
| 119 | thread_resource_error::thread_resource_error(int sys_err_code) |
|---|
| 120 | : thread_exception(sys_err_code) |
|---|
| 121 | { |
|---|
| 122 | } |
|---|
| 123 | |
|---|
| 124 | thread_resource_error::~thread_resource_error() throw() |
|---|
| 125 | { |
|---|
| 126 | } |
|---|
| 127 | |
|---|
| 128 | const char* thread_resource_error::what() const throw() |
|---|
| 129 | { |
|---|
| 130 | return "boost::thread_resource_error"; |
|---|
| 131 | } |
|---|
| 132 | |
|---|
| 133 | unsupported_thread_option::unsupported_thread_option() |
|---|
| 134 | { |
|---|
| 135 | } |
|---|
| 136 | |
|---|
| 137 | unsupported_thread_option::unsupported_thread_option(int sys_err_code) |
|---|
| 138 | : thread_exception(sys_err_code) |
|---|
| 139 | { |
|---|
| 140 | } |
|---|
| 141 | |
|---|
| 142 | unsupported_thread_option::~unsupported_thread_option() throw() |
|---|
| 143 | { |
|---|
| 144 | } |
|---|
| 145 | |
|---|
| 146 | const char* unsupported_thread_option::what() const throw() |
|---|
| 147 | { |
|---|
| 148 | return "boost::unsupported_thread_option"; |
|---|
| 149 | } |
|---|
| 150 | |
|---|
| 151 | invalid_thread_argument::invalid_thread_argument() |
|---|
| 152 | { |
|---|
| 153 | } |
|---|
| 154 | |
|---|
| 155 | invalid_thread_argument::invalid_thread_argument(int sys_err_code) |
|---|
| 156 | : thread_exception(sys_err_code) |
|---|
| 157 | { |
|---|
| 158 | } |
|---|
| 159 | |
|---|
| 160 | invalid_thread_argument::~invalid_thread_argument() throw() |
|---|
| 161 | { |
|---|
| 162 | } |
|---|
| 163 | |
|---|
| 164 | const char* invalid_thread_argument::what() const throw() |
|---|
| 165 | { |
|---|
| 166 | return "boost::invalid_thread_argument"; |
|---|
| 167 | } |
|---|
| 168 | |
|---|
| 169 | thread_permission_error::thread_permission_error() |
|---|
| 170 | { |
|---|
| 171 | } |
|---|
| 172 | |
|---|
| 173 | thread_permission_error::thread_permission_error(int sys_err_code) |
|---|
| 174 | : thread_exception(sys_err_code) |
|---|
| 175 | { |
|---|
| 176 | } |
|---|
| 177 | |
|---|
| 178 | thread_permission_error::~thread_permission_error() throw() |
|---|
| 179 | { |
|---|
| 180 | } |
|---|
| 181 | |
|---|
| 182 | const char* thread_permission_error::what() const throw() |
|---|
| 183 | { |
|---|
| 184 | return "boost::thread_permission_error"; |
|---|
| 185 | } |
|---|
| 186 | |
|---|
| 187 | } // namespace boost |
|---|