lichao
2021-05-06 7ecd6323ffedbfef92c87c02b2a8680dd53b772c
rename atomic queue io function.
3个文件已修改
16 ■■■■ 已修改文件
src/robust.h 4 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/shm_queue.h 4 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
utest/robust_test.cpp 8 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/robust.h
@@ -307,7 +307,7 @@
    size_type tail() const { return tail_.load(); }
    bool like_empty() const { return head() == tail() && Empty(buf[head()]); }
    bool like_full() const { return head() == tail() && !Empty(buf[head()]); }
    bool push_back(const Data d, bool try_more = false)
    bool push(const Data d, bool try_more = false)
    {
        bool r = false;
        size_type i = 0;
@@ -320,7 +320,7 @@
        } while (try_more && !r && ++i < capacity);
        return r;
    }
    bool pop_front(Data &d, bool try_more = false)
    bool pop(Data &d, bool try_more = false)
    {
        bool r = false;
        Data cur;
src/shm_queue.h
@@ -74,8 +74,8 @@
        } while (steady_clock::now() < end_time);
        return false;
    }
    bool TryRead(Data &d, const bool try_more = true) { return queue_.pop_front(d, try_more); }
    bool TryWrite(const Data d, const bool try_more = true) { return queue_.push_back(d, try_more); }
    bool TryRead(Data &d, const bool try_more = true) { return queue_.pop(d, try_more); }
    bool TryWrite(const Data d, const bool try_more = true) { return queue_.push(d, try_more); }
private:
    robust::AtomicQueue<Power, Data> queue_;
utest/robust_test.cpp
@@ -38,11 +38,11 @@
    Rcb tmp;
    BOOST_CHECK(tmp.like_empty());
    BOOST_CHECK(tmp.push_back(1));
    BOOST_CHECK(tmp.push(1));
    BOOST_CHECK(tmp.tail() == 1);
    BOOST_CHECK(tmp.head() == 0);
    int64_t d;
    BOOST_CHECK(tmp.pop_front(d));
    BOOST_CHECK(tmp.pop(d));
    BOOST_CHECK(tmp.like_empty());
    BOOST_CHECK(tmp.head() == 1);
    BOOST_CHECK(tmp.tail() == 1);
@@ -63,7 +63,7 @@
    auto Writer = [&]() {
        uint64_t n = 0;
        while ((n = nwrite++) < nmsg) {
            while (!rcb->push_back(n, try_more)) {
            while (!rcb->push(n, try_more)) {
                // MySleep();
            }
            ++writedone;
@@ -73,7 +73,7 @@
    auto Reader = [&]() {
        while (nread.load() < nmsg) {
            int64_t d;
            if (rcb->pop_front(d, try_more)) {
            if (rcb->pop(d, try_more)) {
                ++nread;
                total += d;
            } else {