changed setup_tick() and cancel_tick() to moo_start_tick() and moo_stop_tick()

This commit is contained in:
hyunghwan.chung 2018-11-19 15:52:26 +00:00
parent 2e75b97b11
commit 44c72e07e6
9 changed files with 181 additions and 295 deletions

View File

@ -355,6 +355,7 @@ pdfdir = @pdfdir@
prefix = @prefix@ prefix = @prefix@
program_transform_name = @program_transform_name@ program_transform_name = @program_transform_name@
psdir = @psdir@ psdir = @psdir@
runstatedir = @runstatedir@
sbindir = @sbindir@ sbindir = @sbindir@
sharedstatedir = @sharedstatedir@ sharedstatedir = @sharedstatedir@
srcdir = @srcdir@ srcdir = @srcdir@
@ -585,7 +586,7 @@ distdir: $(DISTFILES)
! -type d ! -perm -444 -exec $(install_sh) -c -m a+r {} {} \; \ ! -type d ! -perm -444 -exec $(install_sh) -c -m a+r {} {} \; \
|| chmod -R a+r "$(distdir)" || chmod -R a+r "$(distdir)"
dist-gzip: distdir dist-gzip: distdir
tardir=$(distdir) && $(am__tar) | eval GZIP= gzip $(GZIP_ENV) -c >$(distdir).tar.gz tardir=$(distdir) && $(am__tar) | GZIP=$(GZIP_ENV) gzip -c >$(distdir).tar.gz
$(am__post_remove_distdir) $(am__post_remove_distdir)
dist-bzip2: distdir dist-bzip2: distdir
@ -611,7 +612,7 @@ dist-shar: distdir
@echo WARNING: "Support for shar distribution archives is" \ @echo WARNING: "Support for shar distribution archives is" \
"deprecated." >&2 "deprecated." >&2
@echo WARNING: "It will be removed altogether in Automake 2.0" >&2 @echo WARNING: "It will be removed altogether in Automake 2.0" >&2
shar $(distdir) | eval GZIP= gzip $(GZIP_ENV) -c >$(distdir).shar.gz shar $(distdir) | GZIP=$(GZIP_ENV) gzip -c >$(distdir).shar.gz
$(am__post_remove_distdir) $(am__post_remove_distdir)
dist-zip: distdir dist-zip: distdir
@ -629,7 +630,7 @@ dist dist-all:
distcheck: dist distcheck: dist
case '$(DIST_ARCHIVES)' in \ case '$(DIST_ARCHIVES)' in \
*.tar.gz*) \ *.tar.gz*) \
eval GZIP= gzip $(GZIP_ENV) -dc $(distdir).tar.gz | $(am__untar) ;;\ GZIP=$(GZIP_ENV) gzip -dc $(distdir).tar.gz | $(am__untar) ;;\
*.tar.bz2*) \ *.tar.bz2*) \
bzip2 -dc $(distdir).tar.bz2 | $(am__untar) ;;\ bzip2 -dc $(distdir).tar.bz2 | $(am__untar) ;;\
*.tar.lz*) \ *.tar.lz*) \
@ -639,7 +640,7 @@ distcheck: dist
*.tar.Z*) \ *.tar.Z*) \
uncompress -c $(distdir).tar.Z | $(am__untar) ;;\ uncompress -c $(distdir).tar.Z | $(am__untar) ;;\
*.shar.gz*) \ *.shar.gz*) \
eval GZIP= gzip $(GZIP_ENV) -dc $(distdir).shar.gz | unshar ;;\ GZIP=$(GZIP_ENV) gzip -dc $(distdir).shar.gz | unshar ;;\
*.zip*) \ *.zip*) \
unzip $(distdir).zip ;;\ unzip $(distdir).zip ;;\
esac esac

31
moo/configure vendored
View File

