delete extra IPC thread, update simple-ipc

This commit is contained in:
nullifiedcat 2017-08-18 12:30:25 +03:00
parent 89bf29f17d
commit d643b133cc
4 changed files with 5 additions and 22 deletions

@ -1 +1 @@
Subproject commit 94b3e53b00ac5be465ebe44ea5fe1b1fbc18aa8f Subproject commit 98934e7579ac276ba1a1972db3e1eb741c789068

View File

@ -427,6 +427,9 @@ void FrameStageNotify_hook(void* _this, int stage) {
static Timer ipc_timer {}; static Timer ipc_timer {};
if (ipc_timer.test_and_set(1000)) { if (ipc_timer.test_and_set(1000)) {
if (ipc::peer) { if (ipc::peer) {
if (ipc::peer->HasCommands()) {
ipc::peer->ProcessCommands();
}
ipc::Heartbeat(); ipc::Heartbeat();
ipc::UpdateTemporaryData(); ipc::UpdateTemporaryData();
} }

View File

@ -16,19 +16,6 @@
namespace ipc { namespace ipc {
std::atomic<bool> thread_running(false);
pthread_t listener_thread { 0 };
void* listen(void*) {
while (thread_running) {
if (peer->HasCommands()) {
peer->ProcessCommands();
}
usleep(10000);
}
return 0;
}
CatCommand fix_deadlock("ipc_fix_deadlock", "Fix deadlock", []() { CatCommand fix_deadlock("ipc_fix_deadlock", "Fix deadlock", []() {
if (peer) { if (peer) {
pthread_mutex_unlock(&peer->memory->mutex); pthread_mutex_unlock(&peer->memory->mutex);
@ -36,7 +23,7 @@ CatCommand fix_deadlock("ipc_fix_deadlock", "Fix deadlock", []() {
}); });
CatCommand connect("ipc_connect", "Connect to IPC server", []() { CatCommand connect("ipc_connect", "Connect to IPC server", []() {
if (peer || thread_running) { if (peer) {
logging::Info("Already connected!"); logging::Info("Already connected!");
return; return;
} }
@ -60,8 +47,6 @@ CatCommand connect("ipc_connect", "Connect to IPC server", []() {
data.total_score = o_total_score; data.total_score = o_total_score;
StoreClientData(); StoreClientData();
Heartbeat(); Heartbeat();
thread_running = true;
pthread_create(&listener_thread, nullptr, listen, nullptr);
} catch (std::exception& error) { } catch (std::exception& error) {
logging::Info("Runtime error: %s", error.what()); logging::Info("Runtime error: %s", error.what());
delete peer; delete peer;
@ -83,10 +68,7 @@ CatCommand lobby("ipc_lobby", "Join a lobby", [](const CCommand& args) {
peer->SendMessage(format("connect_lobby ", lobby64).c_str(), 0, ipc::commands::execute_client_cmd, 0, 0); peer->SendMessage(format("connect_lobby ", lobby64).c_str(), 0, ipc::commands::execute_client_cmd, 0, 0);
}); });
CatCommand disconnect("ipc_disconnect", "Disconnect from IPC server", []() { CatCommand disconnect("ipc_disconnect", "Disconnect from IPC server", []() {
thread_running = false;
pthread_join(listener_thread, nullptr);
if (peer) delete peer; if (peer) delete peer;
listener_thread = 0;
peer = nullptr; peer = nullptr;
}); });
CatCommand exec("ipc_exec", "Execute command (first argument = bot ID)", [](const CCommand& args) { CatCommand exec("ipc_exec", "Execute command (first argument = bot ID)", [](const CCommand& args) {
@ -163,7 +145,6 @@ void UpdateServerAddress(bool shutdown) {
s_addr = g_IEngine->GetNetChannelInfo()->GetAddress(); s_addr = g_IEngine->GetNetChannelInfo()->GetAddress();
} }
peer_t::MutexLock lock(peer);
user_data_s& data = peer->memory->peer_user_data[peer->client_id]; user_data_s& data = peer->memory->peer_user_data[peer->client_id];
data.friendid = g_ISteamUser->GetSteamID().GetAccountID(); data.friendid = g_ISteamUser->GetSteamID().GetAccountID();
strncpy(data.server, s_addr, sizeof(data.server)); strncpy(data.server, s_addr, sizeof(data.server));

View File

@ -39,7 +39,6 @@ extern CatCommand exec_all;
extern CatCommand lobby; extern CatCommand lobby;
extern CatVar server_name; extern CatVar server_name;
extern pthread_t listener_thread;
constexpr unsigned cathook_magic_number = 0x0DEADCA7; constexpr unsigned cathook_magic_number = 0x0DEADCA7;
struct server_data_s { struct server_data_s {