mirror of
https://github.com/BeamMP/BeamMP-Launcher.git
synced 2025-08-17 16:57:11 +00:00
[Changed] Atomic queue to concurrent queue.
This commit is contained in:
parent
c1ed5184e7
commit
8cdfe5314f
@ -41,7 +41,7 @@ add_executable(${PROJECT_NAME}
|
|||||||
src/Memory/IPC.cpp include/Memory/IPC.h
|
src/Memory/IPC.cpp include/Memory/IPC.h
|
||||||
src/Logger.cpp include/Logger.h
|
src/Logger.cpp include/Logger.h
|
||||||
#src/gui/Gui.cpp
|
#src/gui/Gui.cpp
|
||||||
include/Json.h
|
include/Json.h include/Memory/concurrentqueue.h
|
||||||
src/gui/gifs.cpp src/gui/gifs.h
|
src/gui/gifs.cpp src/gui/gifs.h
|
||||||
src/Network/Http.cpp include/Http.h
|
src/Network/Http.cpp include/Http.h
|
||||||
src/Network/Server.cpp include/Server.h
|
src/Network/Server.cpp include/Server.h
|
||||||
|
3747
include/Memory/concurrentqueue.h
Normal file
3747
include/Memory/concurrentqueue.h
Normal file
File diff suppressed because it is too large
Load Diff
@ -8,7 +8,15 @@
|
|||||||
#include "Memory/BeamNG.h"
|
#include "Memory/BeamNG.h"
|
||||||
#include "Memory/Memory.h"
|
#include "Memory/Memory.h"
|
||||||
|
|
||||||
atomic_queue::AtomicQueue2<std::string, 1000> AtomicQueue;
|
#include <vector>
|
||||||
|
#include <Memory/concurrentqueue.h>
|
||||||
|
|
||||||
|
struct QueueTraits : public moodycamel::ConcurrentQueueDefaultTraits {
|
||||||
|
static const size_t BLOCK_SIZE = 4; // Use bigger blocks
|
||||||
|
static const size_t MAX_SUBQUEUE_SIZE = 1000;
|
||||||
|
};
|
||||||
|
|
||||||
|
moodycamel::ConcurrentQueue<std::string, QueueTraits> ConcQueue;
|
||||||
|
|
||||||
int BeamNG::lua_open_jit_D(lua_State* State) {
|
int BeamNG::lua_open_jit_D(lua_State* State) {
|
||||||
Memory::Print("Got lua State");
|
Memory::Print("Got lua State");
|
||||||
@ -55,7 +63,7 @@ int Game(lua_State* L) {
|
|||||||
|
|
||||||
int LuaPop(lua_State* L) {
|
int LuaPop(lua_State* L) {
|
||||||
std::string MSG;
|
std::string MSG;
|
||||||
if (AtomicQueue.try_pop(MSG)) {
|
if (ConcQueue.try_dequeue(MSG)) {
|
||||||
GELua::lua_push_fstring(L, "%s", MSG.c_str());
|
GELua::lua_push_fstring(L, "%s", MSG.c_str());
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
@ -76,13 +84,21 @@ void BeamNG::SendIPC(const std::string& Data) {
|
|||||||
IPCToLauncher->send(Data);
|
IPCToLauncher->send(Data);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
std::unique_ptr <std::vector<std::string>> ptr1;
|
||||||
|
|
||||||
void BeamNG::IPCListener() {
|
void BeamNG::IPCListener() {
|
||||||
int TimeOuts = 0;
|
int TimeOuts = 0;
|
||||||
|
int QueueTimeOut = 0;
|
||||||
while(TimeOuts < 20) {
|
while(TimeOuts < 20) {
|
||||||
IPCFromLauncher->receive();
|
IPCFromLauncher->receive();
|
||||||
if (!IPCFromLauncher->receive_timed_out()) {
|
if (!IPCFromLauncher->receive_timed_out()) {
|
||||||
TimeOuts = 0;
|
TimeOuts = 0;
|
||||||
AtomicQueue.push(IPCFromLauncher->msg());
|
do {
|
||||||
|
QueueTimeOut++;
|
||||||
|
std::this_thread::sleep_for(std::chrono::milliseconds (500));
|
||||||
|
} while (QueueTimeOut < 10 && !ConcQueue.enqueue(IPCFromLauncher->msg()));
|
||||||
|
QueueTimeOut = 0;
|
||||||
|
|
||||||
IPCFromLauncher->confirm_receive();
|
IPCFromLauncher->confirm_receive();
|
||||||
} else TimeOuts++;
|
} else TimeOuts++;
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user