1
0
mirror of https://github.com/wolfpld/tracy.git synced 2025-03-20 07:40:02 +08:00

Fix shutdown with TRACY_NO_EXIT=1 on Android. (#134)

This commit is contained in:
bjacob
2020-11-26 14:33:54 -05:00
committed by GitHub
parent 0073fd739f
commit dfdf70aea3
4 changed files with 106 additions and 67 deletions
+18 -6
View File
@@ -33,18 +33,30 @@ void _start()
int kernelFd = sym_open( "/sys/kernel/debug/tracing/trace_pipe", O_RDONLY );
if( kernelFd < 0 ) sym_exit( 0 );
struct pollfd pfd;
pfd.fd = kernelFd;
pfd.events = POLLIN | POLLERR;
struct pollfd pfd_in;
pfd_in.fd = kernelFd;
pfd_in.events = POLLIN | POLLERR;
struct pollfd pfd_out;
pfd_out.fd = STDOUT_FILENO;
pfd_out.events = POLLERR;
struct timespec sleepTime;
sleepTime.tv_sec = 0;
sleepTime.tv_nsec = 1000 * 1000 * 10;
for(;;)
// While the pipe is open (no POLLERR on the output fd)
while( sym_poll( &pfd_out, 1, 0) <= 0 )
{
while( sym_poll( &pfd, 1, 0 ) <= 0 ) sym_nanosleep( &sleepTime, NULL );
const int rd = sym_read( kernelFd, buf, BufSize );
// If there is neither data (POLLIN) nor an error (POLLERR) on
// the read fd, sleep. This implements a blocking read without relying
// on the Linux kernel's implementation of blocking reads which causes
// a large number of context switches.
if( sym_poll( &pfd_in, 1, 0 ) <= 0 ) {
sym_nanosleep( &sleepTime, NULL );
continue; // go back to the while condition polling the output fd
}
const ssize_t rd = sym_read( kernelFd, buf, BufSize );
if( rd <= 0 ) break;
sym_write( STDOUT_FILENO, buf, rd );
}