Ejemplo n.º 1
0
    void output_stream::write_async(detail::buffer const& in)
    { // {{{
        if (in.empty())
            return;

        // Perform the IO in another OS thread.
        hpx::get_thread_pool("io_pool")->get_io_service().post(
            boost::bind(&output_stream::call_write_async, this, in));
    } // }}}
Ejemplo n.º 2
0
    void output_stream::call_write_sync(detail::buffer in,
        threads::thread_id_type caller)
    {
        // Perform the IO operation.
        in.write(write_f, mtx_);

        // Wake up caller.
        threads::set_thread_state(caller, threads::pending);
    }
Ejemplo n.º 3
0
        void output(boost::uint32_t locality_id, boost::uint64_t count,
            detail::buffer in, F const& write_f, Mutex& mtx)
        {
            typename Mutex::scoped_lock l(mtx);
            data_type& data = output_data_map_[locality_id];

            if (count == data.first)
            {
                // this is the next expected output line
                if (!in.empty())
                {
                    // output the line as requested
                    util::scoped_unlock<typename Mutex::scoped_lock> ul(l);
                    in.write(write_f, mtx);
                }
                ++data.first;

                // print all consecutive pending buffers
                output_data_type::iterator next = data.second.find(++count);
                while (next != data.second.end())
                {
                    buffer next_in = (*next).second;
                    if (!next_in.empty())
                    {
                        // output the next line
                        util::scoped_unlock<typename Mutex::scoped_lock> ul(l);
                        next_in.write(write_f, mtx);
                    }
                    data.second.erase(next);

                    // find next entry in map
                    ++data.first;
                    next = data.second.find(++count);
                }
            }
            else
            {
                HPX_ASSERT(count > data.first);
                data.second.insert(output_data_type::value_type(count, in));
            }
        }
Ejemplo n.º 4
0
    void output_stream::write_sync(detail::buffer const& in)
    { // {{{
        if (in.empty())
            return;

        // Perform the IO in another OS thread.
        hpx::get_thread_pool("io_pool")->get_io_service().post(
            boost::bind(&output_stream::call_write_sync, this, in,
                threads::get_self_id()));

        // Sleep until the worker thread wakes us up.
        this_thread::suspend(threads::suspended, "output_stream::write_sync");
    } // }}}
Ejemplo n.º 5
0
 void output_stream::call_write_async(detail::buffer in)
 { // {{{
     // Perform the IO operation.
     in.write(write_f, mtx_);
 } // }}}