@ -791,6 +791,7 @@ infodir
docdir docdir
oldincludedir oldincludedir
includedir includedir
runstatedir
localstatedir localstatedir
sharedstatedir sharedstatedir
sysconfdir sysconfdir
@ -887,6 +888,7 @@ datadir='${datarootdir}'
sysconfdir='${prefix}/etc' sysconfdir='${prefix}/etc'
sharedstatedir='${prefix}/com' sharedstatedir='${prefix}/com'
localstatedir='${prefix}/var' localstatedir='${prefix}/var'
runstatedir='${localstatedir}/run'
includedir='${prefix}/include' includedir='${prefix}/include'
oldincludedir='/usr/include' oldincludedir='/usr/include'
docdir='${datarootdir}/doc/${PACKAGE_TARNAME}' docdir='${datarootdir}/doc/${PACKAGE_TARNAME}'
@ -1139,6 +1141,15 @@ do
| -silent | --silent | --silen | --sile | --sil) | -silent | --silent | --silen | --sile | --sil)
silent=yes ;; silent=yes ;;
-runstatedir | --runstatedir | --runstatedi | --runstated \
| --runstate | --runstat | --runsta | --runst | --runs \
| --run | --ru | --r)
ac_prev=runstatedir ;;
-runstatedir=* | --runstatedir=* | --runstatedi=* | --runstated=* \
| --runstate=* | --runstat=* | --runsta=* | --runst=* | --runs=* \
| --run=* | --ru=* | --r=*)
runstatedir=$ac_optarg ;;
-sbindir | --sbindir | --sbindi | --sbind | --sbin | --sbi | --sb) -sbindir | --sbindir | --sbindi | --sbind | --sbin | --sbi | --sb)
ac_prev=sbindir ;; ac_prev=sbindir ;;
-sbindir=* | --sbindir=* | --sbindi=* | --sbind=* | --sbin=* \ -sbindir=* | --sbindir=* | --sbindi=* | --sbind=* | --sbin=* \
@ -1276,7 +1287,7 @@ fi
for ac_var in exec_prefix prefix bindir sbindir libexecdir datarootdir \ for ac_var in exec_prefix prefix bindir sbindir libexecdir datarootdir \
datadir sysconfdir sharedstatedir localstatedir includedir \ datadir sysconfdir sharedstatedir localstatedir includedir \
oldincludedir docdir infodir htmldir dvidir pdfdir psdir \ oldincludedir docdir infodir htmldir dvidir pdfdir psdir \
libdir localedir mandir libdir localedir mandir runstatedir
do do
eval ac_val=\$$ac_var eval ac_val=\$$ac_var
# Remove trailing slashes. # Remove trailing slashes.
@ -1429,6 +1440,7 @@ Fine tuning of the installation directories:
--sysconfdir=DIR read-only single-machine data [PREFIX/etc] --sysconfdir=DIR read-only single-machine data [PREFIX/etc]
--sharedstatedir=DIR modifiable architecture-independent data [PREFIX/com] --sharedstatedir=DIR modifiable architecture-independent data [PREFIX/com]
--localstatedir=DIR modifiable single-machine data [PREFIX/var] --localstatedir=DIR modifiable single-machine data [PREFIX/var]
--runstatedir=DIR modifiable per-process data [LOCALSTATEDIR/run]
--libdir=DIR object code libraries [EPREFIX/lib] --libdir=DIR object code libraries [EPREFIX/lib]
--includedir=DIR C header files [PREFIX/include] --includedir=DIR C header files [PREFIX/include]
--oldincludedir=DIR C header files for non-gcc [/usr/include] --oldincludedir=DIR C header files for non-gcc [/usr/include]
@ -18372,6 +18384,18 @@ _ACEOF
fi fi
done done
for ac_func in sigaction signal
do :
as_ac_var=`$as_echo "ac_cv_func_$ac_func" | $as_tr_sh`
ac_fn_c_check_func "$LINENO" "$ac_func" "$as_ac_var"
if eval test \"x\$"$as_ac_var"\" = x"yes"; then :
cat >>confdefs.h <<_ACEOF
#define `$as_echo "HAVE_$ac_func" | $as_tr_cpp` 1
_ACEOF
fi
done
for ac_func in snprintf _vsnprintf _vsnwprintf strerror_r for ac_func in snprintf _vsnprintf _vsnwprintf strerror_r
do : do :
as_ac_var=`$as_echo "ac_cv_func_$ac_func" | $as_tr_sh` as_ac_var=`$as_echo "ac_cv_func_$ac_func" | $as_tr_sh`
@ -21039,6 +21063,11 @@ _ACEOF
fi fi
cat >>confdefs.h <<_ACEOF
#define MOO_NSIG ${ax_cv_numvalof_NSIG}
_ACEOF
cat >>confdefs.h <<_ACEOF cat >>confdefs.h <<_ACEOF
#define MOO_SIZEOF_STRUCT_SOCKADDR_IN ${ac_cv_sizeof_struct_sockaddr_in} #define MOO_SIZEOF_STRUCT_SOCKADDR_IN ${ac_cv_sizeof_struct_sockaddr_in}

View File

