summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRoman Smrž <roman.smrz@seznam.cz>2024-04-18 21:13:39 +0200
committerRoman Smrž <roman.smrz@seznam.cz>2024-04-18 21:13:39 +0200
commit7b27c1106d77f27808639336610caeaf49f5274c (patch)
treed971b1982372a47a19d095480e9f16986b0af27d
parentab12565f52081c147d9f3cfb2ba4768379218c18 (diff)
Avoid using std::deque with incomplete type
Only some containers are allowed by the standard to be declared with incomplete types, deque is not, for vector it is ok.
-rw-r--r--include/erebos/message.h4
-rw-r--r--src/message.cpp8
2 files changed, 6 insertions, 6 deletions
diff --git a/include/erebos/message.h b/include/erebos/message.h
index b52b84b..508aa23 100644
--- a/include/erebos/message.h
+++ b/include/erebos/message.h
@@ -4,7 +4,6 @@
#include <erebos/service.h>
#include <condition_variable>
-#include <deque>
#include <functional>
#include <memory>
#include <mutex>
@@ -15,7 +14,6 @@
namespace erebos {
using std::condition_variable;
-using std::deque;
using std::mutex;
using std::tuple;
using std::unique_ptr;
@@ -160,7 +158,7 @@ private:
mutex peerSyncMutex;
condition_variable peerSyncCond;
bool peerSyncRun;
- deque<tuple<DirectMessageThread, Peer>> peerSyncQueue;
+ vector<tuple<DirectMessageThread, Peer>> peerSyncQueue;
std::thread peerSyncThread;
Watched<DirectMessageThreads> watched;
diff --git a/src/message.cpp b/src/message.cpp
index 349accb..cda2fa7 100644
--- a/src/message.cpp
+++ b/src/message.cpp
@@ -520,13 +520,15 @@ void DirectMessageService::doSyncWithPeers()
continue;
}
- auto & [ thread, peer ] = peerSyncQueue.front();
+ decltype(peerSyncQueue) queue;
+ std::swap(queue, peerSyncQueue);
+
lock.unlock();
- doSyncWithPeer(thread, peer);
+ for (auto & [ thread, peer ] : queue)
+ doSyncWithPeer(thread, peer);
lock.lock();
- peerSyncQueue.pop_front();
}
}