renamed moo_purgesemiosbyhandle() to moo_releaseiohandle()

pushed back when to call moo_cb_t callbacks
This commit is contained in:
hyunghwan.chung 2018-02-03 16:42:13 +00:00
parent eb35c3d865
commit c0d86a8f0e
5 changed files with 61 additions and 46 deletions

View File

@ -1341,34 +1341,6 @@ static int delete_from_sem_io (moo_t* moo, moo_oop_semaphore_t sem, int force)
return 0;
}
void moo_purgesemiosbyhandle (moo_t* moo, moo_ooi_t io_handle)
{
moo_ooi_t index;
moo_oop_semaphore_t sem;
if (io_handle < moo->sem_io_map_capa)
{
index = moo->sem_io_map[io_handle];
if (index >= 0)
{
MOO_ASSERT(moo, moo->sem_io_tuple[index].handle == io_handle);
sem = moo->sem_io_tuple[index].sem[MOO_SEMAPHORE_IO_TYPE_INPUT];
if (sem) delete_from_sem_io (moo, sem, 0);
}
}
if (io_handle < moo->sem_io_map_capa)
{
index = moo->sem_io_map[io_handle];
if (index >= 0)
{
MOO_ASSERT(moo, moo->sem_io_tuple[index].handle == io_handle);
sem = moo->sem_io_tuple[index].sem[MOO_SEMAPHORE_IO_TYPE_OUTPUT];
if (sem) delete_from_sem_io (moo, sem, 0);
}
}
}
static void _signal_io_semaphore (moo_t* moo, moo_oop_semaphore_t sem)
{
moo_oop_process_t proc;
@ -1420,6 +1392,41 @@ static void signal_io_semaphore (moo_t* moo, moo_ooi_t io_handle, moo_ooi_t mask
MOO_LOG1 (moo, MOO_LOG_WARN, "Warning - semaphore signaling requested on an unmapped handle %zd\n", io_handle);
}
}
void moo_releaseiohandle (moo_t* moo, moo_ooi_t io_handle)
{
/* TODO: optimize io semapore unmapping. since i'm to close the handle,
* i don't need to call delete_from_sem_io() seperately for input
* and output. */
if (io_handle < moo->sem_io_map_capa)
{
moo_ooi_t index;
moo_oop_semaphore_t sem;
index = moo->sem_io_map[io_handle];
if (index >= 0)
{
MOO_ASSERT(moo, moo->sem_io_tuple[index].handle == io_handle);
sem = moo->sem_io_tuple[index].sem[MOO_SEMAPHORE_IO_TYPE_INPUT];
if (sem) delete_from_sem_io (moo, sem, 0);
}
}
if (io_handle < moo->sem_io_map_capa)
{
moo_ooi_t index;
moo_oop_semaphore_t sem;
index = moo->sem_io_map[io_handle];
if (index >= 0)
{
MOO_ASSERT(moo, moo->sem_io_tuple[index].handle == io_handle);
sem = moo->sem_io_tuple[index].sem[MOO_SEMAPHORE_IO_TYPE_OUTPUT];
if (sem) delete_from_sem_io (moo, sem, 0);
}
}
}
/* ------------------------------------------------------------------------- */
static moo_oop_process_t start_initial_process (moo_t* moo, moo_oop_context_t c)

View File

