mirror of
https://github.com/AxioDL/boo.git
synced 2025-05-15 20:01:33 +00:00
Fixed main thread join issue
This commit is contained in:
parent
0be417f0b0
commit
c5db148e98
@ -221,15 +221,29 @@ public:
|
|||||||
return PLAT_XLIB;
|
return PLAT_XLIB;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* Empty handler for SIGTERM */
|
||||||
|
static void _sigterm(int) {}
|
||||||
|
|
||||||
int run()
|
int run()
|
||||||
{
|
{
|
||||||
if (!m_xDisp)
|
if (!m_xDisp)
|
||||||
return 1;
|
return 1;
|
||||||
|
|
||||||
|
/* SIGTERM will be used to terminate main thread when client thread ends */
|
||||||
|
pthread_t mainThread = pthread_self();
|
||||||
|
struct sigaction s;
|
||||||
|
s.sa_handler = _sigterm;
|
||||||
|
sigemptyset(&s.sa_mask);
|
||||||
|
s.sa_flags = 0;
|
||||||
|
sigaction(SIGTERM, &s, nullptr);
|
||||||
|
|
||||||
/* Spawn client thread */
|
/* Spawn client thread */
|
||||||
int clientReturn = INT_MIN;
|
int clientReturn = INT_MIN;
|
||||||
std::thread clientThread([&]()
|
std::thread clientThread([&]()
|
||||||
{clientReturn = m_callback.appMain(this);});
|
{
|
||||||
|
clientReturn = m_callback.appMain(this);
|
||||||
|
pthread_kill(mainThread, SIGTERM);
|
||||||
|
});
|
||||||
|
|
||||||
/* Begin application event loop */
|
/* Begin application event loop */
|
||||||
while (clientReturn == INT_MIN)
|
while (clientReturn == INT_MIN)
|
||||||
@ -238,7 +252,12 @@ public:
|
|||||||
FD_ZERO(&fds);
|
FD_ZERO(&fds);
|
||||||
FD_SET(m_xcbFd, &fds);
|
FD_SET(m_xcbFd, &fds);
|
||||||
FD_SET(m_dbusFd, &fds);
|
FD_SET(m_dbusFd, &fds);
|
||||||
select(m_maxFd+1, &fds, NULL, NULL, NULL);
|
if (select(m_maxFd+1, &fds, NULL, NULL, NULL) < 0)
|
||||||
|
{
|
||||||
|
/* SIGTERM handled here */
|
||||||
|
if (errno == EINTR)
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
if (FD_ISSET(m_xcbFd, &fds))
|
if (FD_ISSET(m_xcbFd, &fds))
|
||||||
{
|
{
|
||||||
|
Loading…
x
Reference in New Issue
Block a user