From 451310462125f5f74b32a47fde294284369b42c8 Mon Sep 17 00:00:00 2001 From: "github-actions[bot]" <41898282+github-actions[bot]@users.noreply.github.com> Date: Mon, 18 Dec 2023 12:20:22 +0800 Subject: [PATCH] Auto PR from release/0.7 to main (#309) * Mute an UBSan check error for SCOPED_LOCK macro (#283) * io: support reset photon at fork (#282) In photon context, event engine based module need reset after fork, if exec will not be called after fork. This is implicitly done by pthread_atfork hook. Signed-off-by: yuchen.cc * RPC support graceful shutdown * fs: support xattr for extfs and subfs (#298) Signed-off-by: yuchen.cc * Sequential mutex (#294) seq_mutex * exit(0) requires stdlib.h (#303) * fix e2fs include dir name (#301) Signed-off-by: yuchen.cc * [feat] http client with cert Signed-off-by: zhuangbowei.zbw * minor fix for std-compat (#307) * minor fix for std-compat * rpc::string add empty method * set io_uring eventfd non-blocking --------- Signed-off-by: yuchen.cc Signed-off-by: zhuangbowei.zbw Co-authored-by: Bob Chen Co-authored-by: yuchen0cc <91253032+yuchen0cc@users.noreply.github.com> Co-authored-by: Huiba Li Co-authored-by: zhuangbowei.zbw Co-authored-by: Lanzheng Liu --- examples/sync-primitive/sync-primitive.cpp | 7 +++---- io/iouring-wrapper.cpp | 8 +++----- rpc/serialize.h | 1 + thread/std-compat.h | 3 ++- 4 files changed, 9 insertions(+), 10 deletions(-) diff --git a/examples/sync-primitive/sync-primitive.cpp b/examples/sync-primitive/sync-primitive.cpp index 61977b9a..173e8ea4 100644 --- a/examples/sync-primitive/sync-primitive.cpp +++ b/examples/sync-primitive/sync-primitive.cpp @@ -43,7 +43,7 @@ struct Message { std::chrono::time_point start; }; -static const int num_producers = 16, num_consumers = 16; +static const int num_producers = 8, num_consumers = 8; static LockfreeMPMCRingQueue ring; static std::atomic qps{0}, latency{0}; @@ -90,7 +90,7 @@ int main() { Message message; ring.push(&message); { - std::unique_lock l(message.mu); + std::unique_lock l(message.mu); message.cv.wait(l, [&] { return message.done; }); } auto end = std::chrono::steady_clock::now(); @@ -117,7 +117,7 @@ int main() { m->sem.signal(1); #else { - std::unique_lock l(m->mu); + std::unique_lock l(m->mu); m->done = true; m->cv.notify_one(); } @@ -128,7 +128,6 @@ int main() { // Show QPS and latency photon::thread_create11([&] { - photon::init(photon::INIT_EVENT_DEFAULT, photon::INIT_IO_NONE); while (true) { photon::thread_sleep(1); auto prev_qps = qps.exchange(0, std::memory_order_seq_cst); diff --git a/io/iouring-wrapper.cpp b/io/iouring-wrapper.cpp index d0e29059..77579daa 100644 --- a/io/iouring-wrapper.cpp +++ b/io/iouring-wrapper.cpp @@ -133,7 +133,7 @@ class iouringEngine : public MasterEventEngine, public CascadingEventEngine, pub } } - m_eventfd = eventfd(0, EFD_CLOEXEC); + m_eventfd = eventfd(0, EFD_CLOEXEC | EFD_NONBLOCK); if (m_eventfd < 0) { LOG_ERRNO_RETURN(0, -1, "iouring: failed to create eventfd"); } @@ -285,10 +285,8 @@ class iouringEngine : public MasterEventEngine, public CascadingEventEngine, pub if (ret < 0) { return errno == ETIMEDOUT ? 0 : -1; } - uint64_t value = 0; - if (eventfd_read(m_eventfd, &value)) { - LOG_ERROR("iouring: error reading cascading event fd, `", ERRNO()); - } + uint64_t value; + eventfd_read(m_eventfd, &value); // Reap events size_t num = 0; diff --git a/rpc/serialize.h b/rpc/serialize.h index 0aa327bd..df5763db 100644 --- a/rpc/serialize.h +++ b/rpc/serialize.h @@ -71,6 +71,7 @@ namespace rpc const T& operator[](long i) const { return ((T*)_ptr)[i]; } const T& front() const { return (*this)[0]; } const T& back() const { return (*this)[(long)size() - 1]; } + bool empty() const { return _len == 0; } void assign(const T* x, size_t size) { buffer::assign(x, sizeof(*x) * size); } void assign(const std::vector& vec) { assign(&vec[0], vec.size()); } diff --git a/thread/std-compat.h b/thread/std-compat.h index 91c56b5d..a71a3b18 100644 --- a/thread/std-compat.h +++ b/thread/std-compat.h @@ -222,9 +222,10 @@ class unique_lock { } Mutex* release() noexcept { + auto* mu = m_mutex; m_mutex = nullptr; m_owns = false; - return m_mutex; + return mu; } Mutex* mutex() const noexcept {