- split "show ips" handler from bx_signal_handler to simplify usage without alarm()

This commit is contained in:
Volker Ruppert 2012-08-26 12:32:10 +00:00
parent ae74c5a1d0
commit c2f9150497
5 changed files with 31 additions and 27 deletions

View File

@ -424,7 +424,10 @@ typedef struct {
#endif
} bx_debug_t;
BOCHSAPI_MSVCONLY void CDECL bx_signal_handler(int signum);
#if BX_SHOW_IPS
BOCHSAPI_MSVCONLY void bx_show_ips_handler(void);
#endif
void CDECL bx_signal_handler(int signum);
int bx_atexit(void);
BOCHSAPI extern bx_debug_t bx_dbg;

View File

@ -146,12 +146,6 @@ static bxevent_handler old_callback = NULL;
static void *old_callback_arg = NULL;
#endif
#if BX_SHOW_IPS
#if defined(__MINGW32__) || defined(_MSC_VER)
void bx_signal_handler(int);
#endif
#endif
void switch_to_windowed(void)
{
@ -250,7 +244,7 @@ void switch_to_fullscreen(void)
#if defined(__MINGW32__) || defined(_MSC_VER)
Uint32 SDLCALL sdlTimer(Uint32 interval)
{
bx_signal_handler(SIGALRM);
bx_show_ips_handler();
return interval;
}
#endif

View File

@ -2203,7 +2203,7 @@ void bx_win32_gui_c::set_mouse_mode_absxy(bx_bool mode)
#if BX_SHOW_IPS
VOID CALLBACK MyTimer(HWND hwnd,UINT uMsg, UINT idEvent, DWORD dwTime)
{
bx_signal_handler(SIGALRM);
bx_show_ips_handler();
}
void bx_win32_gui_c::show_ips(Bit32u ips_count)

View File

@ -175,7 +175,7 @@ void MyPanel::OnTimer(wxTimerEvent& WXUNUSED(event))
#if BX_SHOW_IPS
static int i = 10;
if (--i <= 0) {
bx_signal_handler(wxSIGALRM);
bx_show_ips_handler();
i = 10;
}
#endif

View File

@ -1411,6 +1411,28 @@ int bx_atexit(void)
return 0;
}
#if BX_SHOW_IPS
void bx_show_ips_handler(void)
{
static Bit64u ticks_count = 0;
static Bit64u counts = 0;
// amount of system ticks passed from last time the handler was called
Bit64u ips_count = bx_pc_system.time_ticks() - ticks_count;
if (ips_count) {
bx_gui->show_ips((Bit32u) ips_count);
ticks_count = bx_pc_system.time_ticks();
counts++;
if (bx_dbg.print_timestamps) {
printf("IPS: %u\taverage = %u\t\t(%us)\n",
(unsigned) ips_count, (unsigned) (ticks_count/counts), (unsigned) counts);
fflush(stdout);
}
}
return;
}
#endif
void CDECL bx_signal_handler(int signum)
{
// in a multithreaded environment, a signal such as SIGINT can be sent to all
@ -1434,23 +1456,8 @@ void CDECL bx_signal_handler(int signum)
#endif
#if BX_SHOW_IPS
static Bit64u ticks_count = 0;
static Bit64u counts = 0;
if (signum == SIGALRM)
{
// amount of system ticks passed from last time the handler was called
Bit64u ips_count = bx_pc_system.time_ticks() - ticks_count;
if (ips_count) {
bx_gui->show_ips((Bit32u) ips_count);
ticks_count = bx_pc_system.time_ticks();
counts++;
if (bx_dbg.print_timestamps) {
printf("IPS: %u\taverage = %u\t\t(%us)\n",
(unsigned) ips_count, (unsigned) (ticks_count/counts), (unsigned) counts);
fflush(stdout);
}
}
if (signum == SIGALRM) {
bx_show_ips_handler();
#if !defined(WIN32)
if (!SIM->is_wx_selected()) {
signal(SIGALRM, bx_signal_handler);