@ -153,6 +153,7 @@ AC_CHECK_FUNCS([backtrace backtrace_symbols])
AC_CHECK_FUNCS([makecontext swapcontext getcontext setcontext]) AC_CHECK_FUNCS([makecontext swapcontext getcontext setcontext])
AC_CHECK_FUNCS([clock_nanosleep nanosleep usleep]) AC_CHECK_FUNCS([clock_nanosleep nanosleep usleep])
AC_CHECK_FUNCS([localtime_r gmtime_r]) AC_CHECK_FUNCS([localtime_r gmtime_r])
AC_CHECK_FUNCS([sigaction signal])
AC_CHECK_FUNCS([snprintf _vsnprintf _vsnwprintf strerror_r]) AC_CHECK_FUNCS([snprintf _vsnprintf _vsnwprintf strerror_r])
AC_CHECK_FUNCS([accept4 pipe2 epoll_create1]) AC_CHECK_FUNCS([accept4 pipe2 epoll_create1])
AC_CHECK_FUNCS([isatty mmap munmap]) AC_CHECK_FUNCS([isatty mmap munmap])
@ -587,6 +588,7 @@ if test ${ax_cv_numvalof_PATH_MAX} -gt 0
then then
AC_DEFINE_UNQUOTED(MOO_PATH_MAX, ${ax_cv_numvalof_PATH_MAX}, [PATH_MAX]) AC_DEFINE_UNQUOTED(MOO_PATH_MAX, ${ax_cv_numvalof_PATH_MAX}, [PATH_MAX])
fi fi
AC_DEFINE_UNQUOTED(MOO_NSIG, ${ax_cv_numvalof_NSIG}, [NSIG])
AC_DEFINE_UNQUOTED(MOO_SIZEOF_STRUCT_SOCKADDR_IN, ${ac_cv_sizeof_struct_sockaddr_in}, [sizeof(struct sockaddr_in)]) AC_DEFINE_UNQUOTED(MOO_SIZEOF_STRUCT_SOCKADDR_IN, ${ac_cv_sizeof_struct_sockaddr_in}, [sizeof(struct sockaddr_in)])
AC_DEFINE_UNQUOTED(MOO_SIZEOF_STRUCT_SOCKADDR_IN6, ${ac_cv_sizeof_struct_sockaddr_in6}, [sizeof(struct sockaddr_in6)]) AC_DEFINE_UNQUOTED(MOO_SIZEOF_STRUCT_SOCKADDR_IN6, ${ac_cv_sizeof_struct_sockaddr_in6}, [sizeof(struct sockaddr_in6)])

View File

@ -404,6 +404,7 @@ pdfdir = @pdfdir@
prefix = @prefix@ prefix = @prefix@
program_transform_name = @program_transform_name@ program_transform_name = @program_transform_name@
psdir = @psdir@ psdir = @psdir@
runstatedir = @runstatedir@
sbindir = @sbindir@ sbindir = @sbindir@
sharedstatedir = @sharedstatedir@ sharedstatedir = @sharedstatedir@
srcdir = @srcdir@ srcdir = @srcdir@

View File

