Don't abuse goto for building simple loops

This commit is contained in:
Alexander A. Klimov 2019-03-08 14:59:01 +01:00
parent 4339240b46
commit ac354f9e80
2 changed files with 45 additions and 52 deletions

View File

@ -309,8 +309,20 @@ void Application::RunEventLoop()
double lastLoop = Utility::GetTime();
mainloop:
while (!m_ShuttingDown && !m_RequestRestart) {
while (!m_ShuttingDown) {
if (m_RequestRestart) {
m_RequestRestart = false; // we are now handling the request, once is enough
#ifdef HAVE_SYSTEMD
sd_notify(0, "RELOADING=1");
#endif /* HAVE_SYSTEMD */
// are we already restarting? ignore request if we already are
if (!l_Restarting) {
l_Restarting = true;
m_ReloadProcess = StartReloadProcess();
}
} else {
/* Watches for changes to the system time. Adjusts timers if necessary. */
Utility::Sleep(2.5);
@ -339,22 +351,6 @@ mainloop:
lastLoop = now;
}
if (m_RequestRestart) {
m_RequestRestart = false; // we are now handling the request, once is enough
#ifdef HAVE_SYSTEMD
sd_notify(0, "RELOADING=1");
#endif /* HAVE_SYSTEMD */
// are we already restarting? ignore request if we already are
if (l_Restarting)
goto mainloop;
l_Restarting = true;
m_ReloadProcess = StartReloadProcess();
goto mainloop;
}
#ifdef HAVE_SYSTEMD

View File

@ -413,12 +413,11 @@ static pid_t ProcessSpawn(const std::vector<String>& arguments, const Dictionary
msg.msg_controllen = cmsg->cmsg_len;
send_message:
while (sendmsg(l_ProcessControlFD, &msg, 0) < 0)
do {
while (sendmsg(l_ProcessControlFD, &msg, 0) < 0) {
StartSpawnProcessHelper();
if (send(l_ProcessControlFD, jrequest.CStr(), jrequest.GetLength(), 0) < 0)
goto send_message;
}
} while (send(l_ProcessControlFD, jrequest.CStr(), jrequest.GetLength(), 0) < 0);
char buf[4096];
@ -450,12 +449,11 @@ static int ProcessKill(pid_t pid, int signum)
boost::mutex::scoped_lock lock(l_ProcessControlMutex);
send_message:
while (send(l_ProcessControlFD, &length, sizeof(length), 0) < 0)
do {
while (send(l_ProcessControlFD, &length, sizeof(length), 0) < 0) {
StartSpawnProcessHelper();
if (send(l_ProcessControlFD, jrequest.CStr(), jrequest.GetLength(), 0) < 0)
goto send_message;
}
} while (send(l_ProcessControlFD, jrequest.CStr(), jrequest.GetLength(), 0) < 0);
char buf[4096];
@ -482,12 +480,11 @@ static int ProcessWaitPID(pid_t pid, int *status)
boost::mutex::scoped_lock lock(l_ProcessControlMutex);
send_message:
while (send(l_ProcessControlFD, &length, sizeof(length), 0) < 0)
do {
while (send(l_ProcessControlFD, &length, sizeof(length), 0) < 0) {
StartSpawnProcessHelper();
if (send(l_ProcessControlFD, jrequest.CStr(), jrequest.GetLength(), 0) < 0)
goto send_message;
}
} while (send(l_ProcessControlFD, jrequest.CStr(), jrequest.GetLength(), 0) < 0);
char buf[4096];