some code cleanup

This commit is contained in:
hyunghwan.chung 2018-11-16 08:38:05 +00:00
parent 87978792df
commit 0777e9bdf0
2 changed files with 94 additions and 90 deletions

View File

@ -602,7 +602,6 @@ MOO_EXPORT moo_uint128_t moo_hton128 (
); );
#endif #endif
#if defined(__cplusplus) #if defined(__cplusplus)
} }
#endif #endif

View File

@ -359,6 +359,7 @@ struct xtn_t
#define GET_XTN(moo) ((xtn_t*)moo_getxtn(moo)) #define GET_XTN(moo) ((xtn_t*)moo_getxtn(moo))
static moo_t* g_moo = MOO_NULL; static moo_t* g_moo = MOO_NULL;
static int g_moo_tick_active = 0;
/* ========================================================================= */ /* ========================================================================= */
@ -2619,19 +2620,20 @@ static MOO_INLINE void swproc_all (void)
/* TODO: make this atomic */ /* TODO: make this atomic */
} }
#if defined(__DOS__) && (defined(_INTELC32_) || defined(__WATCOMC__)) #if defined(__DOS__) && (defined(_INTELC32_) || defined(__WATCOMC__))
#if defined(_INTELC32_) #if defined(_INTELC32_)
static void (*prev_timer_intr_handler) (void); static void (*dos_prev_timer_intr_handler) (void);
#else #else
static void (__interrupt *prev_timer_intr_handler) (void); static void (__interrupt *dos_prev_timer_intr_handler) (void);
#endif #endif
#if defined(_INTELC32_) #if defined(_INTELC32_)
#pragma interrupt(timer_intr_handler) #pragma interrupt(timer_intr_handler)
static void timer_intr_handler (void) static void dos_timer_intr_handler (void)
#else #else
static void __interrupt timer_intr_handler (void) static void __interrupt dos_timer_intr_handler (void)
#endif #endif
{ {
/* /*
@ -2642,111 +2644,142 @@ static void __interrupt timer_intr_handler (void)
*/ */
/* The timer interrupt (normally) occurs 18.2 times per second. */ /* The timer interrupt (normally) occurs 18.2 times per second. */
if (g_moo) moo_switchprocess (g_moo); swproc_moo ();
_chain_intr (prev_timer_intr_handler); _chain_intr (dos_prev_timer_intr_handler);
}
static void setup_tick (void)
{
dos_prev_timer_intr_handler = _dos_getvect(0x1C);
_dos_setvect (0x1C, dos_timer_intr_handler);
}
static void cancel_tick (void)
{
_dos_setvect (0x1C, dos_prev_timer_intr_handler);
} }
#elif defined(_WIN32) #elif defined(_WIN32)
static HANDLE g_tick_timer = MOO_NULL; /*INVALID_HANDLE_VALUE;*/
static HANDLE win_tick_timer = MOO_NULL; /*INVALID_HANDLE_VALUE;*/
static VOID CALLBACK arrange_process_switching (LPVOID arg, DWORD timeLow, DWORD timeHigh) static VOID CALLBACK arrange_process_switching (LPVOID arg, DWORD timeLow, DWORD timeHigh)
{ {
swproc_all (); swproc_moo ();
}
static void setup_tick (void)
{
LARGE_INTEGER li;
win_tick_timer = CreateWaitableTimer(MOO_NULL, TRUE, MOO_NULL);
if (win_tick_timer)
{
li.QuadPart = -MOO_SECNSEC_TO_NSEC(0, 20000); /* 20000 microseconds. 0.02 seconds */
SetWaitableTimer (win_tick_timer, &li, 0, arrange_process_switching, MOO_NULL, FALSE);
}
}
static void cancel_tick (void)
{
if (win_tick_timer)
{
CancelWaitableTimer (win_tick_timer);
CloseHandle (win_tick_timer);
win_tick_timer = MOO_NULL;
}
} }
#elif defined(__OS2__) #elif defined(__OS2__)
static TID g_tick_tid; static TID os2_tick_tid;
static HEV g_tick_sem; static HEV os2_tick_sem;
static HTIMER g_tick_timer; static HTIMER os2_tick_timer;
static int g_tick_done = 0; static int os2_tick_done = 0;
static void EXPENTRY os2_wait_for_timer_event (ULONG x) static void EXPENTRY os2_wait_for_timer_event (ULONG x)
{ {
APIRET rc; APIRET rc;
ULONG count; ULONG count;
rc = DosCreateEventSem (NULL, &g_tick_sem, DC_SEM_SHARED, FALSE); rc = DosCreateEventSem (NULL, &os2_tick_sem, DC_SEM_SHARED, FALSE);
if (rc != NO_ERROR) if (rc != NO_ERROR)
{ {
/* xxxx */ /* xxxx */
} }
rc = DosStartTimer (1L, (HSEM)g_tick_sem, &g_tick_timer); rc = DosStartTimer (1L, (HSEM)os2_tick_sem, &os2_tick_timer);
if (rc != NO_ERROR) if (rc != NO_ERROR)
{ {
} }
while (!g_tick_done) while (!os2_tick_done)
{ {
rc = DosWaitEventSem((HSEM)g_tick_sem, 5000L); rc = DosWaitEventSem((HSEM)os2_tick_sem, 5000L);
DosResetEventSem((HSEM)g_tick_sem, &count); DosResetEventSem((HSEM)os2_tick_sem, &count);
swproc_all (); swproc_moo ();
} }
DosStopTimer (g_tick_timer); DosStopTimer (os2_tick_timer);
DosCloseEventSem ((HSEM)g_tick_sem); DosCloseEventSem ((HSEM)os2_tick_sem);
g_tick_timer = NULL; os2_tick_timer = NULL;
g_tick_sem = NULL; os2_tick_sem = NULL;
DosExit (EXIT_THREAD, 0); DosExit (EXIT_THREAD, 0);
} }
static void setup_tick (void)
{
/* TODO: Error check */
DosCreateThread (&os2_tick_tid, os2_wait_for_timer_event, 0, 0, 4096);
}
static void cancel_tick (void)
{
if (os2_tick_sem) DosPostEventSem (os2_tick_sem);
os2_tick_done = 1;
}
#elif defined(macintosh) #elif defined(macintosh)
static TMTask g_tmtask; static TMTask mac_tmtask;
static ProcessSerialNumber g_psn; static ProcessSerialNumber mac_psn;
#define TMTASK_DELAY 50 /* milliseconds if positive, microseconds(after negation) if negative */ #define TMTASK_DELAY 50 /* milliseconds if positive, microseconds(after negation) if negative */
static pascal void timer_intr_handler (TMTask* task) static pascal void timer_intr_handler (TMTask* task)
{ {
swproc_all (); swproc_moo ();
WakeUpProcess (&g_psn); WakeUpProcess (&mac_psn);
PrimeTime ((QElem*)&g_tmtask, TMTASK_DELAY); PrimeTime ((QElem*)&mac_tmtask, TMTASK_DELAY);
} }
#else
static void arrange_process_switching (int sig)
{
swproc_all ();
}
#endif
static void setup_tick (void) static void setup_tick (void)
{ {
#if defined(__DOS__) && (defined(_INTELC32_) || defined(__WATCOMC__)) GetCurrentProcess (&mac_psn);
memset (&mac_tmtask, 0, MOO_SIZEOF(mac_tmtask));
prev_timer_intr_handler = _dos_getvect (0x1C); mac_tmtask.tmAddr = NewTimerProc (timer_intr_handler);
_dos_setvect (0x1C, timer_intr_handler); InsXTime ((QElem*)&mac_tmtask);
PrimeTime ((QElem*)&mac_tmtask, TMTASK_DELAY);
#elif defined(_WIN32)
LARGE_INTEGER li;
g_tick_timer = CreateWaitableTimer(MOO_NULL, TRUE, MOO_NULL);
if (g_tick_timer)
{
li.QuadPart = -MOO_SECNSEC_TO_NSEC(0, 20000); /* 20000 microseconds. 0.02 seconds */
SetWaitableTimer (g_tick_timer, &li, 0, arrange_process_switching, MOO_NULL, FALSE);
} }
#elif defined(__OS2__) static void cancel_tick (void)
/* TODO: Error check */ {
DosCreateThread (&g_tick_tid, os2_wait_for_timer_event, 0, 0, 4096); RmvTime ((QElem*)&mac_tmtask);
/*DisposeTimerProc (mac_tmtask.tmAddr);*/
#elif defined(macintosh) }
GetCurrentProcess (&g_psn);
MOO_MEMSET (&g_tmtask, 0, MOO_SIZEOF(g_tmtask));
g_tmtask.tmAddr = NewTimerProc (timer_intr_handler);
InsXTime ((QElem*)&g_tmtask);
PrimeTime ((QElem*)&g_tmtask, TMTASK_DELAY);
#elif defined(HAVE_SETITIMER) && defined(SIGVTALRM) && defined(ITIMER_VIRTUAL) #elif defined(HAVE_SETITIMER) && defined(SIGVTALRM) && defined(ITIMER_VIRTUAL)
static void arrange_process_switching (int sig)
{
swproc_moo ();
}
static void setup_tick (void)
{
struct itimerval itv; struct itimerval itv;
struct sigaction act; struct sigaction act;
MOO_MEMSET (&act, 0, sizeof(act)); memset (&act, 0, sizeof(act));
sigemptyset (&act.sa_mask); sigemptyset (&act.sa_mask);
act.sa_handler = arrange_process_switching; act.sa_handler = arrange_process_switching;
act.sa_flags = SA_RESTART; act.sa_flags = SA_RESTART;
@ -2759,36 +2792,10 @@ static void setup_tick (void)
itv.it_value.tv_sec = 0; itv.it_value.tv_sec = 0;
itv.it_value.tv_usec = MOO_ITIMER_TICK; itv.it_value.tv_usec = MOO_ITIMER_TICK;
setitimer (ITIMER_VIRTUAL, &itv, MOO_NULL); setitimer (ITIMER_VIRTUAL, &itv, MOO_NULL);
#else
# error UNSUPPORTED
#endif
} }
static void cancel_tick (void) static void cancel_tick (void)
{ {
#if defined(__DOS__) && (defined(_INTELC32_) || defined(__WATCOMC__))
_dos_setvect (0x1C, prev_timer_intr_handler);
#elif defined(_WIN32)
if (g_tick_timer)
{
CancelWaitableTimer (g_tick_timer);
CloseHandle (g_tick_timer);
g_tick_timer = MOO_NULL;
}
#elif defined(__OS2__)
if (g_tick_sem) DosPostEventSem (g_tick_sem);
g_tick_done = 1;
#elif defined(macintosh)
RmvTime ((QElem*)&g_tmtask);
/*DisposeTimerProc (g_tmtask.tmAddr);*/
#elif defined(HAVE_SETITIMER) && defined(SIGVTALRM) && defined(ITIMER_VIRTUAL)
struct itimerval itv; struct itimerval itv;
struct sigaction act; struct sigaction act;
@ -2802,12 +2809,10 @@ static void cancel_tick (void)
act.sa_handler = SIG_IGN; /* ignore the signal potentially fired by the one-shot arrange above */ act.sa_handler = SIG_IGN; /* ignore the signal potentially fired by the one-shot arrange above */
act.sa_flags = 0; act.sa_flags = 0;
sigaction (SIGVTALRM, &act, MOO_NULL); sigaction (SIGVTALRM, &act, MOO_NULL);
}
#else #else
# error UNSUPPORTED # error UNSUPPORTED
#endif #endif
}
/* ========================================================================= */ /* ========================================================================= */