@ -553,7 +553,10 @@ static void* dl_open (moo_t* moo, const moo_ooch_t* name, int flags)
goto retry;
}
}
else MOO_DEBUG3 (moo, "Opened(ext) DL %hs[%js] handle %p\n", &bufptr[len], name, handle);
else
{
MOO_DEBUG3 (moo, "Opened(ext) DL %hs[%js] handle %p\n", &bufptr[len], name, handle);
}
}
else
{
@ -755,6 +758,7 @@ static void log_write (moo_t* moo, moo_oow_t mask, const moo_ooch_t* msg, moo_oo
if (mask & MOO_LOG_STDOUT) logfd = 1;
else
{
logfd = xtn->logfd;
if (logfd <= -1) return;
}
@ -2045,7 +2049,7 @@ static void clear_sigterm (void)
}
/* ========================================================================= */
static void close_moo (moo_t* moo)
static void fini_moo (moo_t* moo)
{
xtn_t* xtn = moo_getxtn(moo);
if (xtn->logfd >= 0)
@ -2054,7 +2058,6 @@ static void close_moo (moo_t* moo)
xtn->logfd = -1;
xtn->logfd_istty = 0;
}
moo_close (moo);
}
static int handle_logopt (moo_t* moo, const moo_bch_t* str)
@ -2171,6 +2174,7 @@ int main (int argc, char* argv[])
moo_oocs_t objname;
moo_oocs_t mthname;
moo_vmprim_t vmprim;
moo_cb_t moocb;
int i, xret;
moo_bci_t c;
@ -2300,11 +2304,15 @@ int main (int argc, char* argv[])
xtn->logfd = -1;
xtn->logfd_istty = 0;
memset (&moocb, 0, MOO_SIZEOF(moocb));
moocb.fini = fini_moo;
moo_regcb (moo, &moocb);
if (logopt)
{
if (handle_logopt (moo, logopt) <= -1)
{
close_moo (moo);
moo_close (moo);
return -1;
}
}
@ -2319,7 +2327,7 @@ int main (int argc, char* argv[])
{
if (handle_dbgopt (moo, dbgopt) <= -1)
{
close_moo (moo);
moo_close (moo);
return -1;
}
}
@ -2328,7 +2336,7 @@ int main (int argc, char* argv[])
if (moo_ignite(moo) <= -1)
{
moo_logbfmt (moo, MOO_LOG_STDERR, "ERROR: cannot ignite moo - [%d] %js\n", moo_geterrnum(moo), moo_geterrstr(moo));
close_moo (moo);
moo_close (moo);
return -1;
}
@ -2380,7 +2388,7 @@ int main (int argc, char* argv[])
moo_logbfmt (moo, MOO_LOG_STDERR, "ERROR: cannot compile code - [%d] %js\n", moo_geterrnum(moo), moo_geterrmsg(moo));
}
close_moo (moo);
moo_close (moo);
#if defined(USE_LTDL)
lt_dlexit ();
#endif
@ -2411,7 +2419,7 @@ int main (int argc, char* argv[])
/*moo_dumpsymtab(moo);
*moo_dumpdic(moo, moo->sysdic, "System dictionary");*/
close_moo (moo);
moo_close (moo);
#if defined(USE_LTDL)
lt_dlexit ();

View File

@ -203,14 +203,14 @@ void moo_fini (moo_t* moo)
moo->proc_map_free_last = -1;
}
moo_rbt_walk (&moo->modtab, unload_module, moo); /* unload all modules */
moo_rbt_fini (&moo->modtab);
for (cb = moo->cblist; cb; cb = cb->next)
{
if (cb->fini) cb->fini (moo);
}
moo_rbt_walk (&moo->modtab, unload_module, moo); /* unload all modules */
moo_rbt_fini (&moo->modtab);
/* TOOD: persistency? storing objects to image file? */
moo_killheap (moo, moo->newheap);

View File

@ -2153,11 +2153,11 @@ MOO_EXPORT const moo_ooch_t* moo_errnum_to_errstr (
);
/**
* The moo_purgesemiosbyhandle() function deletes IO semaphores associated
* with the given IO handle. It can be called usefaully when you close
* a IO handle with dangling semaphores associated.
* The moo_releaseiohandle() function deletes resources associated with
* the given IO handle. The resources include IO semaphores. You should call
* this function before closing an IO handle.
*/
MOO_EXPORT void moo_purgesemiosbyhandle (
MOO_EXPORT void moo_releaseiohandle (
moo_t* moo,
moo_ooi_t io_handle
);

View File

@ -132,7 +132,7 @@ static moo_pfrc_t pf_close_socket (moo_t* moo, moo_ooi_t nargs)
fd = MOO_OOP_TO_SMOOI(sck->handle);
if (fd >= 0)
{
moo_purgesemiobyhandle (moo, MOO_OOP_TO_SMOOI(sck->handle));
moo_releaseiohandle (moo, MOO_OOP_TO_SMOOI(sck->handle));
if (close(MOO_OOP_TO_SMOOI(sck->handle)) == -1)
{
moo_seterrwithsyserr (moo, errno);