simplified vm_startup() and vm_cleanup() in main.c
used qse_seterrwithsyserr() in mod/stdio.c
This commit is contained in:
parent
ae06fb7b8b
commit
5580b1abc2
@ -1447,15 +1447,13 @@ static int _mod_poll_fd (moo_t* moo, int fd, int event_mask)
|
||||
|
||||
static int vm_startup (moo_t* moo)
|
||||
{
|
||||
#if defined(_WIN32)
|
||||
xtn_t* xtn = (xtn_t*)moo_getxtn(moo);
|
||||
xtn->waitable_timer = CreateWaitableTimer(MOO_NULL, TRUE, MOO_NULL);
|
||||
|
||||
#else
|
||||
|
||||
xtn_t* xtn = (xtn_t*)moo_getxtn(moo);
|
||||
int pcount = 0, flag;
|
||||
|
||||
#if defined(_WIN32)
|
||||
xtn->waitable_timer = CreateWaitableTimer(MOO_NULL, TRUE, MOO_NULL);
|
||||
#endif
|
||||
|
||||
#if defined(USE_DEVPOLL)
|
||||
xtn->ep = open ("/dev/poll", O_RDWR);
|
||||
if (xtn->ep == -1)
|
||||
@ -1557,22 +1555,21 @@ oops:
|
||||
#endif
|
||||
|
||||
return -1;
|
||||
#endif
|
||||
}
|
||||
|
||||
static void vm_cleanup (moo_t* moo)
|
||||
{
|
||||
#if defined(_WIN32)
|
||||
xtn_t* xtn = (xtn_t*)moo_getxtn(moo);
|
||||
|
||||
xtn->vm_running = 0;
|
||||
|
||||
#if defined(_WIN32)
|
||||
if (xtn->waitable_timer)
|
||||
{
|
||||
CloseHandle (xtn->waitable_timer);
|
||||
xtn->waitable_timer = MOO_NULL;
|
||||
}
|
||||
#else
|
||||
xtn_t* xtn = (xtn_t*)moo_getxtn(moo);
|
||||
|
||||
xtn->vm_running = 0;
|
||||
#endif
|
||||
|
||||
#if defined(USE_THREAD)
|
||||
if (xtn->iothr_up)
|
||||
@ -1626,8 +1623,6 @@ static void vm_cleanup (moo_t* moo)
|
||||
xtn->ev.reg.maxfd = -1;
|
||||
MUTEX_DESTROY (&xtn->ev.reg.smtx);
|
||||
#endif
|
||||
|
||||
#endif
|
||||
}
|
||||
|
||||
static void vm_gettime (moo_t* moo, moo_ntime_t* now)
|
||||
@ -1646,7 +1641,7 @@ static void vm_gettime (moo_t* moo, moo_ntime_t* now)
|
||||
if (msec < xtn->tc_last)
|
||||
{
|
||||
/* i assume the difference is never bigger than 49.7 days */
|
||||
//diff = (MOO_TYPE_MAX(DWORD) - xtn->tc_last) + 1 + msec;
|
||||
/*diff = (MOO_TYPE_MAX(DWORD) - xtn->tc_last) + 1 + msec;*/
|
||||
xtn->tc_overflow++;
|
||||
bigmsec = ((moo_uint64_t)MOO_TYPE_MAX(DWORD) * xtn->tc_overflow) + msec;
|
||||
}
|
||||
|
@ -278,11 +278,8 @@ restart:
|
||||
{
|
||||
int sought = pfd[i].events;
|
||||
pfd[i].revents = 0;
|
||||
if (pfd[i].fd < 0)
|
||||
continue;
|
||||
if (!(sought & (POLLIN | POLLRDNORM | POLLOUT | POLLWRNORM | POLLWRBAND
|
||||
| POLLPRI | POLLRDBAND)))
|
||||
continue;
|
||||
if (pfd[i].fd < 0) continue;
|
||||
if (!(sought & (POLLIN | POLLRDNORM | POLLOUT | POLLWRNORM | POLLWRBAND | POLLPRI | POLLRDBAND))) continue;
|
||||
|
||||
h = (HANDLE)_get_osfhandle (pfd[i].fd);
|
||||
if (IsSocketHandle (h))
|
||||
@ -316,14 +313,12 @@ restart:
|
||||
a character is available. windows_compute_revents eliminates
|
||||
bits for the "wrong" direction. */
|
||||
pfd[i].revents = windows_compute_revents (h, &sought);
|
||||
if (sought)
|
||||
handle_array[nhandles++] = h;
|
||||
if (pfd[i].revents)
|
||||
timeout = 0;
|
||||
if (sought) handle_array[nhandles++] = h;
|
||||
if (pfd[i].revents) timeout = 0;
|
||||
}
|
||||
}
|
||||
|
||||
if (select (0, &rfds, &wfds, &xfds, &tv0) > 0)
|
||||
if (select(0, &rfds, &wfds, &xfds, &tv0) > 0)
|
||||
{
|
||||
/* Do MsgWaitForMultipleObjects anyway to dispatch messages, but
|
||||
no need to call select again. */
|
||||
@ -341,8 +336,7 @@ restart:
|
||||
|
||||
for (;;)
|
||||
{
|
||||
ret = MsgWaitForMultipleObjects (nhandles, handle_array, FALSE,
|
||||
wait_timeout, QS_ALLINPUT);
|
||||
ret = MsgWaitForMultipleObjects(nhandles, handle_array, FALSE, wait_timeout, QS_ALLINPUT);
|
||||
|
||||
if (ret == WAIT_OBJECT_0 + nhandles)
|
||||
{
|
||||
@ -370,8 +364,7 @@ restart:
|
||||
|
||||
if (pfd[i].fd < 0)
|
||||
continue;
|
||||
if (!(pfd[i].events & (POLLIN | POLLRDNORM |
|
||||
POLLOUT | POLLWRNORM | POLLWRBAND)))
|
||||
if (!(pfd[i].events & (POLLIN | POLLRDNORM | POLLOUT | POLLWRNORM | POLLWRBAND)))
|
||||
continue;
|
||||
|
||||
h = (HANDLE) _get_osfhandle (pfd[i].fd);
|
||||
|
@ -75,7 +75,7 @@ static moo_pfrc_t pf_open (moo_t* moo, moo_mod_t* mod, moo_ooi_t nargs)
|
||||
#endif
|
||||
if (!stdio->fp)
|
||||
{
|
||||
moo_seterrnum (moo, moo_syserr_to_errnum(errno));
|
||||
moo_seterrwithsyserr (moo, errno);
|
||||
goto softfail;
|
||||
}
|
||||
|
||||
@ -157,7 +157,7 @@ static moo_pfrc_t __pf_puts (moo_t* moo, moo_ooi_t nargs, moo_oow_t limit)
|
||||
|
||||
if (fwrite (bcs, 1, bcslen, stdio->fp) < bcslen)
|
||||
{
|
||||
moo_seterrnum (moo, moo_syserr_to_errnum(errno));
|
||||
moo_seterrwithsyserr (moo, errno);
|
||||
goto softfail;
|
||||
}
|
||||
|
||||
@ -169,7 +169,7 @@ static moo_pfrc_t __pf_puts (moo_t* moo, moo_ooi_t nargs, moo_oow_t limit)
|
||||
puts_string:
|
||||
if (fwrite (x->slot, 1, MOO_OBJ_GET_SIZE(x), stdio->fp) < MOO_OBJ_GET_SIZE(x))
|
||||
{
|
||||
moo_seterrnum (moo, moo_syserr_to_errnum(errno));
|
||||
moo_seterrwithsyserr (moo, errno);
|
||||
goto softfail;
|
||||
}
|
||||
#endif
|
||||
|
Loading…
x
Reference in New Issue
Block a user