Changeset 18340
- Timestamp:
- 08/27/08 22:02:39 (4 months ago)
- Location:
- lang/c/mpio/trunk/mp
- Files:
-
- 7 added
- 6 modified
-
Makefile (modified) (1 diff)
-
iothreads.pre.h (modified) (2 diffs)
-
iothreads/connect.h (added)
-
iothreads/listen.h (modified) (4 diffs)
-
iothreads/parallel_io.h (modified) (3 diffs)
-
iothreads/timer.h (modified) (2 diffs)
-
multiplex (added)
-
multiplex.pre.h (added)
-
multiplex/connect.h (added)
-
multiplex/listen.h (added)
-
multiplex/timer.h (added)
-
multiplex_impl.pre.h (added)
-
pthread.h (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
-
lang/c/mpio/trunk/mp/Makefile
r18311 r18340 12 12 async.h async_impl.h \ 13 13 iothreads.h iothreads_impl.h \ 14 multiplex.h multiplex_impl.h \ 14 15 zone.h zone_impl.h \ 15 16 serialize.h \ -
lang/c/mpio/trunk/mp/iothreads.pre.h
r18311 r18340 21 21 22 22 #include "mp/blocking_vector.h" 23 #include "mp/pthread.h" 23 24 #include "mp/source.h" 24 25 #include "mp/zone.h" … … 29 30 namespace mp { 30 31 namespace iothreads { 31 32 template <typename IMPL>33 class pthread_thread {34 public:35 pthread_thread(IMPL* pimpl);36 virtual ~pthread_thread();37 private:38 pthread_t m_thread;39 static void* trampoline(void* obj);40 private:41 pthread_thread();42 pthread_thread(const pthread_thread&);43 };44 45 template <typename IMPL>46 pthread_thread<IMPL>::pthread_thread(IMPL* pimpl)47 {48 pthread_create(&m_thread, NULL,49 &pthread_thread<IMPL>::trampoline,50 reinterpret_cast<void*>(pimpl));51 }52 53 template <typename IMPL>54 pthread_thread<IMPL>::~pthread_thread() {} // FIXME55 56 template <typename IMPL>57 void* pthread_thread<IMPL>::trampoline(void* obj)58 {59 // FIXME exception60 reinterpret_cast<IMPL*>(obj)->operator()();61 return NULL;62 }63 32 64 33 -
lang/c/mpio/trunk/mp/iothreads/listen.h
r18311 r18340 30 30 31 31 struct listener { 32 private:32 private: 33 33 class listen_thread : public pthread_thread<listen_thread> { 34 34 public: … … 43 43 if(errno == EINTR || errno == EAGAIN) { continue; } 44 44 // FIXME 45 throw std::runtime_error("socket broken"); 46 } else if(sock == 0) { 47 // FIXME 48 throw std::runtime_error("socket broken"); 45 49 } 46 50 iothreads::submit(m_callback, m_obj, sock); … … 56 60 }; 57 61 58 public:62 public: 59 63 template <typename T> 60 static void listen(int lsock, void (*callback)( T*, int fd), T* obj)64 static void listen(int lsock, void (*callback)(void*, int fd), T* obj) 61 65 { 62 66 iothreads::manager::add_thread<listen_thread>(lsock, 63 reinterpret_cast<void (*)(void*,int)>(callback), 64 reinterpret_cast<void*>(obj)); 67 callback, reinterpret_cast<void*>(obj)); 65 68 } 66 69 67 private:70 private: 68 71 listener(); 69 72 }; … … 71 74 72 75 template <typename T> 73 inline void listen(int lsock, void (*callback)( T*, int fd), T* obj)76 inline void listen(int lsock, void (*callback)(void*, int fd), T* obj) 74 77 { 75 78 listener::listen(lsock, callback, obj); -
lang/c/mpio/trunk/mp/iothreads/parallel_io.h
r18311 r18340 31 31 virtual ~handler(); 32 32 public: 33 virtual int read_event() = 0; 34 virtual void unbind() = 0; 33 virtual void read_event() = 0; 35 34 virtual void connected() {} 36 35 public: … … 114 113 }; 115 114 115 typedef manager::handler handler; 116 116 117 template <typename Handler> 117 118 inline void add(int fd); … … 124 125 inline void send_data(int fd, char* buf, size_t len); 125 126 127 // FIXME interface 126 128 inline void send_message(int fd, callback_message* msg); 127 129 -
lang/c/mpio/trunk/mp/iothreads/timer.h
r18311 r18340 27 27 28 28 struct timer { 29 private:29 private: 30 30 class timer_thread : public pthread_thread<timer_thread> { 31 31 public: … … 51 51 }; 52 52 53 public:53 public: 54 54 template <typename T> 55 55 static void start(double interval_sec, void (*callback)(void*), T* obj) 56 56 { 57 57 iothreads::manager::add_thread<timer_thread>(interval_sec, 58 callback, 59 reinterpret_cast<void*>(obj)); 58 callback, reinterpret_cast<void*>(obj)); 60 59 } 61 60 }; -
lang/c/mpio/trunk/mp/pthread.h
r18310 r18340 23 23 24 24 namespace mp { 25 26 27 template <typename IMPL> 28 class pthread_thread { 29 public: 30 pthread_thread(IMPL* pimpl); 31 virtual ~pthread_thread(); 32 private: 33 pthread_t m_thread; 34 static void* trampoline(void* obj); 35 private: 36 pthread_thread(); 37 pthread_thread(const pthread_thread&); 38 }; 39 40 41 template <typename IMPL> 42 pthread_thread<IMPL>::pthread_thread(IMPL* pimpl) 43 { 44 pthread_create(&m_thread, NULL, 45 &pthread_thread<IMPL>::trampoline, 46 reinterpret_cast<void*>(pimpl)); 47 } 48 49 template <typename IMPL> 50 pthread_thread<IMPL>::~pthread_thread() {} // FIXME 51 52 template <typename IMPL> 53 void* pthread_thread<IMPL>::trampoline(void* obj) 54 { 55 // FIXME exception 56 reinterpret_cast<IMPL*>(obj)->operator()(); 57 return NULL; 58 } 25 59 26 60
![(please configure the [header_logo] section in trac.ini)](/share/chrome/site/your_project_logo.png)