changed to raise/lower the number of IO semaphores being waited on when a semaphore is added/removed to/from a semaphore group.

reverted semaphore removal disallowance implemented in the previous revision
This commit is contained in:
hyunghwan.chung 2017-11-04 03:41:08 +00:00
parent 27c2c5b404
commit 384c5702bf

View File

@ -2588,8 +2588,17 @@ static moo_pfrc_t pf_semaphore_group_add_semaphore (moo_t* moo, moo_ooi_t nargs)
{
moo_ooi_t count;
count = MOO_OOP_TO_SMOOI(rcv->sem_io_count);
MOO_ASSERT (moo, count >= 0);
count++;
rcv->sem_io_count = MOO_SMOOI_TO_OOP(count);
if (count == 1)
{
moo_oop_process_t wp;
/* TODO: add sem_wait_count to process. no traversal... */
for (wp = rcv->waiting.first; (moo_oop_t)wp != moo->_nil; wp = wp->sem_wait.next)
moo->sem_io_wait_count++;
}
}
MOO_STACK_SETRETTORCV (moo, nargs);
@ -2623,6 +2632,7 @@ static moo_pfrc_t pf_semaphore_group_remove_semaphore (moo_t* moo, moo_ooi_t nar
{
int sems_idx;
#if 0
if ((moo_oop_t)rcv->waiting.first != moo->_nil)
{
/* there is a process waiting on this semaphore group.
@ -2640,6 +2650,7 @@ static moo_pfrc_t pf_semaphore_group_remove_semaphore (moo_t* moo, moo_ooi_t nar
MOO_STACK_SETRETTOERROR (moo, nargs, MOO_EPERM);
goto done;
}
#endif
sems_idx = MOO_OOP_TO_SMOOI(sem->count) > 0? MOO_SEMAPHORE_GROUP_SEMS_SIG: MOO_SEMAPHORE_GROUP_SEMS_UNSIG;
MOO_DELETE_FROM_OOP_LIST (moo, &rcv->sems[sems_idx], sem, grm);
@ -2654,6 +2665,14 @@ static moo_pfrc_t pf_semaphore_group_remove_semaphore (moo_t* moo, moo_ooi_t nar
MOO_ASSERT (moo, count > 0);
count--;
rcv->sem_io_count = MOO_SMOOI_TO_OOP(count);
if (count == 0)
{
moo_oop_process_t wp;
/* TODO: add sem_wait_count to process. no traversal... */
for (wp = rcv->waiting.first; (moo_oop_t)wp != moo->_nil; wp = wp->sem_wait.next)
moo->sem_io_wait_count--;
}
}
MOO_STACK_SETRETTORCV (moo, nargs);