Skip to content

add atomic variable to check application ready. #18

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 10 additions & 4 deletions src/plugins/servicebackends/windows/windowsservicebackend.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ Q_LOGGING_CATEGORY(logBackend, "qt.service.plugin.windows.backend")
QPointer<WindowsServiceBackend> WindowsServiceBackend::_backendInstance;

static QString xPath;
static std::atomic<bool> isApplicationReady{false};

WindowsServiceBackend::WindowsServiceBackend(Service *service) :
ServiceBackend{service}
Expand Down Expand Up @@ -130,6 +131,7 @@ int WindowsServiceBackend::runService(int &argc, char **argv, int flags)

//execute the app
qCDebug(logBackend) << "running application";
isApplicationReady = true;
_status.dwServiceSpecificExitCode = app.exec();
if(_status.dwServiceSpecificExitCode != EXIT_SUCCESS)
_status.dwWin32ExitCode = ERROR_SERVICE_SPECIFIC_ERROR;
Expand Down Expand Up @@ -230,10 +232,14 @@ void WindowsServiceBackend::serviceMain(DWORD dwArgc, wchar_t **lpszArgv)
lock.unlock();

// wait for the mainthread to finish startup, then register the service handler
lock.relock();
qCDebug(logBackend) << "wait for main thread to finish startup";
_backendInstance->_startCondition.wait(&_backendInstance->_svcLock);
lock.unlock();
// we wait until variable isApplicationReady become true
while (!isApplicationReady)
{
lock.relock();
qCDebug(logBackend) << "wait for main thread to finish startup";
_backendInstance->_startCondition.wait(&_backendInstance->_svcLock, 5000);
lock.unlock();
}

// handle the start event
qCDebug(logBackend) << "handle service start event";
Expand Down