Currently I have this:
Code:
bool gasp_thread_signal(
char const *src, int ext_pipes[2], int int_pipes[2], int sig
)
{
int ret = SIGSTOP;
struct pollfd pfd = {0};
node_t n = 0;
pfd.fd = int_pipes[0];
pfd.events = POLLIN;
write( ext_pipes[0], &sig, sizeof(int) );
fprintf( stderr, "%s thread is now waiting\n", src );
while ( ret != SIGCONT )
{
while ( poll( &pfd, 1, CLOCKS_PER_SEC ) == 0 );
read( int_pipes[0], &ret, sizeof(int) );
if ( n == UCHAR_MAX ) {
fputs( "Poll limit reached, aborting attempt\n", stderr );
return 0;
}
++n;
}
fprintf( stderr, "%s thread is now running\n", src );
return 1;
}
bool gasp_thread_should_die(
char const *src, int ext_pipes[2], int int_pipes[2]
)
{
int ret = SIGCONT;
struct pollfd pfd = {0};
pfd.fd = int_pipes[0];
pfd.events = POLLIN;
if ( poll( &pfd, 1, 10 ) )
{
read( int_pipes[0], &ret, sizeof(int) );
switch ( ret )
{
case SIGKILL:
return 1;
case SIGSTOP:
return !gasp_thread_signal(
src, ext_pipes, int_pipes, SIGCONT );
}
}
return 0;
}
Since it's not quite working I must be doing something wrong, any ideas?