@ -116,208 +116,8 @@ static MOO_INLINE void abort_moo (void)
if (g_moo) moo_abortstd (g_moo); if (g_moo) moo_abortstd (g_moo);
} }
static MOO_INLINE void swproc_moo (void)
{
if (g_moo) moo_switchprocess (g_moo);
}
/* ========================================================================= */ /* ========================================================================= */
#if defined(__DOS__) && (defined(_INTELC32_) || defined(__WATCOMC__))
#if defined(_INTELC32_)
static void (*prev_timer_intr_handler) (void);
#else
static void (__interrupt *prev_timer_intr_handler) (void);
#endif
#if defined(_INTELC32_)
#pragma interrupt(timer_intr_handler)
static void timer_intr_handler (void)
#else
static void __interrupt timer_intr_handler (void)
#endif
{
/*
_XSTACK *stk;
int r;
stk = (_XSTACK *)_get_stk_frame();
r = (unsigned short)stk_ptr->eax;
*/
/* The timer interrupt (normally) occurs 18.2 times per second. */
swproc_moo ();
_chain_intr (prev_timer_intr_handler);
}
static void setup_tick (void)
{
prev_timer_intr_handler = _dos_getvect (0x1C);
_dos_setvect (0x1C, timer_intr_handler);
}
static void cancel_tick (void)
{
_dos_setvect (0x1C, prev_timer_intr_handler);
}
#elif defined(_WIN32)
static HANDLE g_tick_timer = MOO_NULL; /*INVALID_HANDLE_VALUE;*/
static VOID CALLBACK arrange_process_switching (LPVOID arg, DWORD timeLow, DWORD timeHigh)
{
swproc_moo ();
}
static void setup_tick (void)
{
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);
}
}
static void cancel_tick (void)
{
if (g_tick_timer)
{
CancelWaitableTimer (g_tick_timer);
CloseHandle (g_tick_timer);
g_tick_timer = MOO_NULL;
}
}
#elif defined(__OS2__)
static TID g_tick_tid;
static HEV g_tick_sem;
static HTIMER g_tick_timer;
static int g_tick_done = 0;
static void EXPENTRY os2_wait_for_timer_event (ULONG x)
{
APIRET rc;
ULONG count;
rc = DosCreateEventSem (NULL, &g_tick_sem, DC_SEM_SHARED, FALSE);
if (rc != NO_ERROR)
{
/* xxxx */
}
rc = DosStartTimer (1L, (HSEM)g_tick_sem, &g_tick_timer);
if (rc != NO_ERROR)
{
}
while (!g_tick_done)
{
rc = DosWaitEventSem((HSEM)g_tick_sem, 5000L);
DosResetEventSem((HSEM)g_tick_sem, &count);
swproc_moo ();
}
DosStopTimer (g_tick_timer);
DosCloseEventSem ((HSEM)g_tick_sem);
g_tick_timer = NULL;
g_tick_sem = NULL;
DosExit (EXIT_THREAD, 0);
}
static void setup_tick (void)
{
/* TODO: Error check */
DosCreateThread (&g_tick_tid, os2_wait_for_timer_event, 0, 0, 4096);
}
static void cancel_tick (void)
{
if (g_tick_sem) DosPostEventSem (g_tick_sem);
g_tick_done = 1;
}
#elif defined(macintosh)
static TMTask g_tmtask;
static ProcessSerialNumber g_psn;
#define TMTASK_DELAY 50 /* milliseconds if positive, microseconds(after negation) if negative */
static pascal void timer_intr_handler (TMTask* task)
{
swproc_moo ();
WakeUpProcess (&g_psn);
PrimeTime ((QElem*)&g_tmtask, TMTASK_DELAY);
}
static void setup_tick (void)
{
GetCurrentProcess (&g_psn);
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);
}
static void cancel_tick (void)
{
RmvTime ((QElem*)&g_tmtask);
/*DisposeTimerProc (g_tmtask.tmAddr);*/
}
#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 sigaction act, oldact;
memset (&act, 0, sizeof(act));
sigemptyset (&act.sa_mask);
act.sa_handler = arrange_process_switching;
act.sa_flags = SA_RESTART;
sigaction (SIGVTALRM, &act, MOO_NULL);
/*#define MOO_ITIMER_TICK 10000*/ /* microseconds. 0.01 seconds */
#define MOO_ITIMER_TICK 20000 /* microseconds. 0.02 seconds. */
itv.it_interval.tv_sec = 0;
itv.it_interval.tv_usec = MOO_ITIMER_TICK;
itv.it_value.tv_sec = 0;
itv.it_value.tv_usec = MOO_ITIMER_TICK;
setitimer (ITIMER_VIRTUAL, &itv, MOO_NULL);
}
static void cancel_tick (void)
{
struct itimerval itv;
struct sigaction act;
itv.it_interval.tv_sec = 0;
itv.it_interval.tv_usec = 0;
itv.it_value.tv_sec = 0; /* make setitimer() one-shot only */
itv.it_value.tv_usec = 0;
setitimer (ITIMER_VIRTUAL, &itv, MOO_NULL);
sigemptyset (&act.sa_mask);
act.sa_handler = SIG_IGN; /* ignore the signal potentially fired by the one-shot arrange above */
act.sa_flags = 0;
sigaction (SIGVTALRM, &act, MOO_NULL);
}
#else
# error UNSUPPORTED
#endif
#if defined(_WIN32) #if defined(_WIN32)
static BOOL WINAPI handle_term (DWORD ctrl_type) static BOOL WINAPI handle_term (DWORD ctrl_type)
{ {
@ -627,9 +427,11 @@ int main (int argc, char* argv[])
MOO_DEBUG0 (moo, "COMPILE OK. STARTING EXECUTION...\n"); MOO_DEBUG0 (moo, "COMPILE OK. STARTING EXECUTION...\n");
xret = 0; xret = 0;
g_moo = moo; g_moo = moo;
setup_tick (); moo_start_ticker ();
setup_sigterm (); setup_sigterm ();
moo_rcvtickstd (moo, 1);
objname.ptr = str_my_object; objname.ptr = str_my_object;
objname.len = 8; objname.len = 8;
mthname.ptr = str_main; mthname.ptr = str_main;
@ -640,7 +442,7 @@ int main (int argc, char* argv[])
xret = -1; xret = -1;
} }
cancel_tick (); moo_stop_ticker ();
clear_sigterm (); clear_sigterm ();
g_moo = MOO_NULL; g_moo = MOO_NULL;

