Changeset 21348
- Timestamp:
- 10/15/08 11:41:06 (5 years ago)
- Location:
- lang/c/mpio/trunk
- Files:
-
- 1 added
- 20 modified
-
Makefile.am (modified) (1 diff)
-
mp/Makefile (modified) (1 diff)
-
mp/coroutine.h (modified) (1 diff)
-
mp/event.pre.h (modified) (1 diff)
-
mp/exception.h (added)
-
mp/fdnotify.h (modified) (2 diffs)
-
mp/fdnotify_impl.h (modified) (4 diffs)
-
mp/iothreads.pre.h (modified) (2 diffs)
-
mp/iothreads_impl.pre.h (modified) (2 diffs)
-
mp/pthread.h (modified) (3 diffs)
-
mp/pthread_impl.h (modified) (5 diffs)
-
mp/system/buffered_kqueue_impl.h (modified) (1 diff)
-
mp/system/epoll_impl.h (modified) (1 diff)
-
mp/system/kqueue_impl.h (modified) (1 diff)
-
mp/utility.pre.h (modified) (2 diffs)
-
mp/zone_impl.pre.h (modified) (1 diff)
-
src/iothreads.cc (modified) (1 diff)
-
src/iothreads_connector.cc (modified) (2 diffs)
-
src/iothreads_listener.cc (modified) (3 diffs)
-
src/iothreads_reader.cc (modified) (5 diffs)
-
src/iothreads_writer.cc (modified) (4 diffs)
Legend:
- Unmodified
- Added
- Removed
-
lang/c/mpio/trunk/Makefile.am
r19729 r21348 17 17 mp/event.h \ 18 18 mp/event_impl.h \ 19 mp/exception.h \ 19 20 mp/fdnotify.h \ 20 21 mp/fdnotify_impl.h \ -
lang/c/mpio/trunk/mp/Makefile
r21111 r21348 68 68 $< > $@ 69 69 70 .PHONY: clean 70 .PHONY: clean install distdir 71 71 clean: 72 72 $(RM) $(NEED_PREPROCESS) 73 73 74 install:75 # dummy76 77 distdir: -
lang/c/mpio/trunk/mp/coroutine.h
r19729 r21348 71 71 static void join(handler& target) 72 72 { s_instance->join_impl(target); } 73 74 //! Return current handler 75 static handler& current() 76 { return *s_current; } 73 77 74 78 //! Resume suspended handler's routine. -
lang/c/mpio/trunk/mp/event.pre.h
r18183 r21348 21 21 22 22 #include "mp/system/config.h" 23 #include "mp/exception.h" 23 24 #include "mp/utility.h" 24 25 #include "mp/sparse_array.h" -
lang/c/mpio/trunk/mp/fdnotify.h
r19040 r21348 20 20 #define MP_FDNOTIFY_H__ 21 21 22 #include <sys/types.h> 23 #include <sys/uio.h> 24 #include <unistd.h> 25 #include <stdexcept> 22 #include "mp/exception.h" 26 23 27 24 #ifndef MP_FDNOTIFY_VECTOR_SIZE 28 #define MP_FDNOTIFY_VECTOR_SIZE 6425 #define MP_FDNOTIFY_VECTOR_SIZE 32 29 26 #endif 30 27 … … 32 29 33 30 34 struct fdnotify_e xception : public std::runtime_error {35 fdnotify_e xception(const std::string& msg) :36 s td::runtime_error(msg) {}31 struct fdnotify_error : system_error { 32 fdnotify_error(int errno_, const std::string& msg) : 33 system_error(errno_, msg) {} 37 34 }; 38 35 -
lang/c/mpio/trunk/mp/fdnotify_impl.h
r19911 r21348 20 20 #define MP_FDNOTIFY_IMPL_H__ 21 21 22 #include <sys/types.h> 23 #include <sys/uio.h> 24 #include <unistd.h> 22 25 #include <fcntl.h> 23 26 #include <errno.h> … … 30 33 { 31 34 if( ::pipe(m_pipe) < 0 ) { 32 throw fdnotify_e xception("can't create pipe");35 throw fdnotify_error(errno, "can't create pipe"); 33 36 } 34 37 if( ::fcntl(m_pipe[0], F_SETFL, O_NONBLOCK) < 0 ) { 35 38 ::close(m_pipe[0]); 36 39 ::close(m_pipe[1]); 37 throw fdnotify_e xception("can't set non-blocking mode");40 throw fdnotify_error(errno, "can't set non-blocking mode"); 38 41 } 39 42 } … … 69 72 if(len < 0) { 70 73 if(errno != EAGAIN && errno != EINTR) { 71 throw fdnotify_e xception("write-side pipe is broken");74 throw fdnotify_error(errno, "write-side pipe is broken"); 72 75 } 73 76 } else if(len == 0) { 74 throw fdnotify_e xception("write-side pipe is closed");77 throw fdnotify_error(errno, "write-side pipe is closed"); 75 78 } 76 79 } … … 91 94 return false; 92 95 } else { 93 throw fdnotify_e xception("read-side pipe is broken");96 throw fdnotify_error(errno, "read-side pipe is broken"); 94 97 } 95 98 } else if(len == 0) { 96 throw fdnotify_e xception("read-side pipe is closed");99 throw fdnotify_error(errno, "read-side pipe is closed"); 97 100 } 98 101 -
lang/c/mpio/trunk/mp/iothreads.pre.h
r21304 r21348 62 62 MP_ARGS_END 63 63 64 static void submit(function<void ()> func); // FIXME64 static void submit(function<void ()> func); 65 65 66 66 static void join(); … … 85 85 blocking_vector<function<void ()> > m_messages; 86 86 zone m_zone; 87 88 typedef std::vector<function<void ()> > messages_t;89 87 90 88 private: -
lang/c/mpio/trunk/mp/iothreads_impl.pre.h
r19410 r21348 26 26 27 27 template <typename ThreadIMPL> 28 ThreadIMPL* manager::add_thread() {28 inline ThreadIMPL* manager::add_thread() { 29 29 return instance().add_thread_impl<ThreadIMPL>(); 30 30 } … … 32 32 MP_ARGS_BEGIN 33 33 template <typename ThreadIMPL, MP_ARGS_TEMPLATE> 34 ThreadIMPL* manager::add_thread(MP_ARGS_PARAMS) {34 inline ThreadIMPL* manager::add_thread(MP_ARGS_PARAMS) { 35 35 return instance().add_thread_impl<ThreadIMPL>(MP_ARGS_FUNC); 36 36 } -
lang/c/mpio/trunk/mp/pthread.h
r19911 r21348 20 20 #define MP_PTHREAD_H__ 21 21 22 #include "mp/exception.h" 22 23 #include <pthread.h> 23 24 #include <signal.h> 24 25 25 26 namespace mp { 27 28 29 struct pthread_error : system_error { 30 pthread_error(int errno_, const std::string& msg) : 31 system_error(errno_, msg) {} 32 }; 26 33 27 34 … … 39 46 private: 40 47 pthread_t m_thread; 41 friend bool operator== (const pthread_thread& x, const pthread_thread& y); 48 bool operator== (const pthread_thread& other) const; 49 bool operator!= (const pthread_thread& other) const; 42 50 }; 43 44 bool operator== (const pthread_thread& x, const pthread_thread& y);45 51 46 52 … … 102 108 private: 103 109 struct scoped_sigprocmask { 104 scoped_sigprocmask(const sigset_t& ss) : m_ss(ss) 105 { sigprocmask(SIG_BLOCK, &m_ss, NULL); } 106 ~scoped_sigprocmask() 107 { sigprocmask(SIG_UNBLOCK, &m_ss, NULL); } 110 scoped_sigprocmask(const sigset_t& ss); 111 ~scoped_sigprocmask(); 108 112 const sigset_t* get() const { return &m_ss; } 109 113 private: -
lang/c/mpio/trunk/mp/pthread_impl.h
r19911 r21348 20 20 #define MP_PTHREAD_IMPL_H__ 21 21 22 #include <iostream> 23 #include <typeinfo> 24 #ifndef MP_NO_CXX_ABI_H 25 #include <cxxabi.h> 26 #endif 27 22 28 namespace mp { 23 29 … … 26 32 pthread_thread::pthread_thread(IMPL* pimpl) 27 33 { 28 pthread_create(&m_thread, NULL,34 int err = pthread_create(&m_thread, NULL, 29 35 &pthread_thread::trampoline<IMPL>, 30 reinterpret_cast<void*>(pimpl) 31 );36 reinterpret_cast<void*>(pimpl)); 37 if(err) { throw pthread_error(err, "failed to create thread"); } 32 38 } 33 39 … … 37 43 inline void pthread_thread::detach() 38 44 { 39 pthread_detach(m_thread); 45 int err = pthread_detach(m_thread); 46 if(err) { throw pthread_error(err, "failed to detach thread"); } 40 47 } 41 48 … … 43 50 { 44 51 void* ret; 45 pthread_join(m_thread, &ret); // FIXME error 52 int err = pthread_join(m_thread, &ret); 53 if(err) { throw pthread_error(err, "failed to join thread"); } 46 54 return ret; 47 55 } 48 56 49 inline bool operator== (const pthread_thread& x, const pthread_thread& y)57 inline bool pthread_thread::operator== (const pthread_thread& other) const 50 58 { 51 return pthread_equal(x.m_thread, y.m_thread); 59 return pthread_equal(m_thread, other.m_thread); 60 } 61 62 inline bool pthread_thread::operator!= (const pthread_thread& other) const 63 { 64 return !(*this == other); 52 65 } 53 66 54 67 template <typename IMPL> 55 68 void* pthread_thread::trampoline(void* obj) 56 { 57 // FIXME exception 69 try { 58 70 reinterpret_cast<IMPL*>(obj)->operator()(); 59 71 return NULL; // FIXME 72 73 } catch (std::exception& e) { 74 try { 75 #ifndef MP_NO_CXX_ABI_H 76 int status; 77 std::cerr 78 << "thread terminated with throwing an instance of '" 79 << abi::__cxa_demangle(typeid(e).name(), 0, 0, &status) 80 << "'\n" 81 << " what(): " << e.what() << std::endl; 82 #else 83 std::cerr 84 << "thread terminated with throwing an instance of '" 85 << typeid(e).name() 86 << "'\n" 87 << " what(): " << e.what() << std::endl; 88 #endif 89 } catch (...) {} 90 throw; 91 92 } catch (...) { 93 try { 94 std::cerr << "thread terminated with throwing an unknown object" << std::endl; 95 } catch (...) {} 96 throw; 60 97 } 61 98 … … 118 155 119 156 157 inline pthread_signal::scoped_sigprocmask::scoped_sigprocmask(const sigset_t& ss) : 158 m_ss(ss) 159 { 160 if( sigprocmask(SIG_BLOCK, &m_ss, NULL) < 0 ) { 161 throw pthread_error(errno, "failed to set sigprocmask"); 162 } 163 } 164 165 inline pthread_signal::scoped_sigprocmask::~scoped_sigprocmask() 166 { 167 sigprocmask(SIG_UNBLOCK, &m_ss, NULL); 168 } 169 120 170 inline pthread_signal::pthread_signal(const sigset_t& ss, void (*handler)(int)) : 121 171 m_sigmask(ss), m_handler(handler), m_thread(this) {} -
lang/c/mpio/trunk/mp/system/buffered_kqueue_impl.h
r8088 r21348 7 7 system::system() : m_kqfd(kqueue()) 8 8 { 9 // FIXME m_kqfd < 0 9 if(m_kqfd < 0) { 10 throw event_error(errno, "failed to initialize kqueue"); 11 } 10 12 } 11 13 -
lang/c/mpio/trunk/mp/system/epoll_impl.h
r18183 r21348 10 10 system::system() : m_epfd(epoll_create(MP_EVENT_EPOLL_MAX_RESULT)) 11 11 { 12 // FIXME m_epfd < 0 12 if(m_epfd < 0) { 13 throw event_error(errno, "failed to create epoll"); 14 } 13 15 } 14 16 -
lang/c/mpio/trunk/mp/system/kqueue_impl.h
r8088 r21348 7 7 system::system() : m_kqfd(kqueue()) 8 8 { 9 // FIXME m_kqfd < 0 9 if(m_kqfd < 0) { 10 throw event_error(errno, "failed to initialize kqueue"); 11 } 10 12 } 11 13 -
lang/c/mpio/trunk/mp/utility.pre.h
r19729 r21348 37 37 inline void set_nonblock(int fd) 38 38 { 39 // FIXME error 40 fcntl(fd, F_SETFL, O_NONBLOCK); 39 if( ::fcntl(fd, F_SETFL, O_NONBLOCK) < 0 ) { 40 throw system_error(errno, "failed to set nonblock flag"); 41 } 41 42 } 42 43 … … 153 154 154 155 #endif /* mp/utility.h */ 156 -
lang/c/mpio/trunk/mp/zone_impl.pre.h
r20171 r21348 21 21 22 22 #include <stdlib.h> 23 #include < stdexcept>23 #include <new> 24 24 25 25 namespace mp { -
lang/c/mpio/trunk/src/iothreads.cc
r19410 r21348 46 46 void manager::run_impl() 47 47 { 48 typedef std::vector<function<void ()> > messages_t; 48 49 messages_t cache; 49 50 while(!m_end_flag) { -
lang/c/mpio/trunk/src/iothreads_connector.cc
r19911 r21348 141 141 connector::impl::worker::worker() 142 142 { 143 m_ev.add(m_notify.getfd(), EV_READ); // FIXME error 143 if( m_ev.add(m_notify.getfd(), EV_READ) < 0 ) { 144 throw event_error(errno, "iothreads connector failed to initialize event notifier"); 145 } 144 146 } 145 147 … … 178 180 if(m_ev.wait(1000) < 0) { // FIXME 179 181 if(errno != EAGAIN && errno != EINTR) { 180 throw std::runtime_error("connector event failed");182 throw event_error(errno, "iothreads connector event failed"); 181 183 } 182 184 } -
lang/c/mpio/trunk/src/iothreads_listener.cc
r19911 r21348 118 118 listener::impl::worker::worker() 119 119 { 120 m_ev.add(m_notify.getfd(), EV_READ, 121 (void (*)(void*, int))NULL, (void*)NULL); // FIXME error 120 if( m_ev.add(m_notify.getfd(), EV_READ, 121 (void (*)(void*, int))NULL, (void*)NULL) < 0 ) { 122 throw event_error(errno, "iothreads listener failed to initialize event notifier"); 123 } 122 124 } 123 125 … … 150 152 if(m_ev.wait(1000) < 0) { // FIXME 151 153 if(errno != EAGAIN && errno != EINTR) { 152 throw std::runtime_error("listener event failed");154 throw event_error(errno, "iothreads listener event failed"); 153 155 } 154 156 } … … 171 173 void listener::impl::worker::listen_impl(notify_entry& e) 172 174 { 173 m_ev.add(e.lsock, EV_READ, e.callback, e.obj); 175 if( m_ev.add(e.lsock, EV_READ, e.callback, e.obj) < 0 ) { 176 throw event_error(errno, "iothreads listener failed to add event"); 177 } 174 178 } 175 179 -
lang/c/mpio/trunk/src/iothreads_reader.cc
r21142 r21348 60 60 message_t* func; 61 61 int fd; 62 } m ;62 } message; 63 63 } as; 64 64 }; … … 130 130 reader::impl::worker::worker() 131 131 { 132 m_ev.add(m_notify.getfd(), EV_READ); // FIXME error 132 if( m_ev.add(m_notify.getfd(), EV_READ) < 0 ) { 133 throw event_error(errno, "iothreads reader failed to initialize event notifier"); 134 } 133 135 } 134 136 … … 153 155 { 154 156 notify_entry e = { MESSAGE }; 155 e.as.m .func = msg;156 e.as.m .fd = fd;157 e.as.message.func = msg; 158 e.as.message.fd = fd; 157 159 try { 158 160 m_notify.send(e); … … 170 172 if(m_ev.wait(1000) < 0) { // FIXME 171 173 if(errno != EAGAIN && errno != EINTR) { 172 throw std::runtime_error("reader event failed");174 throw event_error(errno, "iothreads reader event failed"); 173 175 } 174 176 } … … 214 216 215 217 } else { // e.type == MESSAGE 216 int fd = e.as.m.fd; 218 int fd = e.as.message.fd; 219 std::auto_ptr<message_t> func(e.as.message.func); 217 220 if(!m_ev.test(fd)) { return; } 218 message_t* func = e.as.m.func; 219 try { 220 (*func)(*m_ev.data(fd)); 221 } catch (...) { 222 delete func; 223 throw; 221 (*func)(*m_ev.data(fd)); 222 } 223 } 224 225 inline void reader::impl::worker::add_handler(handler* h) 226 { 227 try { 228 if( m_ev.add(h->fd(), EV_READ, h) < 0 ) { 229 throw event_error(errno, "iothreads reader failed to add event"); 224 230 } 225 delete func;226 }227 }228 229 inline void reader::impl::worker::add_handler(handler* h)230 {231 try {232 m_ev.add(h->fd(), EV_READ, h);233 231 } catch (...) { 234 232 ::close(h->fd()); -
lang/c/mpio/trunk/src/iothreads_writer.cc
r21303 r21348 185 185 struct rlimit rbuf; 186 186 if(::getrlimit(RLIMIT_NOFILE, &rbuf) < 0) { 187 throw s td::runtime_error("getrlimit() failed");187 throw system_error(errno, "getrlimit() failed"); 188 188 } 189 189 … … 386 386 writer::impl::worker::worker() 387 387 { 388 m_ev.add(m_notify.getfd(), EV_READ); // FIXME error 388 if( m_ev.add(m_notify.getfd(), EV_READ) < 0 ) { 389 throw event_error(errno, "iothreads writer failed to initialize event notifier"); 390 } 389 391 } 390 392 … … 414 416 if(m_ev.wait(1000) < 0) { // FIXME 415 417 if(errno != EAGAIN && errno != EINTR) { 416 throw std::runtime_error("writer event failed");418 throw event_error(errno, "iothreads writer event failed"); 417 419 } 418 420 } … … 469 471 impl::wake_io_ebit(e.fd); 470 472 if(!m_ev.test(e.fd)) { 471 m_ev.add(e.fd, EV_WRITE); // FIXME error 473 if( m_ev.add(e.fd, EV_WRITE) < 0 ) { 474 throw event_error(errno, "iothreads writer failed to add event"); 475 } 472 476 } 473 477 request req(e.buf, e.buflen, e.finalize, e.user, e.thread_safe);
![(please configure the [header_logo] section in trac.ini)](/share/chrome/site/your_project_logo.png)