mirror of
https://github.com/mutouyun/cpp-ipc.git
synced 2025-12-06 16:56:45 +08:00
fine-tune code
This commit is contained in:
parent
6a3c3cde23
commit
be15b2377f
@ -286,8 +286,9 @@ public:
|
|||||||
}
|
}
|
||||||
|
|
||||||
template <typename F>
|
template <typename F>
|
||||||
bool pop(detail::u2_t& cur, F&& f) noexcept {
|
bool pop(detail::u2_t* cur, F&& f) noexcept {
|
||||||
return base_t::pop(this, cur, std::forward<F>(f), block_);
|
if (cur == nullptr) return false;
|
||||||
|
return base_t::pop(this, *cur, std::forward<F>(f), block_);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@ -45,7 +45,7 @@ public:
|
|||||||
return elems_;
|
return elems_;
|
||||||
}
|
}
|
||||||
|
|
||||||
std::size_t connect() noexcept {
|
std::size_t connect() {
|
||||||
if (elems_ == nullptr) return invalid_value;
|
if (elems_ == nullptr) return invalid_value;
|
||||||
if (connected_.exchange(true, std::memory_order_acq_rel)) {
|
if (connected_.exchange(true, std::memory_order_acq_rel)) {
|
||||||
// if it's already connected, just return an error count
|
// if it's already connected, just return an error count
|
||||||
@ -56,7 +56,7 @@ public:
|
|||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
std::size_t disconnect() noexcept {
|
std::size_t disconnect() {
|
||||||
if (elems_ == nullptr) return invalid_value;
|
if (elems_ == nullptr) return invalid_value;
|
||||||
if (!connected_.exchange(false, std::memory_order_acq_rel)) {
|
if (!connected_.exchange(false, std::memory_order_acq_rel)) {
|
||||||
// if it's already disconnected, just return an error count
|
// if it's already disconnected, just return an error count
|
||||||
@ -115,7 +115,7 @@ public:
|
|||||||
}
|
}
|
||||||
|
|
||||||
template <typename... P>
|
template <typename... P>
|
||||||
auto push(P&&... params) noexcept {
|
auto push(P&&... params) {
|
||||||
if (elems_ == nullptr) return false;
|
if (elems_ == nullptr) return false;
|
||||||
if (elems_->push([&](void* p) {
|
if (elems_->push([&](void* p) {
|
||||||
::new (p) T(std::forward<P>(params)...);
|
::new (p) T(std::forward<P>(params)...);
|
||||||
@ -126,13 +126,13 @@ public:
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
T pop() noexcept {
|
T pop() {
|
||||||
if (elems_ == nullptr) {
|
if (elems_ == nullptr) {
|
||||||
return {};
|
return {};
|
||||||
}
|
}
|
||||||
T item;
|
T item;
|
||||||
for (unsigned k = 0;;) {
|
for (unsigned k = 0;;) {
|
||||||
if (elems_->pop(cursor_, [&item](void* p) {
|
if (elems_->pop(&cursor_, [&item](void* p) {
|
||||||
::new (&item) T(std::move(*static_cast<T*>(p)));
|
::new (&item) T(std::move(*static_cast<T*>(p)));
|
||||||
})) {
|
})) {
|
||||||
return item;
|
return item;
|
||||||
|
|||||||
@ -136,7 +136,7 @@ struct test_cq<ipc::circ::elem_array<D, P>> {
|
|||||||
void recv(cn_t cur, F&& proc) {
|
void recv(cn_t cur, F&& proc) {
|
||||||
while (1) {
|
while (1) {
|
||||||
msg_t msg;
|
msg_t msg;
|
||||||
while (ca_->pop(cur, [&msg](void* p) {
|
while (ca_->pop(&cur, [&msg](void* p) {
|
||||||
msg = *static_cast<msg_t*>(p);
|
msg = *static_cast<msg_t*>(p);
|
||||||
})) {
|
})) {
|
||||||
if (msg.pid_ < 0) {
|
if (msg.pid_ < 0) {
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user