View File

@ -174,6 +174,12 @@
/* Define to 1 if you have the `settimeofday' function. */ /* Define to 1 if you have the `settimeofday' function. */
#undef HAVE_SETTIMEOFDAY #undef HAVE_SETTIMEOFDAY
/* Define to 1 if you have the `sigaction' function. */
#undef HAVE_SIGACTION
/* Define to 1 if you have the `signal' function. */
#undef HAVE_SIGNAL
/* Define to 1 if you have the <signal.h> header file. */ /* Define to 1 if you have the <signal.h> header file. */
#undef HAVE_SIGNAL_H #undef HAVE_SIGNAL_H
@ -348,6 +354,9 @@
/* MB_LEN_MAX */ /* MB_LEN_MAX */
#undef MOO_MBLEN_MAX #undef MOO_MBLEN_MAX
/* NSIG */
#undef MOO_NSIG
/* offsetof(struct sockaddr, sa_family) */ /* offsetof(struct sockaddr, sa_family) */
#undef MOO_OFFSETOF_SA_FAMILY #undef MOO_OFFSETOF_SA_FAMILY

View File

@ -78,6 +78,14 @@ typedef struct moo_iostd_t moo_iostd_t;
extern "C" { extern "C" {
#endif #endif
MOO_EXPORT void moo_start_ticker (
void
);
MOO_EXPORT void moo_stop_ticker (
void
);
MOO_EXPORT moo_t* moo_openstd ( MOO_EXPORT moo_t* moo_openstd (
moo_oow_t xtnsize, moo_oow_t xtnsize,
const moo_cfgstd_t* cfg, const moo_cfgstd_t* cfg,
@ -97,6 +105,12 @@ MOO_EXPORT int moo_compilestd(
const moo_iostd_t* in, const moo_iostd_t* in,
moo_oow_t count moo_oow_t count
); );
MOO_EXPORT void moo_rcvtickstd (
moo_t* moo,
int v
);
#if defined(__cplusplus) #if defined(__cplusplus)
} }
#endif #endif

View File

@ -265,6 +265,7 @@ struct xtn_t
moo_t* prev; moo_t* prev;
int vm_running; int vm_running;
int rcv_tick;
struct struct
{ {
@ -359,7 +360,6 @@ 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;
/* ========================================================================= */ /* ========================================================================= */
@ -2604,6 +2604,8 @@ static void vm_sleep (moo_t* moo, const moo_ntime_t* dur)
/* ========================================================================= */ /* ========================================================================= */
#if defined(HAVE_SIGACTION)
typedef struct sig_state_t sig_state_t; typedef struct sig_state_t sig_state_t;
struct sig_state_t struct sig_state_t
{ {
@ -2615,14 +2617,16 @@ struct sig_state_t
typedef void (*sig_handler_t) (int sig); typedef void (*sig_handler_t) (int sig);
#if !defined(NSIGS) static sig_state_t g_sig_state[MOO_NSIG];
# define NSIGS 100 /* TODO: change this */
#endif
static sig_state_t g_sig_state[NSIGS];
static void dispatch_siginfo (int sig, siginfo_t* si, void* ctx) static void dispatch_siginfo (int sig, siginfo_t* si, void* ctx)
{ {
((sig_handler_t)g_sig_state[sig].handler) (sig); if (g_sig_state[sig].handler != (moo_oow_t)SIG_IGN &&
g_sig_state[sig].handler != (moo_oow_t)SIG_DFL)
{
((sig_handler_t)g_sig_state[sig].handler) (sig);
}
if (g_sig_state[sig].old_handler && if (g_sig_state[sig].old_handler &&
g_sig_state[sig].old_handler != (moo_oow_t)SIG_IGN && g_sig_state[sig].old_handler != (moo_oow_t)SIG_IGN &&
g_sig_state[sig].old_handler != (moo_oow_t)SIG_DFL) g_sig_state[sig].old_handler != (moo_oow_t)SIG_DFL)
@ -2633,7 +2637,12 @@ static void dispatch_siginfo (int sig, siginfo_t* si, void* ctx)
static void dispatch_signal (int sig) static void dispatch_signal (int sig)
{ {
((sig_handler_t)g_sig_state[sig].handler) (sig); if (g_sig_state[sig].handler != (moo_oow_t)SIG_IGN &&
g_sig_state[sig].handler != (moo_oow_t)SIG_DFL)
{
((sig_handler_t)g_sig_state[sig].handler) (sig);
}
if (g_sig_state[sig].old_handler && if (g_sig_state[sig].old_handler &&
g_sig_state[sig].old_handler != (moo_oow_t)SIG_IGN && g_sig_state[sig].old_handler != (moo_oow_t)SIG_IGN &&
g_sig_state[sig].old_handler != (moo_oow_t)SIG_DFL) g_sig_state[sig].old_handler != (moo_oow_t)SIG_DFL)
@ -2647,6 +2656,7 @@ static int set_signal_handler (int sig, sig_handler_t handler, int extra_flags)
if (g_sig_state[sig].handler) if (g_sig_state[sig].handler)
{ {
/* already set - allow handler change. ignore extra_flags. */ /* already set - allow handler change. ignore extra_flags. */
if (g_sig_state[sig].handler == (moo_oow_t)handler) return -1;
g_sig_state[sig].handler = (moo_oow_t)handler; g_sig_state[sig].handler = (moo_oow_t)handler;
} }
else else
@ -2713,9 +2723,10 @@ static int unset_signal_handler (int sig)
return 0; return 0;
} }
#endif
/* ========================================================================= */ /* ========================================================================= */
static MOO_INLINE void swproc_all (void) static MOO_INLINE void swproc_all_moos (void)
{ {
/* TODO: make this atomic */ /* TODO: make this atomic */
if (g_moo) if (g_moo)
@ -2723,15 +2734,15 @@ static MOO_INLINE void swproc_all (void)
moo_t* moo = g_moo; moo_t* moo = g_moo;
do do
{ {
moo_switchprocess (moo); xtn_t* xtn = GET_XTN(moo);
moo = GET_XTN(moo)->next; if (xtn->rcv_tick) moo_switchprocess (moo);
moo = xtn->next;
} }
while (moo); while (moo);
} }
/* 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_)
@ -2755,48 +2766,61 @@ static void __interrupt dos_timer_intr_handler (void)
*/ */
/* The timer interrupt (normally) occurs 18.2 times per second. */ /* The timer interrupt (normally) occurs 18.2 times per second. */
swproc_moo (); swproc_all_moos ();
_chain_intr (dos_prev_timer_intr_handler); _chain_intr (dos_prev_timer_intr_handler);
} }
static void setup_tick (void) static void moo_start_ticker (void)
{ {
dos_prev_timer_intr_handler = _dos_getvect(0x1C); if (++ticker_started == 1)
_dos_setvect (0x1C, dos_timer_intr_handler); {
dos_prev_timer_intr_handler = _dos_getvect(0x1C);
_dos_setvect (0x1C, dos_timer_intr_handler);
}
} }
static void cancel_tick (void) static void moo_stop_ticker (void)
{ {
_dos_setvect (0x1C, dos_prev_timer_intr_handler); if (ticker_started > 0 && --ticker_started == 0)
{
_dos_setvect (0x1C, dos_prev_timer_intr_handler);
}
} }
#elif defined(_WIN32) #elif defined(_WIN32)
static HANDLE win_tick_timer = MOO_NULL; /*INVALID_HANDLE_VALUE;*/ static HANDLE win_tick_timer = MOO_NULL; /*INVALID_HANDLE_VALUE;*/
static moo_uint32_t ticker_started = 0;
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_moo (); swproc_all_moos ();
} }
static void setup_tick (void) static void moo_start_ticker (void)
{ {
LARGE_INTEGER li; if (++ticker_started == 1)
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 */ LARGE_INTEGER li;
SetWaitableTimer (win_tick_timer, &li, 0, arrange_process_switching, MOO_NULL, FALSE); 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) static void moo_stop_ticker (void)
{ {
if (win_tick_timer) if (ticker_started > 0 && --ticker_started == 0)
{ {
CancelWaitableTimer (win_tick_timer); if (win_tick_timer)
CloseHandle (win_tick_timer); {
win_tick_timer = MOO_NULL; CancelWaitableTimer (win_tick_timer);
CloseHandle (win_tick_timer);
win_tick_timer = MOO_NULL;
}
} }
} }
@ -2805,6 +2829,7 @@ static TID os2_tick_tid;
static HEV os2_tick_sem; static HEV os2_tick_sem;
static HTIMER os2_tick_timer; static HTIMER os2_tick_timer;
static int os2_tick_done = 0; static int os2_tick_done = 0;
static moo_uint32_t ticker_started = 0;
static void EXPENTRY os2_wait_for_timer_event (ULONG x) static void EXPENTRY os2_wait_for_timer_event (ULONG x)
{ {
@ -2826,7 +2851,7 @@ static void EXPENTRY os2_wait_for_timer_event (ULONG x)
{ {
rc = DosWaitEventSem((HSEM)os2_tick_sem, 5000L); rc = DosWaitEventSem((HSEM)os2_tick_sem, 5000L);
DosResetEventSem((HSEM)os2_tick_sem, &count); DosResetEventSem((HSEM)os2_tick_sem, &count);
swproc_moo (); swproc_all_moos ();
} }
DosStopTimer (os2_tick_timer); DosStopTimer (os2_tick_timer);
@ -2837,16 +2862,22 @@ static void EXPENTRY os2_wait_for_timer_event (ULONG x)
DosExit (EXIT_THREAD, 0); DosExit (EXIT_THREAD, 0);
} }
static void setup_tick (void) static void moo_start_ticker (void)
{ {
/* TODO: Error check */ if (++ticker_started == 1)
DosCreateThread (&os2_tick_tid, os2_wait_for_timer_event, 0, 0, 4096); {
/* TODO: Error check */
DosCreateThread (&os2_tick_tid, os2_wait_for_timer_event, 0, 0, 4096);
}
} }
static void cancel_tick (void) static void moo_stop_ticker (void)
{ {
if (os2_tick_sem) DosPostEventSem (os2_tick_sem); if (ticker_started > 0 && --ticker_started == 0)
os2_tick_done = 1; {
if (os2_tick_sem) DosPostEventSem (os2_tick_sem);
os2_tick_done = 1;
}
} }
#elif defined(macintosh) #elif defined(macintosh)
@ -2858,12 +2889,12 @@ static ProcessSerialNumber mac_psn;
static pascal void timer_intr_handler (TMTask* task) static pascal void timer_intr_handler (TMTask* task)
{ {
swproc_moo (); swproc_all_moos ();
WakeUpProcess (&mac_psn); WakeUpProcess (&mac_psn);
PrimeTime ((QElem*)&mac_tmtask, TMTASK_DELAY); PrimeTime ((QElem*)&mac_tmtask, TMTASK_DELAY);
} }
static void setup_tick (void) static void moo_start_ticker (void)
{ {
GetCurrentProcess (&mac_psn); GetCurrentProcess (&mac_psn);
memset (&mac_tmtask, 0, MOO_SIZEOF(mac_tmtask)); memset (&mac_tmtask, 0, MOO_SIZEOF(mac_tmtask));
@ -2872,7 +2903,7 @@ static void setup_tick (void)
PrimeTime ((QElem*)&mac_tmtask, TMTASK_DELAY); PrimeTime ((QElem*)&mac_tmtask, TMTASK_DELAY);
} }
static void cancel_tick (void) static void moo_stop_ticker (void)
{ {
RmvTime ((QElem*)&mac_tmtask); RmvTime ((QElem*)&mac_tmtask);
/*DisposeTimerProc (mac_tmtask.tmAddr);*/ /*DisposeTimerProc (mac_tmtask.tmAddr);*/
@ -2882,58 +2913,47 @@ static void cancel_tick (void)
static void arrange_process_switching (int sig) static void arrange_process_switching (int sig)
{ {
swproc_moo (); swproc_all_moos ();
} }
static void setup_tick (void) static moo_uint32_t ticker_started = 0;
void moo_start_ticker (void)
{ {
struct itimerval itv; if (++ticker_started == 1)
{
#if 0 if (set_signal_handler(SIGVTALRM, arrange_process_switching, SA_RESTART) >= 0)
struct sigaction act; {
struct itimerval itv;
memset (&act, 0, sizeof(act)); /*#define MOO_ITIMER_TICK 10000*/ /* microseconds. 0.01 seconds */
sigemptyset (&act.sa_mask); #define MOO_ITIMER_TICK 20000 /* microseconds. 0.02 seconds. */
act.sa_handler = arrange_process_switching; itv.it_interval.tv_sec = 0;
act.sa_flags = SA_RESTART; itv.it_interval.tv_usec = MOO_ITIMER_TICK;
sigaction (SIGVTALRM, &act, MOO_NULL); itv.it_value.tv_sec = 0;
#else itv.it_value.tv_usec = MOO_ITIMER_TICK;
set_signal_handler (SIGVTALRM, arrange_process_switching, SA_RESTART); setitimer (ITIMER_VIRTUAL, &itv, MOO_NULL);
#endif }
}
/*#define MOO_ITIMER_TICK 10000*/ /* microseconds. 0.01 seconds */
#define MOO_ITIMER_TICK 20000 /* microseconds. 0.02 seconds. */
itv.it_interval.tv_sec = 0;
itv.it_interval.tv_usec = MOO_ITIMER_TICK;
itv.it_value.tv_sec = 0;
itv.it_value.tv_usec = MOO_ITIMER_TICK;
setitimer (ITIMER_VIRTUAL, &itv, MOO_NULL);
} }
static void cancel_tick (void) void moo_stop_ticker (void)
{ {
struct itimerval itv; if (ticker_started > 0 && --ticker_started == 0)
#if 0 {
struct sigaction act; /* ignore the signal fired by the activated timer.
#endif * unsetting the signal may cause the program to terminate(default action) */
if (set_signal_handler(SIGVTALRM, SIG_IGN, 0) >= 0)
itv.it_interval.tv_sec = 0; {
itv.it_interval.tv_usec = 0; struct itimerval itv;
itv.it_value.tv_sec = 0; /* make setitimer() one-shot only */ itv.it_interval.tv_sec = 0;
itv.it_value.tv_usec = 0; itv.it_interval.tv_usec = 0;
setitimer (ITIMER_VIRTUAL, &itv, MOO_NULL); itv.it_value.tv_sec = 0; /* make setitimer() one-shot only */
itv.it_value.tv_usec = 0;
#if 0 setitimer (ITIMER_VIRTUAL, &itv, MOO_NULL);
sigemptyset (&act.sa_mask); }
act.sa_handler = SIG_IGN; /* ignore the signal potentially fired by the one-shot arrange above */ }
act.sa_flags = 0;
sigaction (SIGVTALRM, &act, MOO_NULL);
#else
/* ignore the signal potentially fired by the one-shot arrange above
* instead of unsetting the signal handler */
set_signal_handler (SIGVTALRM, SIG_IGN, 0);
#endif
} }
#else #else
# error UNSUPPORTED # error UNSUPPORTED
#endif #endif
@ -3275,9 +3295,11 @@ static MOO_INLINE void chain (moo_t* moo)
xtn_t* xtn = GET_XTN(moo); xtn_t* xtn = GET_XTN(moo);
/* TODO: make this atomic */ /* TODO: make this atomic */
xtn->prev = MOO_NULL;
xtn->next = g_moo;
if (g_moo) GET_XTN(g_moo)->prev = moo; if (g_moo) GET_XTN(g_moo)->prev = moo;
else g_moo = moo; else g_moo = moo;
xtn->next = g_moo;
/* TODO: make this atomic */ /* TODO: make this atomic */
} }
@ -3369,12 +3391,11 @@ void moo_abortstd (moo_t* moo)
moo_abort (moo); moo_abort (moo);
} }
int moo_compilestd(moo_t* moo, const moo_iostd_t* in, moo_oow_t count) int moo_compilestd (moo_t* moo, const moo_iostd_t* in, moo_oow_t count)
{ {
xtn_t* xtn; xtn_t* xtn = GET_XTN(moo);
moo_oow_t i; moo_oow_t i;
xtn = GET_XTN(moo);
for (i = 0; i < count; i++) for (i = 0; i < count; i++)
{ {
xtn->in = &in[i]; xtn->in = &in[i];
@ -3383,3 +3404,9 @@ int moo_compilestd(moo_t* moo, const moo_iostd_t* in, moo_oow_t count)
return 0; return 0;
}; };
void moo_rcvtickstd (moo_t* moo, int v)
{
xtn_t* xtn = GET_XTN(moo);
xtn->rcv_tick = v;
}

View File

@ -419,6 +419,7 @@ pdfdir = @pdfdir@
prefix = @prefix@ prefix = @prefix@
program_transform_name = @program_transform_name@ program_transform_name = @program_transform_name@
psdir = @psdir@ psdir = @psdir@
runstatedir = @runstatedir@
sbindir = @sbindir@ sbindir = @sbindir@
sharedstatedir = @sharedstatedir@ sharedstatedir = @sharedstatedir@
srcdir = @srcdir@ srcdir = @srcdir@