Ejemplo n.º 1
0
    void run(void)
    {
        running = true;

        BOOST_REQUIRE(sf.empty());

        thread reader(boost::bind(&spsc_queue_tester::get, this));
        thread writer(boost::bind(&spsc_queue_tester::add, this));
        cout << "reader and writer threads created" << endl;

        writer.join();
        cout << "writer threads joined. waiting for readers to finish" << endl;

        reader.join();

        BOOST_REQUIRE_EQUAL(received_nodes, nodes_per_thread);
        BOOST_REQUIRE_EQUAL(spsc_queue_cnt, 0);
        BOOST_REQUIRE(sf.empty());
        BOOST_REQUIRE(working_set.count_nodes() == 0);
    }
Ejemplo n.º 2
0
    void add(void)
    {
        for (boost::uint32_t i = 0; i != nodes_per_thread; ++i) {
            int id = generate_id<int>();
            working_set.insert(id);

            while (sf.push(id) == false)
            {}

            ++spsc_queue_cnt;
        }
        running = false;
    }
Ejemplo n.º 3
0
    bool get_element(void)
    {
        int data;
        bool success = sf.pop(data);

        if (success) {
            ++received_nodes;
            --spsc_queue_cnt;
            bool erased = working_set.erase(data);
            assert(erased);
            return true;
        } else
            return false;
    }
Ejemplo n.º 4
0
    bool get_elements(void)
    {
        boost::array<int, buf_size> output_buffer;

        size_t popd = sf.pop(output_buffer.c_array(), output_buffer.size());

        if (popd) {
            received_nodes += popd;
            spsc_queue_cnt -= popd;

            for (size_t i = 0; i != popd; ++i) {
                bool erased = working_set.erase(output_buffer[i]);
                assert(erased);
            }

            return true;
        } else
            return false;
    }
Ejemplo n.º 5
0
    void add(void)
    {
        boost::array<int, buf_size> input_buffer;
        for (boost::uint32_t i = 0; i != nodes_per_thread; i+=buf_size) {
            for (size_t i = 0; i != buf_size; ++i) {
                int id = generate_id<int>();
                working_set.insert(id);
                input_buffer[i] = id;
            }

            size_t pushed = 0;

            do {
                pushed += sf.push(input_buffer.c_array() + pushed,
                                  input_buffer.size()    - pushed);
            } while (pushed != buf_size);

            spsc_queue_cnt+=buf_size;
        }
    }
Ejemplo n.º 6
0
 inline void yield(vector<double> &s){ data_queue.push(s); };