// // mp::iothreads // // Copyright (C) 2008 FURUHASHI Sadayuki // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. // You may obtain a copy of the License at // // http://www.apache.org/licenses/LICENSE-2.0 // // Unless required by applicable law or agreed to in writing, software // distributed under the License is distributed on an "AS IS" BASIS, // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. // See the License for the specific language governing permissions and // limitations under the License. // #ifndef MP_IOTHREADS_IMPL_H__ #define MP_IOTHREADS_IMPL_H__ namespace mp { namespace iothreads { template inline ThreadIMPL* manager::add_thread() { return instance().add_thread_impl(); } MP_ARGS_BEGIN template inline ThreadIMPL* manager::add_thread(MP_ARGS_PARAMS) { return instance().add_thread_impl(MP_ARGS_FUNC); } MP_ARGS_END template ThreadIMPL* manager::add_thread_impl() { ThreadIMPL* impl = m_zone.allocate(); m_threads.push_back(pthread_thread(impl)); return impl; } MP_ARGS_BEGIN template ThreadIMPL* manager::add_thread_impl(MP_ARGS_PARAMS) { ThreadIMPL* impl = m_zone.allocate(MP_ARGS_FUNC); m_threads.push_back(pthread_thread(impl)); return impl; } MP_ARGS_END inline void manager::submit_impl(function func) { m_messages.push_back(func); } inline void manager::submit(function func) { instance().submit_impl(func); } inline void manager::run() { instance().run_impl(); } inline void manager::end() { instance().m_end_flag = 1; } inline bool manager::is_end() { return instance().m_end_flag == 1; } inline void manager::join() { instance().join_impl(); } inline void manager::join_impl() { for(threads_t::iterator it(m_threads.begin()), it_end(m_threads.end()); it != it_end; ++it) { it->join(); } } } // namespace iothreads } // namespace mp #endif /* mp/iothreads_impl.h */