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 {