Skip to content

Commit

Permalink
Revert "新增一个线程用来更新计时器"
Browse files Browse the repository at this point in the history
This reverts commit b8ed4ca.
  • Loading branch information
1265578519 committed Apr 14, 2024
1 parent b8ed4ca commit 82b5747
Showing 1 changed file with 10 additions and 12 deletions.
22 changes: 10 additions & 12 deletions opentracker/opentracker.c
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,10 @@ static void signal_handler( int s ) {
#endif

exit( 0 );
} else if( s == SIGALRM ) {
/* Maintain our copy of the clock. time() on BSDs is very expensive. */
g_now_seconds = time(NULL);
alarm(5);
}
}

Expand All @@ -79,6 +83,7 @@ static void defaul_signal_handlers( void ) {
sigaddset (&signal_mask, SIGPIPE);
sigaddset (&signal_mask, SIGHUP);
sigaddset (&signal_mask, SIGINT);
sigaddset (&signal_mask, SIGALRM);
pthread_sigmask (SIG_BLOCK, &signal_mask, NULL);
}

Expand All @@ -90,10 +95,11 @@ static void install_signal_handlers( void ) {
sa.sa_handler = signal_handler;
sigemptyset(&sa.sa_mask);
sa.sa_flags = SA_RESTART;
if ((sigaction(SIGINT, &sa, NULL) == -1))
if ((sigaction(SIGINT, &sa, NULL) == -1) || (sigaction(SIGALRM, &sa, NULL) == -1) )
panic( "install_signal_handlers" );

sigaddset (&signal_mask, SIGINT);
sigaddset (&signal_mask, SIGALRM);
pthread_sigmask (SIG_UNBLOCK, &signal_mask, NULL);
}

Expand Down Expand Up @@ -602,22 +608,12 @@ int drop_privileges ( const char * const serveruser, const char * const serverdi
return 0;
}

/* Maintain our copy of the clock. time() on BSDs is very expensive. */
static void *time_caching_worker(void*args) {
(void)args;
while (1) {
g_now_seconds = time(NULL);
sleep(5);
}
}

int main( int argc, char **argv ) {
ot_ip6 serverip;
ot_net tmpnet;
int bound = 0, scanon = 1;
uint16_t tmpport;
char * statefile = 0;
pthread_t thread_id; /* time cacher */

memset( serverip, 0, sizeof(ot_ip6) );
#ifdef WANT_V4_ONLY
Expand Down Expand Up @@ -694,7 +690,6 @@ int main( int argc, char **argv ) {
panic( "drop_privileges failed, exiting. Last error");

g_now_seconds = time( NULL );
pthread_create( &thread_id, NULL, time_caching_worker, NULL);

/* Create our self pipe which allows us to interrupt mainloops
io_wait in case some data is available to send out */
Expand All @@ -719,6 +714,9 @@ int main( int argc, char **argv ) {
if( !g_udp_workers )
udp_init( -1, 0 );

/* Kick off our initial clock setting alarm */
alarm(5);

server_mainloop( 0 );

return 0;
Expand Down

0 comments on commit 82b5747

Please sign in to comment.