reason for speed change; refactor.
| | |
| | | set(CMAKE_CXX_STANDARD_REQUIRED True) |
| | | |
| | | if(CMAKE_GENERATOR MATCHES "Ninja") |
| | | #check_and_add_flag(DIAGNOSTICS_COLOR -fdiagnostics-color) |
| | | set(CMAKE_CXX_FLAGS ${CMAKE_CXX_FLAGS} -fdiagnostics-color=always) |
| | | set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fdiagnostics-color=always") |
| | | endif() |
| | | # control where the static and shared libraries are built so that on windows |
| | | # we don't need to tinker with the path to run the executable |
| | |
| | | void FreeFrom(SharedMemory &shm); |
| | | }; |
| | | |
| | | Msg BuildMsg(const MQId &src, const void *p, const size_t size); |
| | | inline void swap(Msg &m1, Msg &m2) { m1.swap(m2); } |
| | | |
| | | |
| | | } // namespace bhome_shm |
| | |
| | | { |
| | | Queue *remote = find(MsgQIdToName(remote_id)); |
| | | |
| | | return remote && remote->Write(msg, timeout_ms); |
| | | |
| | | if(!remote) { |
| | | return false; |
| | | } |
| | |
| | | |
| | | bool ShmMsgQueue::Send(const MQId &remote_id, const void *data, const size_t size, const int timeout_ms) |
| | | { |
| | | // Test shows that in the 2 cases: |
| | | // 1) build msg first, then find remote queue; |
| | | // 2) find remote queue first, then build msg; |
| | | // 1 is about 50% faster than 2, maybe cache related. |
| | | |
| | | Msg msg; |
| | | if (msg.Build(shm(), Id(), data, size, false)) { |
| | | if (Send(remote_id, msg, timeout_ms)) { |
| | |
| | | using Super::size; |
| | | using Super::capacity; |
| | | const MQId &Id() const { return id_; } |
| | | bool Write(D buf, const int timeout_ms) { |
| | | bool Write(const D &buf, const int timeout_ms) { |
| | | Guard lock(mutex()); |
| | | if (cond_write_.timed_wait(lock, MSFromNow(timeout_ms), [&]() { return !this->full(); })) { |
| | | this->push_back(buf); |
| | |
| | | bool Read(D &buf, const int timeout_ms){ |
| | | Guard lock(mutex()); |
| | | if (cond_read_.timed_wait(lock, MSFromNow(timeout_ms), [&]() { return !this->empty(); })) { |
| | | buf = this->front(); |
| | | using std::swap; |
| | | swap(buf, this->front()); |
| | | this->pop_front(); |
| | | cond_write_.notify_one(); |
| | | return true; |