added moo_purgesemiosbyhandle()

This commit is contained in:
hyunghwan.chung 2018-02-03 07:16:29 +00:00
parent ea70db9633
commit eb35c3d865
4 changed files with 39 additions and 1 deletions

View File

@ -1341,6 +1341,34 @@ 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;

View File

@ -599,7 +599,7 @@ static void* dl_open (moo_t* moo, const moo_ooch_t* name, int flags)
static void dl_close (moo_t* moo, void* handle)
{
#if defined(USE_LTDL) | defined(USE_DLFCN)
#if defined(USE_LTDL) || defined(USE_DLFCN)
MOO_DEBUG1 (moo, "Closed DL handle %p\n", handle);
sys_dl_close (handle);

View File

@ -2152,6 +2152,15 @@ MOO_EXPORT const moo_ooch_t* moo_errnum_to_errstr (
moo_errnum_t errnum
);
/**
* 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.
*/
MOO_EXPORT void moo_purgesemiosbyhandle (
moo_t* moo,
moo_ooi_t io_handle
);
#if defined(MOO_INCLUDE_COMPILER)

View File

@ -132,6 +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));
if (close(MOO_OOP_TO_SMOOI(sck->handle)) == -1)
{
moo_seterrwithsyserr (moo, errno);